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