Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/185 edit educators and volunteer #195

Merged
merged 22 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4f5044d
feat:Implemented update user by admin
ivaramlar Apr 8, 2024
5d14e64
feat:Implemented update user by admin
ivaramlar Apr 8, 2024
8614f1d
Merge branch 'develop' into feature/185--edit-educators-and-volunteer
ivaramlar Apr 8, 2024
4981566
feat:Changed color blue from link
ivaramlar Apr 8, 2024
591b03e
Merge branch 'feature/185--edit-educators-and-volunteer' of https://g…
ivaramlar Apr 8, 2024
58ecf4e
feat:Changed color blue from link
ivaramlar Apr 8, 2024
a88c9fd
feat:Solved a bug related to modify a educator
ivaramlar Apr 8, 2024
9754084
feat:Solved a bug related to modify a educator
ivaramlar Apr 9, 2024
fd850cf
feat:Added the changes requested by the reviwer
ivaramlar Apr 9, 2024
6da0e5c
feat:Now the info is shown in the update form
ivaramlar Apr 9, 2024
9c2e760
fix:Solved the problems with family request
ivaramlar Apr 10, 2024
fc01d2d
fix:Added download feature
ivaramlar Apr 10, 2024
65e6a71
fix:Solved a bug related to acept and refuse a volunteer
ivaramlar Apr 10, 2024
1b1dd52
fix:Implemented download a file from a student
ivaramlar Apr 10, 2024
f7c6c0f
fix:Solved a bug bringed by the changes made in develop
ivaramlar Apr 11, 2024
d7fb8f0
Merge branch 'develop' into feature/185--edit-educators-and-volunteer
ivaramlar Apr 11, 2024
6dff5a8
fix:Solved a bug bringed by the changes made in develop
ivaramlar Apr 11, 2024
e11186f
Merge branch 'develop' into feature/185--edit-educators-and-volunteer
ivaramlar Apr 11, 2024
2f2f7d2
Merge branch 'develop' into feature/185--edit-educators-and-volunteer
ivaramlar Apr 11, 2024
d24213f
fix:Solved conflicts with develop
ivaramlar Apr 11, 2024
2798db9
Merge branch 'feature/185--edit-educators-and-volunteer' of https://g…
ivaramlar Apr 11, 2024
a82aa25
fix:Solved conflicts with develop
ivaramlar Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/AdminEditProfiles.js
Original file line number Diff line number Diff line change
@@ -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 { id } = useParams(); // Extrae la ID de la URL

return (
<LayoutProfiles profile={'admin'} >
<UpdateProfile tipo={'admin'} id={id}/>
</LayoutProfiles>
);
};

export default AdminEditProfiles;
104 changes: 58 additions & 46 deletions src/components/PersonCard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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';
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
Expand All @@ -23,69 +27,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
}
}

Expand All @@ -97,11 +101,11 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
<p>{person.first_name}</p>
<p><strong>{person.name}</strong></p>
<p>Número de niños: {kids.filter(kid => kid.family === person.id).length}</p>
</div>
</div>
:
<div className='family-request'>
<img src={person.avatar} alt='placeholder' />
<div className='family-info' style={{ borderRight: 'none', borderBottom: 'none'}}>
<div className='family-info' style={{ borderRight: 'none', borderBottom: 'none' }}>
{personType === 'Familias-solicitudes' ? <p><strong>{person.first_name}</strong></p> : <p>{person.first_name}</p>}
<p>{person.last_name}</p>
</div>
Expand Down Expand Up @@ -132,7 +136,15 @@ function PersonCard({ person, personType, kids, request = false, trash = true })
</div>
</div>
}
{trash && <DeleteIcon className='trash' onClick={() => handleEliminar(person)} />}
{trash &&
<div className='buttons-acceptance'>
<DeleteIcon className='trash' style={{marginLeft:'87.5%'}} onClick={() => handleEliminar(person)} />
<EditIcon className='edit' style={{marginLeft:'87.5%'}} onClick={() => window.location.replace(`/admin/perfil/actualizar/${person.id}`) } />
</div>
}



</div>
);
}
Expand Down
Empty file added src/components/PersonEdit.js
Empty file.
69 changes: 42 additions & 27 deletions src/components/UpdateProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ import {useNavigate} from 'react-router-dom';

const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT;


const UpdateProfile = ({tipo}) => {

const id = localStorage.getItem('userId');
const [avatar, setAvatar] = useState("");
const UpdateProfile = ({tipo,id}) => {
console.log(id)

const [valoresList, setValores] = useState([]);

const navigate = useNavigate();

//Traemos los datos del usuario
useEffect(() => {

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);
});

const fetchData = async () => {
try {
let response;
if (id) {
response = await axios.get(`${API_ENDPOINT}user/${id}/`);
} else {
response = await axios.get(`${API_ENDPOINT}auth/users/me/`);
}
setValores(response.data);
} catch (error) {
console.error(error);
}
};

fetchData();
}, []);


//Atributos
const [name, setName] = useState("");
const [surname, setSurname] = useState("");
Expand Down Expand Up @@ -71,13 +73,20 @@ const UpdateProfile = ({tipo}) => {
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}user/${id}/`, updatedData);

const { data } = update;
if (data.message) {
window.alert(data.message);
} else {
}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`);
}
} catch (error) {
Expand All @@ -103,33 +112,34 @@ const UpdateProfile = ({tipo}) => {
defaultValue={name} //defaultValue es como value, pero permite el cambio
onChange={(e) => setName(e.target.value)}
type='text'
placeholder='Nombre'
placeholder={valoresList.first_name}
></input>

<p>Apellido</p>
<input
defaultValue={surname}
onChange={(e) => setSurname(e.target.value)}
type='text'
placeholder='Primer Apellido'
placeholder={valoresList.last_name}
></input>

<p>DNI/NIE/Pasaporte</p>
<input
defaultValue={id_number}
onChange={(e) => setId_number(e.target.value)}
type='text'
placeholder='DNI/NIE/Pasaporte'
placeholder={valoresList.id_number}
></input>

<p>Número de teléfono</p>
<input
defaultValue={phone}
onChange={(e) => setPhone(e.target.value)}
type='tel'
placeholder='Número de teléfono'
placeholder={valoresList.phone}
></input>

{id? <></>:
<>
<p>Correo electrónico</p>
<input
defaultValue={email}
Expand All @@ -138,15 +148,20 @@ const UpdateProfile = ({tipo}) => {
placeholder='ejemplo@gmail.com'
></input>

<p>Contraseña</p>

<p style={{textAlign:'center'}}>
<img src='https://www.pngall.com/wp-content/uploads/8/Red-Warning.png' style={{ width: '3.5%' }} alt='' />
Contraseña (obligatorio)
<img src='https://www.pngall.com/wp-content/uploads/8/Red-Warning.png' style={{ width: '3.5%' }} alt='' />
</p>
<input
defaultValue={password}
onChange={(e) => setPassword(e.target.value)}
type='password'
placeholder='Contraseña'
placeholder='Contraseña de tu cuenta'
></input>


</>
}
<button onClick={updateAdmin} className='register-button admin' >
Actualizar perfil
</button>
Expand Down
4 changes: 4 additions & 0 deletions src/screens/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -101,6 +103,8 @@ function App() {
{/* ADMIN ROUTES */}
<Route path="/admin/perfil" exact={true} element={<AdminProfile />} />
<Route path="/admin/perfil/actualizar" exact={true} element={<AdminProfileUpdate />} />
<Route path="/admin/perfil/actualizar/:id" exact={true} element={<AdminEditProfiles />} />


<Route path="/admin/voluntarios" element={<AdminVolunteers />} />
<Route path="/admin/voluntarios/solicitudes" exact={true} element={<AdminVolunteersRequests />} />
Expand Down
22 changes: 22 additions & 0 deletions src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,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;
}




Expand Down