diff --git a/Back-End/Subscriptions/views/guardian_views.py b/Back-End/Subscriptions/views/guardian_views.py index d04fe84..de449c9 100644 --- a/Back-End/Subscriptions/views/guardian_views.py +++ b/Back-End/Subscriptions/views/guardian_views.py @@ -50,11 +50,22 @@ class DissociateGuardianView(APIView): # Récupérer le guardian guardian = Guardian.objects.get(id=guardian_id) + # Vérifier s'il y a d'autres guardians associés au student + other_guardians = student.guardians.exclude(id=guardian_id) + if not other_guardians.exists(): + return JsonResponse( + {"error": "Impossible de dissocier ce responsable car il n'en existe aucun autre rattaché à l'élève."}, + status=status.HTTP_400_BAD_REQUEST + ) + # Supprimer la relation entre le student et le guardian student.guardians.remove(guardian) - if guardian.profile_role: - guardian.profile_role.save() + # Mettre à jour le responsable principal (par exemple, le premier autre guardian) + new_main_guardian = other_guardians.first() + if new_main_guardian: + # Logique pour définir le nouveau responsable principal + print(f"Le guardian {new_main_guardian} devient le responsable principal.") isGuardianDeleted = False # Vérifier si le guardian n'est plus associé à aucun élève @@ -76,16 +87,6 @@ class DissociateGuardianView(APIView): # Supprimer le guardian guardian.delete() - # Récupérer le RegistrationForm associé au Student - registerForm = bdd.getObject(RegistrationForm, "student__id", student_id) - if registerForm: - # Réinitialiser le statut en "Créé" - registerForm.status = RegistrationForm.RegistrationFormStatus.RF_CREATED - registerForm.save() - - # Supprimer le fichier et le dossier associés - util.delete_registration_files(registerForm) - return JsonResponse( { "message": f"Le guardian {guardian.last_name} {guardian.first_name} a été dissocié de l'étudiant {student.last_name} {student.first_name}.", diff --git a/Front-End/src/app/[locale]/admin/subscriptions/page.js b/Front-End/src/app/[locale]/admin/subscriptions/page.js index 606f684..5089c24 100644 --- a/Front-End/src/app/[locale]/admin/subscriptions/page.js +++ b/Front-End/src/app/[locale]/admin/subscriptions/page.js @@ -142,15 +142,6 @@ export default function Page({ params: { locale } }) { setIsOpen(false); }; - const handleOpenAddGuardian = (eleveSelected) => { - setIsOpenAddGuardian(true); - setStudent(eleveSelected); - }; - - const handleCloseAddGuardian = () => { - setIsOpenAddGuardian(false); - }; - const openModalAssociationEleve = (eleveSelected) => { setIsOpenAffectationClasse(true); setStudent(eleveSelected); @@ -1175,22 +1166,6 @@ export default function Page({ params: { locale } }) { )} /> )} - {isOpenAddGuardian && ( - ( - - )} - /> - )} {isSepaUploadModalOpen && ( { }, } ); + if (!response.ok) { - throw new Error('Erreur lors de la dissociation.'); + // Extraire le message d'erreur du backend + const errorData = await response.json(); + const errorMessage = + errorData?.error || 'Une erreur est survenue lors de la dissociation.'; + + // Jeter une erreur avec le message spécifique + throw new Error(errorMessage); } + return response.json(); }; diff --git a/Front-End/src/components/Inscription/InscriptionForm.js b/Front-End/src/components/Inscription/InscriptionForm.js index 0c8fc71..0beb4b8 100644 --- a/Front-End/src/components/Inscription/InscriptionForm.js +++ b/Front-End/src/components/Inscription/InscriptionForm.js @@ -21,7 +21,6 @@ const InscriptionForm = ({ tuitionFees, profiles, onSubmit, - currentStep, groups, showOnlyStep2 = false, }) => { @@ -54,7 +53,7 @@ const InscriptionForm = ({ }; }); - const [step, setStep] = useState(currentStep || 1); + const [step, setStep] = useState(1); const [selectedStudent, setSelectedEleve] = useState(''); const [existingGuardians, setExistingGuardians] = useState([]); const [totalRegistrationAmount, setTotalRegistrationAmount] = useState(0); @@ -134,10 +133,6 @@ const InscriptionForm = ({ formDataRef.current = formData; // Mettre à jour la référence à chaque changement de formData }, [formData]); - useEffect(() => { - setStep(currentStep || 1); - }, [currentStep]); - const handleToggleChange = () => { setFormData({ ...formData, autoMail: !formData.autoMail }); }; diff --git a/Front-End/src/components/ProfileDirectory.js b/Front-End/src/components/ProfileDirectory.js index d6916a3..914c1ed 100644 --- a/Front-End/src/components/ProfileDirectory.js +++ b/Front-End/src/components/ProfileDirectory.js @@ -111,7 +111,7 @@ const ProfileDirectory = ({ setPopupVisible(true); }) .catch((error) => { - setPopupMessage('Erreur lors de la dissociation du responsable.'); + setPopupMessage(error.message); setPopupVisible(true); }); setConfirmPopupVisible(false);