mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 15:33:22 +00:00
fix: Possibilité d'ajouter un 2ème guardian, même si son mail est
associé à un profil existant
This commit is contained in:
@ -17,6 +17,7 @@ import {
|
||||
fetchRegistrationPaymentPlans,
|
||||
fetchTuitionPaymentPlans,
|
||||
} from '@/app/actions/schoolAction';
|
||||
import { fetchProfiles } from '@/app/actions/authAction';
|
||||
import { BASE_URL, FE_PARENTS_HOME_URL } from '@/utils/Url';
|
||||
import logger from '@/utils/logger';
|
||||
import FilesToUpload from '@/components/Inscription/FilesToUpload';
|
||||
@ -41,6 +42,7 @@ export default function InscriptionFormShared({
|
||||
studentId,
|
||||
csrfToken,
|
||||
selectedEstablishmentId,
|
||||
apiDocuseal,
|
||||
onSubmit,
|
||||
errors = {}, // Nouvelle prop pour les erreurs
|
||||
enable = true,
|
||||
@ -87,6 +89,8 @@ export default function InscriptionFormShared({
|
||||
// État pour suivre l'index du fichier en cours
|
||||
const [currentTemplateIndex, setCurrentTemplateIndex] = useState(0);
|
||||
|
||||
const [profiles, setProfiles] = useState([]);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// Mettre à jour les états en fonction de la valeur de `enable`
|
||||
@ -150,7 +154,7 @@ export default function InscriptionFormShared({
|
||||
}
|
||||
|
||||
// Télécharger le template
|
||||
downloadTemplate(template.slug)
|
||||
downloadTemplate(template.slug, selectedEstablishmentId, apiDocuseal)
|
||||
.then((downloadUrl) => fetch(downloadUrl))
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
@ -212,6 +216,14 @@ export default function InscriptionFormShared({
|
||||
setUploadedFiles(filteredFiles);
|
||||
});
|
||||
|
||||
fetchProfiles()
|
||||
.then((data) => {
|
||||
setProfiles(data);
|
||||
})
|
||||
.catch((error) =>
|
||||
logger.error('Error fetching profiles : ', error)
|
||||
);
|
||||
|
||||
if (selectedEstablishmentId) {
|
||||
// Fetch data for registration payment modes
|
||||
handleRegistrationPaymentModes();
|
||||
@ -492,6 +504,7 @@ export default function InscriptionFormShared({
|
||||
<ResponsableInputFields
|
||||
guardians={guardians}
|
||||
setGuardians={setGuardians}
|
||||
profiles={profiles}
|
||||
errors={errors}
|
||||
setIsPageValid={setIsPage2Valid}
|
||||
enable={enable}
|
||||
@ -587,7 +600,7 @@ export default function InscriptionFormShared({
|
||||
/>
|
||||
) : (
|
||||
<iframe
|
||||
src={`${BASE_URL}/${schoolFileTemplates[currentTemplateIndex].file}`}
|
||||
src={`${BASE_URL}${schoolFileTemplates[currentTemplateIndex].file}`}
|
||||
title="Document Viewer"
|
||||
className="w-full"
|
||||
style={{
|
||||
|
||||
@ -5,10 +5,12 @@ import { useTranslations } from 'next-intl';
|
||||
import { Trash2, Plus, Users } from 'lucide-react';
|
||||
import SectionHeader from '@/components/SectionHeader';
|
||||
import { useEstablishment } from '@/context/EstablishmentContext';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export default function ResponsableInputFields({
|
||||
guardians,
|
||||
setGuardians,
|
||||
profiles,
|
||||
errors,
|
||||
setIsPageValid,
|
||||
enable = true,
|
||||
@ -70,8 +72,17 @@ export default function ResponsableInputFields({
|
||||
|
||||
// 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;
|
||||
const existingProfile = profiles?.find(
|
||||
(profile) => profile.email === value
|
||||
);
|
||||
if (existingProfile) {
|
||||
updatedGuardian.profile_role_data.profile = existingProfile.id;
|
||||
delete updatedGuardian.profile_role_data.profile_data;
|
||||
} else {
|
||||
updatedGuardian.profile_role_data.profile_data.email = value;
|
||||
updatedGuardian.profile_role_data.profile_data.username = value;
|
||||
delete updatedGuardian.profile_role_data.profile;
|
||||
}
|
||||
}
|
||||
|
||||
return updatedGuardian;
|
||||
|
||||
Reference in New Issue
Block a user