Skip to content

Commit

Permalink
image_perfil
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuDSora committed Jul 26, 2024
1 parent c591fb9 commit 336c28e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 55 deletions.
Binary file added client/public/images/perfil.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 70 additions & 47 deletions client/src/AccountComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { format } from 'date-fns';

function AccountComponent() {
const navigate = useNavigate();
const pre = '/images/'
const [user, setUser] = useState({});
const [tutorData, setTutorData] = useState({});
const [isEditing, setIsEditing] = useState(false);
Expand Down Expand Up @@ -42,6 +43,7 @@ function AccountComponent() {
};
fetchTutor();
}
console.log(data);
setUser(data);
setFormData(data);
} catch (error) {
Expand Down Expand Up @@ -180,32 +182,77 @@ function AccountComponent() {
</div>
<div className="card-body">
<form>

<div className="mb-3">
<label className="form-label">ID: {formData.id || ''}</label>
<br />
</div>
<div className="mb-3">
<label className="form-label float-start">Nombre</label>
<input
type="text"
className="form-control"
name="name"
value={formData.name || ''}
onChange={handleChange}
disabled={!isEditing}
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Apellido</label>
<input
type="text"
className="form-control"
name="last"
value={formData.last || ''}
onChange={handleChange}
disabled={!isEditing}
/>
<div className="row">
<div className="col-4">
<img src={pre+formData.imagen_perfil} alt={formData.imagen_perfil} />
<select
className="form-control mt-3"
name="imagen_perfil"
value={formData.imagen_perfil || ''}
onChange={handleChange}
disabled={!isEditing}
>
<option value="perfil.jpg">Imagen de Perfil</option>
<option value="tutor1.jpg">Perfil Masculino</option>
<option value="tutor2.jpg">Perfil Femenino</option>
</select>
</div>
<div className="col-8">
<div className="mb-3">
<label className="form-label float-start">Nombre</label>
<input
type="text"
className="form-control"
name="name"
value={formData.name || ''}
onChange={handleChange}
disabled={!isEditing}
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Apellido</label>
<input
type="text"
className="form-control"
name="last"
value={formData.last || ''}
onChange={handleChange}
disabled={!isEditing}
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Rol</label>
<input
type="text"
className="form-control"
name="role"
value={formData.role || ''}
disabled
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Género</label>
<select
className="form-control"
name="gender"
value={formData.gender || ''}
onChange={handleChange}
disabled={!isEditing}
>
<option value="">Selecciona el género</option>
<option value="Male">Masculino</option>
<option value="Female">Femenino</option>
</select>
</div>
</div>
</div>


<div className="mb-3">
<label className="form-label float-start">Correo Electrónico</label>
<input
Expand All @@ -226,16 +273,7 @@ function AccountComponent() {
disabled
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Rol</label>
<input
type="text"
className="form-control"
name="role"
value={formData.role || ''}
disabled
/>
</div>

<div className="mb-3">
<label className="form-label float-start">Fecha de Nacimiento</label>
<input
Expand All @@ -247,22 +285,7 @@ function AccountComponent() {
disabled={!isEditing}
/>
</div>
<div className="mb-3">
<label className="form-label float-start">Género</label>
<select
className="form-control"
name="gender"
value={formData.gender || ''}
onChange={handleChange}
disabled={!isEditing}
>
<option value="">Selecciona el género</option>
<option value="Male">Masculino</option>
<option value="Female">Femenino</option>
<option value="Other">Otro</option>
<option value="Not Specified">No especificado</option>
</select>
</div>

{isEditing ? (
<>
<button
Expand Down
14 changes: 11 additions & 3 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//dependencias
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { useState, useEffect } from 'react';
import Cookies from 'js-cookie';

//componentes
import DashboardComponent from './DashboardComponent';
import AboutUs from './components/AboutUs';
import HelpCenter from './components/HelpCenter';
Expand Down Expand Up @@ -30,13 +34,17 @@ import DashST from './DashboardStudent/DashST.jsx';
import SubscriptionPlans from './SubscriptionPlans.jsx';
import withAuth from './hoc/withAuth'; // Importa el HOC desde la carpeta 'hoc'


function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);

useEffect(() => {
const storedLoggedIn = localStorage.getItem('token');
if (storedLoggedIn) {
setIsLoggedIn(true);
const session = Cookies.get('session');
if (session) {
const storedLoggedIn = localStorage.getItem('token');
if (storedLoggedIn) {
setIsLoggedIn(true);
}
}
}, []);

Expand Down
2 changes: 1 addition & 1 deletion client/src/hoc/withAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const withAuth = (WrappedComponent, allowedRoles) => {
const userRole = session ? Cookies.get('UserRol') || '' : '';

if (!session) {
return <Navigate to="/login" replace />;
return <Navigate to="/" replace />;
}

if (!allowedRoles.includes(userRole)) {
Expand Down
9 changes: 5 additions & 4 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const updateRole = async (req, res) => {
//actualizar el usuario
export const updateUsuario = async (req, res) => {
const { id } = req.params;
const { name, last, birth, gender } = req.body;
const { name, last, birth, gender, imagen_perfil } = req.body;

const client = await pool.connect();
try {
Expand All @@ -223,12 +223,13 @@ export const updateUsuario = async (req, res) => {
name = $1,
last = $2,
birth = $3,
gender = $4
WHERE id = $5
gender = $4,
imagen_perfil = $5
WHERE id = $6
RETURNING *;
`;

const result = await client.query(updateQuery, [name, last, birth, gender, id]);
const result = await client.query(updateQuery, [name, last, birth, gender,imagen_perfil ,id]);

if (result.rows.length === 0) {
return res.status(404).send('User not found.');
Expand Down

0 comments on commit 336c28e

Please sign in to comment.