mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
feat: Gestion des profils ADMIN/ECOLE (création des enseignants)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { User, Mail, Phone, UserCheck, DollarSign, Percent } from 'lucide-react';
|
||||
import InputTextIcon from '@/components/InputTextIcon';
|
||||
import ToggleSwitch from '@/components/ToggleSwitch';
|
||||
@ -51,6 +51,8 @@ const InscriptionForm = ( { students, registrationDiscounts, tuitionDiscounts, r
|
||||
const [popupVisible, setPopupVisible] = useState(false);
|
||||
const [popupMessage, setPopupMessage] = useState("");
|
||||
|
||||
const formDataRef = useRef(formData);
|
||||
|
||||
const stepTitles = {
|
||||
1: 'Nouvel élève',
|
||||
2: 'Nouveau Responsable',
|
||||
@ -103,6 +105,10 @@ const InscriptionForm = ( { students, registrationDiscounts, tuitionDiscounts, r
|
||||
|
||||
}, [registrationDiscounts, registrationFees]);
|
||||
|
||||
useEffect(() => {
|
||||
formDataRef.current = formData; // Mettre à jour la référence à chaque changement de formData
|
||||
}, [formData]);
|
||||
|
||||
useEffect(() => {
|
||||
setStep(currentStep || 1);
|
||||
}, [currentStep]);
|
||||
@ -119,24 +125,39 @@ const InscriptionForm = ( { students, registrationDiscounts, tuitionDiscounts, r
|
||||
}));
|
||||
};
|
||||
|
||||
const nextStep = () => {
|
||||
if (step === 2) {
|
||||
// Vérifier si l'adresse email saisie est rattachée à un profil existant
|
||||
const existingProfile = profiles.find(profile => profile.email === formData.guardianEmail);
|
||||
|
||||
if (existingProfile) {
|
||||
// Vérifier si le profil a un rôle de type PARENT
|
||||
const parentRole = existingProfile.roles.find(role => role.role_type === 2);
|
||||
console.log('Profil associé trouvé !', existingProfile);
|
||||
setFormData((prevData) => ({
|
||||
...prevData,
|
||||
guardianEmail: existingProfile.email, // Mettre à jour le champ guardianEmail avec l'email du profil
|
||||
isExistingParentProfile: true, // Indiquer que le profil est un parent existant
|
||||
existingProfileId: existingProfile.id
|
||||
}));
|
||||
}
|
||||
const validateAndSubmit = async () => {
|
||||
const existingProfile = profiles.find(profile => profile.email === formData.guardianEmail);
|
||||
|
||||
if (existingProfile) {
|
||||
console.log('existingProfile : ', existingProfile);
|
||||
await setFormData((prevData) => ({
|
||||
...prevData,
|
||||
guardianEmail: existingProfile.email, // Mettre à jour le champ guardianEmail avec l'email du profil
|
||||
isExistingParentProfile: true, // Indiquer que le profil est un parent existant
|
||||
existingProfileId: existingProfile.id,
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
// Utiliser la dernière version de formData via formDataRef
|
||||
logger.debug('Submitting form data:', formDataRef.current);
|
||||
onSubmit(formDataRef.current);
|
||||
};
|
||||
|
||||
const nextStep = async () => {
|
||||
if (step === 2) {
|
||||
const existingProfile = profiles.find(profile => profile.email === formData.guardianEmail);
|
||||
|
||||
if (existingProfile) {
|
||||
console.log('existingProfile : ', existingProfile);
|
||||
await setFormData((prevData) => ({
|
||||
...prevData,
|
||||
guardianEmail: existingProfile.email, // Mettre à jour le champ guardianEmail avec l'email du profil
|
||||
isExistingParentProfile: true, // Indiquer que le profil est un parent existant
|
||||
existingProfileId: existingProfile.id,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (!showOnlyStep2 && step < steps.length) {
|
||||
setStep(step + 1);
|
||||
}
|
||||
@ -182,9 +203,11 @@ const InscriptionForm = ( { students, registrationDiscounts, tuitionDiscounts, r
|
||||
};
|
||||
|
||||
const submit = () => {
|
||||
setTimeout(() => {
|
||||
logger.debug('Submitting form data:', formData);
|
||||
onSubmit(formData);
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const handleRegistrationFeeSelection = (feeId) => {
|
||||
setFormData((prevData) => {
|
||||
@ -683,7 +706,7 @@ const InscriptionForm = ( { students, registrationDiscounts, tuitionDiscounts, r
|
||||
<>
|
||||
<Button
|
||||
text="Valider"
|
||||
onClick={submit}
|
||||
onClick={validateAndSubmit}
|
||||
className={`px-4 py-2 rounded-md shadow-sm focus:outline-none ${
|
||||
(
|
||||
(step === 1 && !isStep1Valid) ||
|
||||
|
||||
Reference in New Issue
Block a user