mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-04 01:51:28 +00:00
feat: Ajout de la photo pour le dossier de l'élève + correction
sauvegarde des datas des responsables
This commit is contained in:
@ -4,6 +4,7 @@ import React, { useEffect } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Trash2, Plus, Users } from 'lucide-react';
|
||||
import SectionHeader from '@/components/SectionHeader';
|
||||
import { useEstablishment } from '@/context/EstablishmentContext';
|
||||
|
||||
export default function ResponsableInputFields({
|
||||
guardians,
|
||||
@ -12,6 +13,7 @@ export default function ResponsableInputFields({
|
||||
setIsPageValid,
|
||||
}) {
|
||||
const t = useTranslations('ResponsableInputFields');
|
||||
const { selectedEstablishmentId } = useEstablishment();
|
||||
|
||||
useEffect(() => {
|
||||
const isValid =
|
||||
@ -38,7 +40,7 @@ export default function ResponsableInputFields({
|
||||
(field === 'first_name' &&
|
||||
(!guardians[index].first_name ||
|
||||
guardians[index].first_name.trim() === '')) ||
|
||||
(field === 'email' &&
|
||||
(field === 'associated_profile_email' &&
|
||||
(!guardians[index].associated_profile_email ||
|
||||
guardians[index].associated_profile_email.trim() === '')) ||
|
||||
(field === 'birth_date' &&
|
||||
@ -56,16 +58,45 @@ export default function ResponsableInputFields({
|
||||
};
|
||||
|
||||
const onGuardiansChange = (id, field, value) => {
|
||||
const updatedGuardians = guardians.map((guardian) =>
|
||||
guardian.id === id ? { ...guardian, [field]: value } : guardian
|
||||
);
|
||||
const updatedGuardians = guardians.map((guardian) => {
|
||||
if (guardian.id === id) {
|
||||
const updatedGuardian = { ...guardian, [field]: value };
|
||||
|
||||
// Synchroniser profile_data.email et profile_data.username avec associated_profile_email
|
||||
if (field === 'associated_profile_email') {
|
||||
updatedGuardian.profile_role_data.profile_data.email = value;
|
||||
updatedGuardian.profile_role_data.profile_data.username = value;
|
||||
}
|
||||
|
||||
return updatedGuardian;
|
||||
}
|
||||
return guardian;
|
||||
});
|
||||
|
||||
setGuardians(updatedGuardians);
|
||||
};
|
||||
|
||||
const addGuardian = () => {
|
||||
setGuardians([
|
||||
...guardians,
|
||||
{ id: Date.now(), name: '', email: '', phone: '' },
|
||||
{
|
||||
profile_role_data: {
|
||||
establishment: selectedEstablishmentId,
|
||||
role_type: 2,
|
||||
is_active: false,
|
||||
profile_data: {
|
||||
email: '',
|
||||
password: 'Provisoire01!',
|
||||
username: '',
|
||||
},
|
||||
},
|
||||
last_name: '',
|
||||
first_name: '',
|
||||
birth_date: '',
|
||||
address: '',
|
||||
phone: '',
|
||||
profession: '',
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
@ -143,7 +174,8 @@ export default function ResponsableInputFields({
|
||||
}}
|
||||
required
|
||||
errorMsg={
|
||||
getError(index, 'email') || getLocalError(index, 'email')
|
||||
getError(index, 'associated_profile_email') ||
|
||||
getLocalError(index, 'associated_profile_email')
|
||||
}
|
||||
/>
|
||||
<InputPhone
|
||||
|
||||
Reference in New Issue
Block a user