From 4f5044d1ceb98cbe13b041caa1dd4bff80c8948f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 8 Apr 2024 16:08:15 +0200 Subject: [PATCH 01/13] feat:Implemented update user by admin --- src/components/AdminEditProfiles.js | 17 +++++ src/components/PersonCard.js | 107 ++++++++++++++++------------ src/components/PersonEdit.js | 0 src/components/UpdateProfile.js | 44 +++++++----- src/screens/App.js | 4 ++ src/styles/styles.css | 22 ++++++ 6 files changed, 131 insertions(+), 63 deletions(-) create mode 100644 src/components/AdminEditProfiles.js create mode 100644 src/components/PersonEdit.js diff --git a/src/components/AdminEditProfiles.js b/src/components/AdminEditProfiles.js new file mode 100644 index 00000000..295391de --- /dev/null +++ b/src/components/AdminEditProfiles.js @@ -0,0 +1,17 @@ +import '../styles/styles.css'; +import LayoutProfiles from '../components/LayoutProfiles'; +import UpdateProfile from '../components/UpdateProfile'; +import { useParams } from 'react-router-dom'; // Importa el hook useParams + + +const AdminEditProfiles = () => { + const { userId } = useParams(); // Extrae la ID de la URL + + return ( + + + + ); +}; + +export default AdminEditProfiles; \ No newline at end of file diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 36ec4865..5b39a2a8 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -2,11 +2,14 @@ import DeleteIcon from '@material-ui/icons/Delete'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; +import { Link } from "react-router-dom"; +import AdminEditProfiles from './AdminEditProfiles' + const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; function PersonCard({ person, personType, kids, request = false, trash = true }) { - const handleDescargar = async(person) => { + const handleDescargar = async (person) => { // Download the enrollment_document const documento = person.enrollment_document; const nombreArchivo = 'documento_de_enlistamiento.pdf'; // Puedes cambiar el nombre del archivo según lo necesites @@ -23,69 +26,69 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) enlaceDescarga.click(); toast.error("Se descarga vacio porque la api pasa enlaces en vez de archivos", { autoClose: 5000 - }); + }); }; - + const handleAceptar = async (person) => { console.log(person) person.status = "ACEPTADO"; - - const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`,{ - status: person.status + + const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`, { + status: person.status }); - console.log('update',update); - const {data} = update; - if (data.message){ - toast.error("Error al actualizar", { - autoClose: 5000 - }); - }else{ - toast.success("Usuario actualizado con éxito.", { - autoClose: 5000 - }) + console.log('update', update); + const { data } = update; + if (data.message) { + toast.error("Error al actualizar", { + autoClose: 5000 + }); + } else { + toast.success("Usuario actualizado con éxito.", { + autoClose: 5000 + }) } window.location.reload(); } - - const handleRechazar = async(person) =>{ + + const handleRechazar = async (person) => { console.log(person) person.status = "RECHAZADO"; - - const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`,{ - status: person.status + + const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`, { + status: person.status }); - console.log('update',update); - const {data} = update; - if (data.message){ - toast.error("Error al actualizar", { - autoClose: 5000 - }); - }else{ - toast.success("Usuario actualizado con éxito.", { - autoClose: 5000 - }) + console.log('update', update); + const { data } = update; + if (data.message) { + toast.error("Error al actualizar", { + autoClose: 5000 + }); + } else { + toast.success("Usuario actualizado con éxito.", { + autoClose: 5000 + }) } window.location.reload(); } - const handleEliminar = async(person) =>{ - if(!person.id || person.id <= 0){ - toast.error('La id no es valida', { - autoClose: 5000 - }) - }else{ - if(personType === 'Familias-solicitudes'){ + const handleEliminar = async (person) => { + if (!person.id || person.id <= 0) { + toast.error('La id no es valida', { + autoClose: 5000 + }) + } else { + if (personType === 'Familias-solicitudes') { await axios.delete(`${API_ENDPOINT}student/${person.id}/`); - } else if(personType === 'Voluntarios'){ + } else if (personType === 'Voluntarios') { console.log(person.id); await axios.delete(`${API_ENDPOINT}volunteer/${person.id}/`); } else { await axios.delete(`${API_ENDPOINT}user/${person.id}/`); } - toast.success("Persona eliminada correctamente", { - autoClose: 5000 - }) - window.location.reload(); // Recarga la ventana después de eliminar + toast.success("Persona eliminada correctamente", { + autoClose: 5000 + }) + window.location.reload(); // Recarga la ventana después de eliminar } } @@ -97,11 +100,11 @@ function PersonCard({ person, personType, kids, request = false, trash = true })

{person.first_name}

{person.name}

Número de niños: {kids.filter(kid => kid.family === person.id).length}

- + :
placeholder -
+
{personType === 'Familias-solicitudes' ?

{person.first_name}

:

{person.first_name}

}

{person.last_name}

@@ -132,7 +135,19 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
} - {trash && handleEliminar(person)} />} + {trash && +
+ handleEliminar(person)} /> + +
+ } + + + ); } diff --git a/src/components/PersonEdit.js b/src/components/PersonEdit.js new file mode 100644 index 00000000..e69de29b diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index 5f2cb2d2..7fbf5902 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -9,10 +9,8 @@ import {useNavigate} from 'react-router-dom'; const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; -const UpdateProfile = ({tipo}) => { +const UpdateProfile = ({tipo,id}) => { - const id = localStorage.getItem('userId'); - const [avatar, setAvatar] = useState(""); const [valoresList, setValores] = useState([]); @@ -20,18 +18,25 @@ const UpdateProfile = ({tipo}) => { //Traemos los datos del usuario useEffect(() => { + const fetchData = async () => { + try { + let response; + if (id) { + response = await axios.get(`${API_ENDPOINT}user/${id}/`); + console.log(response.data) + console.log('--------------------------------') + } else { + response = await axios.get(`${API_ENDPOINT}auth/users/me/`); + } + setValores(response.data); + } catch (error) { + console.error(error); + } + }; + + fetchData(); + }, [id]); - axios.get(`${API_ENDPOINT}user/`) - .then(response => { - setValores(response.data.find(x=>x.id==parseInt(id,10))); - console.log("name", name) - setAvatar(valoresList.avatar) - }) - .catch(error => { - console.error(error); - }); - - }, []); //Atributos const [name, setName] = useState(""); @@ -72,7 +77,7 @@ const UpdateProfile = ({tipo}) => { }; - const update = await axios.put(`${API_ENDPOINT}user/${id}/`, updatedData); + const update = await axios.put(`${API_ENDPOINT}auth/users/me/`, updatedData); const { data } = update; if (data.message) { @@ -138,12 +143,17 @@ const UpdateProfile = ({tipo}) => { placeholder='ejemplo@gmail.com' > -

Contraseña

+ +

+ + Contraseña (obligatorio) + +

setPassword(e.target.value)} type='password' - placeholder='Contraseña' + placeholder='Contraseña de tu cuenta' > diff --git a/src/screens/App.js b/src/screens/App.js index c59d82f8..97d0e0fa 100644 --- a/src/screens/App.js +++ b/src/screens/App.js @@ -40,6 +40,8 @@ import AdminLessonsCreate from './admin/AdminLessonsCreate'; import AdminLessonsEdit from './admin/AdminLessonsEdit'; import AdminSuggestions from './admin/AdminSuggestions'; import AdminTransparency from './admin/AdminTransparency'; +import AdminEditProfiles from '../components/AdminEditProfiles'; + // EDUCATORS import EducatorProfile from './educators/EducatorProfile'; @@ -96,6 +98,8 @@ function App() { {/* ADMIN ROUTES */} } /> } /> + } /> + } /> } /> diff --git a/src/styles/styles.css b/src/styles/styles.css index 2a6164a1..35aca59a 100644 --- a/src/styles/styles.css +++ b/src/styles/styles.css @@ -1445,6 +1445,28 @@ tbody tr:nth-child(odd) { box-shadow: 0 6px 10px 0 #7c7c7c, 0 7px 25px 0 #7c7c7c; } +.button-edit { + background-color: #a7e6b3; + border-radius: 10px; + height: 40%; + width: 40%; + text-align: center; + margin-left: 100px; + margin-bottom: 10%; + font-size: 15px; + font-weight: 500; + padding: 3% 5% 3% 5%; + color: #ffffff; + font-family: "Poppins", Helvetica; + border: 2px solid #a7e6b3; +} + +.button-decline:hover { + cursor: pointer; + background-color: #ff3c32; + box-shadow: 0 6px 10px 0 #7c7c7c, 0 7px 25px 0 #7c7c7c; +} + From 5d14e6470afb62c4b64cc5bf4b6607e73f0b7581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 8 Apr 2024 16:46:49 +0200 Subject: [PATCH 02/13] feat:Implemented update user by admin --- src/components/AdminEditProfiles.js | 4 ++-- src/components/UpdateProfile.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/AdminEditProfiles.js b/src/components/AdminEditProfiles.js index 295391de..01e9edc0 100644 --- a/src/components/AdminEditProfiles.js +++ b/src/components/AdminEditProfiles.js @@ -5,11 +5,11 @@ import { useParams } from 'react-router-dom'; // Importa el hook useParams const AdminEditProfiles = () => { - const { userId } = useParams(); // Extrae la ID de la URL + const { id } = useParams(); // Extrae la ID de la URL return ( - + ); }; diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index 7fbf5902..1b6dcdf6 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -8,9 +8,8 @@ import {useNavigate} from 'react-router-dom'; const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; - const UpdateProfile = ({tipo,id}) => { - + console.log(id) const [valoresList, setValores] = useState([]); @@ -23,8 +22,6 @@ const UpdateProfile = ({tipo,id}) => { let response; if (id) { response = await axios.get(`${API_ENDPOINT}user/${id}/`); - console.log(response.data) - console.log('--------------------------------') } else { response = await axios.get(`${API_ENDPOINT}auth/users/me/`); } @@ -35,7 +32,7 @@ const UpdateProfile = ({tipo,id}) => { }; fetchData(); - }, [id]); + }, []); //Atributos @@ -76,13 +73,18 @@ const UpdateProfile = ({tipo,id}) => { user_permissions: valoresList.user_permissions, }; + const updateEndpoint = id ? `${API_ENDPOINT}user/${id}/` : `${API_ENDPOINT}auth/users/me/`; + const update = await axios.put(updateEndpoint, updatedData); - const update = await axios.put(`${API_ENDPOINT}auth/users/me/`, updatedData); const { data } = update; if (data.message) { window.alert(data.message); - } else { + }else if(id){ + navigate(`/admin/${valoresList.role + "S"}`); + + } + else { navigate(`/${tipo}/perfil`); } } catch (error) { From 498156625bbee7ce69a3b6f024df612ffd61fb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 8 Apr 2024 16:53:56 +0200 Subject: [PATCH 03/13] feat:Changed color blue from link --- src/components/PersonCard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 5b39a2a8..fbba372d 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -139,7 +139,7 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
handleEliminar(person)} /> From 58ecf4ea97ad68451543eca1f39113498699739b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 8 Apr 2024 16:56:15 +0200 Subject: [PATCH 04/13] feat:Changed color blue from link --- src/components/PersonCard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index fbba372d..98f831ee 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -139,7 +139,7 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
handleEliminar(person)} /> From a88c9fd2636297f0da12f37ae475d2f2b37e2628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 8 Apr 2024 17:06:30 +0200 Subject: [PATCH 05/13] feat:Solved a bug related to modify a educator --- src/components/UpdateProfile.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index 1b6dcdf6..a8409565 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -80,9 +80,12 @@ const UpdateProfile = ({tipo,id}) => { const { data } = update; if (data.message) { window.alert(data.message); - }else if(id){ + }else if(id && valoresList.role !== "EDUCADOR"){ navigate(`/admin/${valoresList.role + "S"}`); + }else if(id && valoresList.role === "EDUCADOR"){ + navigate(`/admin/${valoresList.role + "ES"}`) + } else { navigate(`/${tipo}/perfil`); From 975408412b20038d36d5c4886dbc7cb21ef2e677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 9 Apr 2024 10:43:50 +0200 Subject: [PATCH 06/13] feat:Solved a bug related to modify a educator --- src/components/UpdateProfile.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index a8409565..31ad93a3 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -85,8 +85,7 @@ const UpdateProfile = ({tipo,id}) => { }else if(id && valoresList.role === "EDUCADOR"){ navigate(`/admin/${valoresList.role + "ES"}`) - - } + } else { navigate(`/${tipo}/perfil`); } From fd850cf281a0689a087162cdd2b48653f30df4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 9 Apr 2024 11:17:31 +0200 Subject: [PATCH 07/13] feat:Added the changes requested by the reviwer --- src/components/PersonCard.js | 9 +++------ src/components/UpdateProfile.js | 7 ++++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 98f831ee..a6af1bde 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -1,4 +1,5 @@ import DeleteIcon from '@material-ui/icons/Delete'; +import EditIcon from '@material-ui/icons/Edit'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; @@ -137,12 +138,8 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) } {trash &&
- handleEliminar(person)} /> - + handleEliminar(person)} /> + window.location.replace(`/admin/perfil/actualizar/${person.id}`) } />
} diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index 31ad93a3..f1dab9cd 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -138,7 +138,8 @@ const UpdateProfile = ({tipo,id}) => { type='tel' placeholder='Número de teléfono' > - + {id? <>: + <>

Correo electrónico

{ type='password' placeholder='Contraseña de tu cuenta' > - - + + } From 6da0e5c9842e0944f2a35cea410b14cf08088436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 9 Apr 2024 18:56:09 +0200 Subject: [PATCH 08/13] feat:Now the info is shown in the update form --- src/components/UpdateProfile.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index f1dab9cd..c67968c8 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -112,7 +112,7 @@ const UpdateProfile = ({tipo,id}) => { defaultValue={name} //defaultValue es como value, pero permite el cambio onChange={(e) => setName(e.target.value)} type='text' - placeholder='Nombre' + placeholder={valoresList.first_name} >

Apellido

@@ -120,7 +120,7 @@ const UpdateProfile = ({tipo,id}) => { defaultValue={surname} onChange={(e) => setSurname(e.target.value)} type='text' - placeholder='Primer Apellido' + placeholder={valoresList.last_name} >

DNI/NIE/Pasaporte

@@ -128,7 +128,7 @@ const UpdateProfile = ({tipo,id}) => { defaultValue={id_number} onChange={(e) => setId_number(e.target.value)} type='text' - placeholder='DNI/NIE/Pasaporte' + placeholder={valoresList.id_number} >

Número de teléfono

@@ -136,7 +136,7 @@ const UpdateProfile = ({tipo,id}) => { defaultValue={phone} onChange={(e) => setPhone(e.target.value)} type='tel' - placeholder='Número de teléfono' + placeholder={valoresList.phone} > {id? <>: <> From 9c2e76029355b5c1b3a1eb9efce6d3075e5d7d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Apr 2024 15:10:53 +0200 Subject: [PATCH 09/13] fix:Solved the problems with family request --- src/components/PersonCard.js | 113 ++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 35 deletions(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 84fc9a3f..4d13567a 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -1,12 +1,14 @@ import DeleteIcon from '@material-ui/icons/Delete'; +import EditIcon from '@material-ui/icons/Edit'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; + const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; function PersonCard({ person, personType, kids, request = false, trash = true }) { - const handleDescargar = async(person) => { + const handleDescargar = async (person) => { // Download the enrollment_document const documento = person.enrollment_document; const nombreArchivo = 'documento_de_enlistamiento.pdf'; // Puedes cambiar el nombre del archivo según lo necesites @@ -23,46 +25,79 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) enlaceDescarga.click(); toast.error("Se descarga vacio porque la api pasa enlaces en vez de archivos", { autoClose: 5000 - }); + }); }; - + const handleAceptar = async (person) => { - console.log(person) person.status = "ACEPTADO"; - - const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.volunteer}/`,{ - status: person.status + let url; + if (person.volunteer) { + url = `${API_ENDPOINT}volunteer/${person.volunteer}/`; + } else if (person.id) { + url = `${API_ENDPOINT}student/${person.id}/`; + } + + const update = await axios.patch(url, { + status: person.status }); - console.log('update',update); - const {data} = update; - if (data.message){ - toast.error("Error al actualizar", { - autoClose: 5000 - }); - }else{ - toast.success("Usuario actualizado con éxito.", { - autoClose: 5000 - }) + console.log('update', update); + const { data } = update; + if (data.message) { + toast.error("Error al actualizar", { + autoClose: 5000 + }); + } else { + toast.success("Usuario actualizado con éxito.", { + autoClose: 5000 + }) + } + window.location.reload(); +} + + const handleRechazar = async (person) => { + let url; + person.status = "RECHAZADO"; + if (person.volunteer) { + url = `${API_ENDPOINT}volunteer/${person.volunteer}/`; + } else if (person.id) { + url = `${API_ENDPOINT}student/${person.id}/`; + } + + const update = await axios.patch(url, { + status: person.status + }); + console.log('update', update); + const { data } = update; + if (data.message) { + toast.error("Error al actualizar", { + autoClose: 5000 + }); + } else { + toast.success("Usuario actualizado con éxito.", { + autoClose: 5000 + }) } window.location.reload(); } - - const handleRechazarOEliminar = async(person) =>{ - if(!person.id || person.id <= 0){ - toast.error('La id no es valida', { - autoClose: 5000 - }) - }else{ - if(personType === 'Familias-solicitudes'){ + + const handleEliminar = async (person) => { + if (!person.id || person.id <= 0) { + toast.error('La id no es valida', { + autoClose: 5000 + }) + } else { + if (personType === 'Familias-solicitudes') { await axios.delete(`${API_ENDPOINT}student/${person.id}/`); - } - else { + } else if (personType === 'Voluntarios') { + console.log(person.id); + await axios.delete(`${API_ENDPOINT}volunteer/${person.volunteer}/`); + } else { await axios.delete(`${API_ENDPOINT}user/${person.id}/`); } - toast.success("Persona eliminada correctamente", { - autoClose: 5000 - }) - window.location.reload(); // Recarga la ventana después de eliminar + toast.success("Persona eliminada correctamente", { + autoClose: 5000 + }) + window.location.reload(); // Recarga la ventana después de eliminar } } @@ -74,11 +109,11 @@ function PersonCard({ person, personType, kids, request = false, trash = true })

{person.first_name}

{person.name}

Número de niños: {kids.filter(kid => kid.family === person.id).length}

-
+
:
placeholder -
+
{personType === 'Familias-solicitudes' ?

{person.first_name}

:

{person.first_name}

}

{person.last_name}

@@ -105,11 +140,19 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
- +
} - {trash && handleRechazarOEliminar(person)} />} + {trash && +
+ handleEliminar(person)} /> + window.location.replace(`/admin/perfil/actualizar/${person.id}`) } /> +
+ } + + +
); } From fc01d2d62a3bf82155a7192cc343408f4c921aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Apr 2024 15:18:40 +0200 Subject: [PATCH 10/13] fix:Added download feature --- src/components/PersonCard.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 4d13567a..83c71a82 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -8,25 +8,24 @@ const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; function PersonCard({ person, personType, kids, request = false, trash = true }) { - const handleDescargar = async (person) => { - // Download the enrollment_document - const documento = person.enrollment_document; - const nombreArchivo = 'documento_de_enlistamiento.pdf'; // Puedes cambiar el nombre del archivo según lo necesites + const handleDescargar = async(person) => { + const descargarDocumento = (documento, nombreArchivo) => { + const enlaceDescarga = document.createElement('a'); + enlaceDescarga.href = documento; + enlaceDescarga.download = nombreArchivo; - // Crear un objeto Blob a partir de los datos del documento - const blob = new Blob([documento], { type: 'application/pdf' }); + // Simular un clic en el enlace para descargar el archivo + enlaceDescarga.click(); + }; - // Crear un enlace temporal - const enlaceDescarga = document.createElement('a'); - enlaceDescarga.href = window.URL.createObjectURL(blob); - enlaceDescarga.download = nombreArchivo; + // Descargar cada documento + descargarDocumento(`${API_ENDPOINT}export/files/volunteers?name=${person.first_name}&surname=${person.last_name}`, 'documentos_voluntario.zip'); - // Hacer clic en el enlace para descargar el archivo - enlaceDescarga.click(); - toast.error("Se descarga vacio porque la api pasa enlaces en vez de archivos", { - autoClose: 5000 + // Mostrar un mensaje de éxito + toast.success("Descarga existosa", { + autoClose: 5000 }); - }; +}; const handleAceptar = async (person) => { person.status = "ACEPTADO"; From 65e6a713e1450993d09f6b6049ff4cd18674eee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Apr 2024 15:21:18 +0200 Subject: [PATCH 11/13] fix:Solved a bug related to acept and refuse a volunteer --- src/components/PersonCard.js | 53 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index a6af1bde..83c71a82 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -3,38 +3,40 @@ import EditIcon from '@material-ui/icons/Edit'; import axios from 'axios'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; -import { Link } from "react-router-dom"; -import AdminEditProfiles from './AdminEditProfiles' const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; function PersonCard({ person, personType, kids, request = false, trash = true }) { - const handleDescargar = async (person) => { - // Download the enrollment_document - const documento = person.enrollment_document; - const nombreArchivo = 'documento_de_enlistamiento.pdf'; // Puedes cambiar el nombre del archivo según lo necesites + const handleDescargar = async(person) => { + const descargarDocumento = (documento, nombreArchivo) => { + const enlaceDescarga = document.createElement('a'); + enlaceDescarga.href = documento; + enlaceDescarga.download = nombreArchivo; - // Crear un objeto Blob a partir de los datos del documento - const blob = new Blob([documento], { type: 'application/pdf' }); + // Simular un clic en el enlace para descargar el archivo + enlaceDescarga.click(); + }; - // Crear un enlace temporal - const enlaceDescarga = document.createElement('a'); - enlaceDescarga.href = window.URL.createObjectURL(blob); - enlaceDescarga.download = nombreArchivo; + // Descargar cada documento + descargarDocumento(`${API_ENDPOINT}export/files/volunteers?name=${person.first_name}&surname=${person.last_name}`, 'documentos_voluntario.zip'); - // Hacer clic en el enlace para descargar el archivo - enlaceDescarga.click(); - toast.error("Se descarga vacio porque la api pasa enlaces en vez de archivos", { - autoClose: 5000 + // Mostrar un mensaje de éxito + toast.success("Descarga existosa", { + autoClose: 5000 }); - }; +}; const handleAceptar = async (person) => { - console.log(person) person.status = "ACEPTADO"; + let url; + if (person.volunteer) { + url = `${API_ENDPOINT}volunteer/${person.volunteer}/`; + } else if (person.id) { + url = `${API_ENDPOINT}student/${person.id}/`; + } - const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`, { + const update = await axios.patch(url, { status: person.status }); console.log('update', update); @@ -49,13 +51,18 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) }) } window.location.reload(); - } +} const handleRechazar = async (person) => { - console.log(person) + let url; person.status = "RECHAZADO"; + if (person.volunteer) { + url = `${API_ENDPOINT}volunteer/${person.volunteer}/`; + } else if (person.id) { + url = `${API_ENDPOINT}student/${person.id}/`; + } - const update = await axios.patch(`${API_ENDPOINT}volunteer/${person.id}/`, { + const update = await axios.patch(url, { status: person.status }); console.log('update', update); @@ -82,7 +89,7 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) await axios.delete(`${API_ENDPOINT}student/${person.id}/`); } else if (personType === 'Voluntarios') { console.log(person.id); - await axios.delete(`${API_ENDPOINT}volunteer/${person.id}/`); + await axios.delete(`${API_ENDPOINT}volunteer/${person.volunteer}/`); } else { await axios.delete(`${API_ENDPOINT}user/${person.id}/`); } From 1b1dd52876c291b9871233bbf1e0903561dc98b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Apr 2024 15:25:44 +0200 Subject: [PATCH 12/13] fix:Implemented download a file from a student --- src/components/PersonCard.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/PersonCard.js b/src/components/PersonCard.js index 83c71a82..0f11ba35 100644 --- a/src/components/PersonCard.js +++ b/src/components/PersonCard.js @@ -19,8 +19,11 @@ function PersonCard({ person, personType, kids, request = false, trash = true }) }; // Descargar cada documento + if(person.volunteer){ descargarDocumento(`${API_ENDPOINT}export/files/volunteers?name=${person.first_name}&surname=${person.last_name}`, 'documentos_voluntario.zip'); - + } else if (person.id) { + descargarDocumento(person.enrollment_document, 'documentos_student.pdf'); + } // Mostrar un mensaje de éxito toast.success("Descarga existosa", { autoClose: 5000 From a82aa252cd194601be4659713d04db728da7dc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 11 Apr 2024 14:44:01 +0200 Subject: [PATCH 13/13] fix:Solved conflicts with develop --- src/components/UpdateProfile.js | 38 +++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/UpdateProfile.js b/src/components/UpdateProfile.js index c67968c8..4ea25ccd 100644 --- a/src/components/UpdateProfile.js +++ b/src/components/UpdateProfile.js @@ -4,14 +4,19 @@ import 'react-toastify/dist/ReactToastify.css'; import '../styles/styles.css'; import axios from 'axios'; import {useNavigate} from 'react-router-dom'; +import avatarImage from '../logo/avatar.png'; + const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT; const UpdateProfile = ({tipo,id}) => { - console.log(id) + + const [avatar, setAvatar] = useState(""); + const [valoresList, setValores] = useState([]); + const spanishIdFormat = /^[XYZ]?\d{5,8}[A-Z]$/; const navigate = useNavigate(); @@ -34,6 +39,11 @@ const UpdateProfile = ({tipo,id}) => { fetchData(); }, []); + useEffect(() => { + console.log("prueba", valoresList.avatar); + setAvatar(valoresList.avatar); + }, [valoresList]); + //Atributos const [name, setName] = useState(""); @@ -80,7 +90,7 @@ const UpdateProfile = ({tipo,id}) => { const { data } = update; if (data.message) { window.alert(data.message); - }else if(id && valoresList.role !== "EDUCADOR"){ + if(id && valoresList.role !== "EDUCADOR"){ navigate(`/admin/${valoresList.role + "S"}`); }else if(id && valoresList.role === "EDUCADOR"){ @@ -89,8 +99,28 @@ const UpdateProfile = ({tipo,id}) => { else { navigate(`/${tipo}/perfil`); } + }else { + const toastId = toast.success("Datos actualizados con éxito.", { autoClose: 800 }); + const checkToast = setInterval(() => { + if (!toast.isActive(toastId)) { + clearInterval(checkToast); + navigate(`/${tipo}/perfil`); + } + }, 1000); + } } catch (error) { - toast.error("Datos no válidos."); + if (error.response.data.email) { + toast.error("Formato del correo incorrecto."); + } else if (error.response.data.phone) { + toast.error("Formato del telefono incorrecto"); + } + else if (!id.match(spanishIdFormat)) { + toast.error('Formato de identificación inválido'); + return; + } + else { + toast.error("Datos no válidos."); + } } }; @@ -99,7 +129,7 @@ const UpdateProfile = ({tipo,id}) => { <>
- {"imagen"} + imagen