mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
feat: Gestion de la création d'un nouveau guardian, de l'association
avec un guardian dumême établissement, et de l'association avec un guardian d'un autre établissement
This commit is contained in:
@ -43,7 +43,7 @@ import {
|
||||
fetchRegistrationFees,
|
||||
fetchTuitionFees } from '@/app/actions/schoolAction';
|
||||
|
||||
import { createProfile, deleteProfile } from '@/app/actions/authAction';
|
||||
import { createProfile, deleteProfile, fetchProfiles } from '@/app/actions/authAction';
|
||||
|
||||
import {
|
||||
BASE_URL,
|
||||
@ -86,6 +86,7 @@ export default function Page({ params: { locale } }) {
|
||||
const [registrationFees, setRegistrationFees] = useState([]);
|
||||
const [tuitionFees, setTuitionFees] = useState([]);
|
||||
const [groups, setGroups] = useState([]);
|
||||
const [profiles, setProfiles] = useState([]);
|
||||
|
||||
const csrfToken = useCsrfToken();
|
||||
const { selectedEstablishmentId } = useEstablishment();
|
||||
@ -235,7 +236,14 @@ useEffect(() => {
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('Error fetching file groups:', error);
|
||||
}),
|
||||
fetchProfiles()
|
||||
.then(data => {
|
||||
setProfiles(data);
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('Error fetching profileRoles:', error);
|
||||
}),
|
||||
])
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
@ -373,24 +381,46 @@ useEffect(()=>{
|
||||
student: {
|
||||
last_name: updatedData.studentLastName,
|
||||
first_name: updatedData.studentFirstName,
|
||||
guardians: updatedData.selectedGuardians.length !== 0 ? updatedData.selectedGuardians.map(guardianId => ({ id: guardianId })) : [{
|
||||
profile_role_data: {
|
||||
establishment: selectedEstablishmentId,
|
||||
role_type: 2,
|
||||
is_active: false,
|
||||
profile_data: {
|
||||
email: updatedData.guardianEmail,
|
||||
password: 'Provisoire01!',
|
||||
username: updatedData.guardianEmail,
|
||||
}
|
||||
},
|
||||
last_name: updatedData.guardianLastName,
|
||||
first_name: updatedData.guardianFirstName,
|
||||
birth_date: updatedData.guardianBirthDate,
|
||||
address: updatedData.guardianAddress,
|
||||
phone: updatedData.guardianPhone,
|
||||
profession: updatedData.guardianProfession
|
||||
}],
|
||||
guardians: updatedData.selectedGuardians.length !== 0
|
||||
? updatedData.selectedGuardians.map(guardianId => ({ id: guardianId }))
|
||||
: (() => {
|
||||
if (updatedData.isExistingParentProfile) {
|
||||
return [{
|
||||
profile_role_data: {
|
||||
establishment: selectedEstablishmentId,
|
||||
role_type: 2,
|
||||
is_active: false,
|
||||
profile: updatedData.existingProfileId, // Associer au profil existant
|
||||
},
|
||||
last_name: updatedData.guardianLastName,
|
||||
first_name: updatedData.guardianFirstName,
|
||||
birth_date: updatedData.guardianBirthDate,
|
||||
address: updatedData.guardianAddress,
|
||||
phone: updatedData.guardianPhone,
|
||||
profession: updatedData.guardianProfession
|
||||
}];
|
||||
}
|
||||
|
||||
// Si aucun profil existant n'est trouvé, créer un nouveau profil
|
||||
return [{
|
||||
profile_role_data: {
|
||||
establishment: selectedEstablishmentId,
|
||||
role_type: 2,
|
||||
is_active: false,
|
||||
profile_data: {
|
||||
email: updatedData.guardianEmail,
|
||||
password: 'Provisoire01!',
|
||||
username: updatedData.guardianEmail,
|
||||
}
|
||||
},
|
||||
last_name: updatedData.guardianLastName,
|
||||
first_name: updatedData.guardianFirstName,
|
||||
birth_date: updatedData.guardianBirthDate,
|
||||
address: updatedData.guardianAddress,
|
||||
phone: updatedData.guardianPhone,
|
||||
profession: updatedData.guardianProfession
|
||||
}];
|
||||
})(),
|
||||
sibling: []
|
||||
},
|
||||
fees: allFeesIds,
|
||||
@ -699,6 +729,7 @@ const columnsSubscribed = [
|
||||
registrationFees={registrationFees.filter(fee => fee.is_active)}
|
||||
tuitionFees={tuitionFees.filter(fee => fee.is_active)}
|
||||
groups={groups}
|
||||
profiles={profiles}
|
||||
onSubmit={createRF}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -113,6 +113,11 @@ export const deleteProfileRoles = (id, csrfToken) => {
|
||||
return fetch(request).then(requestResponseHandler);
|
||||
};
|
||||
|
||||
export const fetchProfiles = () => {
|
||||
return fetch(`${BE_AUTH_PROFILES_URL}`)
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createProfile = (data, csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_PROFILES_URL}`,
|
||||
|
||||
Reference in New Issue
Block a user