NavDeUsuarios

This commit is contained in:
TioSam77
2024-07-05 19:36:26 -06:00
4 changed files with 37 additions and 29 deletions
+3
View File
@@ -24,6 +24,9 @@ const App = () => {
<div className="App">
<Router>
<Header />
{(permissions === 2 || permissions === 1) && (
<></>
)}
<Routes>
<Route path='/Test' element={<Menu />} />
<Route path={PublicRoutes.NOTFOUND} element={<Pagina404 />} />
@@ -6,7 +6,6 @@ const MapeoUsuario = ({ filters }) => {
const [usuarios, setUsuarios] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const [jwt,setJwt] = useState();
useEffect(() => {
fetchUsuarios();
+34 -27
View File
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useCallback } from 'react';
import { useDropzone } from 'react-dropzone';
import {PrivateRoutes, PublicRoutes} from '../../models/routes'
import { PublicRoutes } from '../../models/routes'
import './FormProfesor.css';
const FormProfesor = () => {
@@ -30,12 +30,12 @@ const FormProfesor = () => {
const [ubicacion,setUbicacion] = useState('');
const [mostrar,setMostrar] = useState(true);
const [nombre,setNombre] =useState('');
let imageUrl = '';
const [grado_maximo,setGrado_maximo] =useState('');
const [grados_obtenidos,setGrados_obtenidos] =useState('');
const [formData,setFormData] = useState()
const handlePageChange = (newPage) => {
setPage(newPage);
};
@@ -58,18 +58,6 @@ const FormProfesor = () => {
}, []);
const handleFileChange = (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onloadend = () => {
setFormData({
...formData,
fotografica: reader.result,
});
};
reader.readAsDataURL(file);
};
const handleLineaInvestigacionChange = (index, value) => {
const newLineas = [...lineasInvestigacion];
newLineas[index].lineas_inv = value;
@@ -104,6 +92,34 @@ const FormProfesor = () => {
event.preventDefault();
try {
const token = localStorage.getItem('Token');
if (!token) {
console.error('No tienes el token');
return;
}
if (fotoBase64) {
const imageUploadResponse = await fetch('http://localhost:3000/imagen', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
fotografia: fotoBase64,
nombre,
}),
});
if (!imageUploadResponse.ok) {
throw new Error('Error al subir la imagen');
}
const imageUploadResult = await imageUploadResponse.json();
console.log('Imagen subida con éxito:', imageUploadResult.imageUrl);
imageUrl = `http://localhost:3000${imageUploadResult.imageUrl}`;
}
const data = {
nombre,
id_usuario,
@@ -129,17 +145,10 @@ const FormProfesor = () => {
grados_obtenidos,
},
],
fotografia:fotoBase64,
fotografia: imageUrl,
};
console.log(data);
const token = localStorage.getItem('Token');
if (!token) {
console.error('No tienes el token');
return;
}
const response = await fetch('http://localhost:3000/profesor', {
method: 'POST',
headers: {
@@ -154,10 +163,8 @@ const FormProfesor = () => {
}
const result = await response.json();
console.log('Profesor guardado con éxito:', result);
console.log("Form submitted");
console.log(fotoBase64);
window.location.href = PublicRoutes.FILTER;
//window.location.href = PublicRoutes.FILTER;
} catch (error) {
console.error('Error al guardar el profesor:', error);
-1
View File
@@ -53,7 +53,6 @@ const LoginForm = () => {
return (
<div className="main-content">
<Link to={"/profesor/perfil/36"}>Hola mundo</Link>
<h1 className="text-warning">Bienvenido al directorio de profesores</h1>
<h2 className='m-3'>Iniciar sesión</h2>
<form onSubmit={handleSubmit} className="login-form" style={{ background: '#f9f9f9', borderRadius: '1em' }}>