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/171 registration of families #208

Merged
merged 27 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4a28eb6
feat: FamilyForm
fracalrod3 Apr 5, 2024
7ac292a
fix: Profile
fracalrod3 Apr 5, 2024
fa1c826
fix: Profile GET & PUT
fracalrod3 Apr 8, 2024
6719e05
fix: unused constants
fracalrod3 Apr 8, 2024
e5cc1e1
fix: Kid route
fracalrod3 Apr 8, 2024
8cd4b99
fix: put fam id
fracalrod3 Apr 8, 2024
1928221
fix: unused constant
fracalrod3 Apr 9, 2024
1d9097b
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 13, 2024
d560219
fix: merge problems
manbarjim2 Apr 13, 2024
b787dbe
feat: kid forms
manbarjim2 Apr 13, 2024
e5f75f2
fix: kid form
manbarjim2 Apr 13, 2024
bb0cb5d
Merge branch 'develop' into feature/171-registration-of-families
claugp06 Apr 15, 2024
6c7e526
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 18, 2024
4fce451
fix: urls
manbarjim2 Apr 18, 2024
56a35df
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 19, 2024
0b05cc3
fix: Redirection to registry
manbarjim2 Apr 19, 2024
fd5d45f
fix: duplicated file
manbarjim2 Apr 19, 2024
401cc26
fix: route duplicated
manbarjim2 Apr 19, 2024
c363c8f
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 20, 2024
5940cc5
fix: add correct tokens
manbarjim2 Apr 20, 2024
123e424
Merge branch 'feature/171-registration-of-families' of https://github…
manbarjim2 Apr 20, 2024
2bc7fe6
fix: password and message
manbarjim2 Apr 20, 2024
33d18ea
fix: first last name, second last name and title added
manbarjim2 Apr 20, 2024
2799538
fix: error password required in update user
manbarjim2 Apr 20, 2024
51b4017
fix: toast success, screen without headers and side menu, redirect to…
manbarjim2 Apr 20, 2024
9321d1c
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 20, 2024
f8bcc36
Merge branch 'develop' into feature/171-registration-of-families
manbarjim2 Apr 20, 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
4 changes: 4 additions & 0 deletions src/screens/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ import PartnersCalendar from './partners/PartnersCalendar';
import PartnerForm from './partners/PartnerForm';

// FAMILIES
import FamilyForm from './family/FamilyForm';
import FamilyProfile from './family/FamilyProfile';
import FamilyUpdate from './family/FamilyUpdate';
import FamilyChildren from './family/FamilyChildren';
import FamilyAuths from './family/FamilyAuths';
import FamilyAuthsPending from './family/FamilyAuthsPending';
Expand Down Expand Up @@ -224,11 +226,13 @@ function App() {
{/* FAMILIES ROUTES */}
{role === 'FAMILIA' && (
<>
<Route path="/familia/registro" exact={true} element={<FamilyForm />} />
<Route path="/familia/perfil" exact={true} element={<FamilyProfile />} />
<Route path="/familia/niños" exact={true} element={<FamilyChildren />} />
<Route path="/familia/niños/registro" exact={true} element={<FamilyChildForm />} />
<Route path="/familia/autorizaciones" exact={true} element={<FamilyAuths />} />
<Route path="/familia/autorizaciones/pendientes" exact={true} element={<FamilyAuthsPending />} />
<Route path='/familia/perfil/actualizar' exact={true} element={<FamilyUpdate/>}/>
<Route path="/familia/evaluacion/:tipoTiempo/:studentIndex" exact={true} element={<FamilyEval />} />
</>
)}
Expand Down
134 changes: 134 additions & 0 deletions src/screens/family/FamilyForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React, { useEffect, useState } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import '../../styles/styles.css';
import axios from 'axios';
import {useNavigate} from 'react-router-dom';
import LayoutProfiles from '../../components/LayoutProfiles';
import useToken from '../../components/useToken';
import { Password } from '@mui/icons-material';


const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT;


const FamilyForm = () => {
const [token, updateToken] = useToken();
const config = {
headers: {
'Authorization': `Bearer ${token}`,
}
};

const [user, setUser] = useState([]);

const navigate = useNavigate();

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

axios.get(`${API_ENDPOINT}auth/users/me/`, config)
.then(response => {
setUser(response.data);
})
.catch(error => {
console.error(error);
});

}, []);

//Atributos
const [surname1, setSurname1] = useState("");
const [surname2, setSurname2] = useState("");

//Atributos son correctos

const updatePut = async () => {
try {

Check notice on line 47 in src/screens/family/FamilyForm.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/screens/family/FamilyForm.js#L47

Unnecessary block.
const postFam = {
name: "Familia " + surname1 + " " + surname2,
};

const post = await axios.post(`${API_ENDPOINT}family/`, postFam, config);
const { data } = post;

const firstKey = Object.values(data)[0];

if (data.message) {
console.error(data.message);
} else {
axios.get(`${API_ENDPOINT}family/${firstKey}`, config)
.then(response => {
const familiaData = response.data;
console.log("fam", familiaData.id);

const updatedData = {
password: user.password,
family: familiaData.id, // Aquí se pasa el pk de la familia
email: user.email,
};

console.log("fam", familiaData.id);
console.log("updatedData", updatedData);
console.log("config", config);

axios.put(`${API_ENDPOINT}auth/users/me/`, updatedData, config)
.then(update => {
const { data: updatedUserData } = update;
navigate('/familia/perfil');
})
.catch(error => {
console.log(error);
toast.error("Error al actualizar los datos del usuario.");
});
})
.catch(error => {
console.error(error);
toast.error("Error al obtener detalles de la familia.");
});
}
} catch (error) {
toast.error("Datos no válidos.");
}
navigate('/familia/perfil');
};




return (
<>
<LayoutProfiles profile={'familia'}>
<ToastContainer />
<div className='register-container' style={{width: '300px', marginTop:'6%'}}>

<h3>Formulario de Familiares</h3>

<p>Primer Apellido</p>
<input
defaultValue={surname1}
onChange={(e) => setSurname1(e.target.value)}
type='text'
placeholder='Primer Apellido'
></input>

<p>Segundo Apellido</p>
<input
defaultValue={surname2}
onChange={(e) => setSurname2(e.target.value)}
type='text'
placeholder='Segundo Apellido'
></input>

<button onClick={updatePut} className='register-button admin' >
Proceder
</button>
</div>
</LayoutProfiles>
</>

)

};

export default FamilyForm;
17 changes: 17 additions & 0 deletions src/screens/family/FamilyUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import '../../styles/styles.css';
import UpdateProfile from '../../components/UpdateProfile';
import LayoutProfiles from '../../components/LayoutProfiles';

const VolunteerProfileUpdate = () => {

return (

<LayoutProfiles profile={'familia'}>
<UpdateProfile tipo={'familia'}/>
</LayoutProfiles>

)

};

export default VolunteerProfileUpdate;
23 changes: 7 additions & 16 deletions src/screens/homepage/LogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import useToken from '../../components/useToken';
import RoleContext from '../../components/RoleContext';
import { Api } from '@mui/icons-material';

const API_ENDPOINT = process.env.REACT_APP_API_ENDPOINT

Expand Down Expand Up @@ -125,23 +126,13 @@ function LogIn() {
}
} else if (user.role === 'FAMILIA') {
localStorage.setItem('role', 'FAMILIA')
if (user.family === null) {
//Crea un objeto familia
const response = await axios.post(`${API_ENDPOINT}family/`,
{name: "Familia " + user.last_name}, {
headers: {
'Authorization': `Bearer ${accessToken}`
}});

localStorage.setItem('familyId', response.data.id);
//El usuario es asignado esa familia
await axios.patch(`${API_ENDPOINT}auth/users/me/`,
{password: password, family: response.data.id}, {
headers: {
'Authorization': `Bearer ${accessToken}`
}});
}
setRole(user.role)
if(user.family === null){
navigate('/familia/registro');
} else {
navigate('/familia/evaluacion/diaria/0');
}

} else if (user.role === 'SOCIO') {
localStorage.setItem('role', 'SOCIO')
if (user.partner === null) {
Expand Down