diff --git a/Back-End/GestionInscriptions/views.py b/Back-End/GestionInscriptions/views.py index e5f5143..f7251d4 100644 --- a/Back-End/GestionInscriptions/views.py +++ b/Back-End/GestionInscriptions/views.py @@ -133,7 +133,6 @@ class FicheInscriptionView(APIView): di.eleve.responsables.add(responsable) di.save() - ficheInscriptions_List=bdd.getAllObjects(FicheInscription) return JsonResponse(ficheEleve_serializer.data, safe=False) return JsonResponse(ficheEleve_serializer.errors, safe=False) diff --git a/Front-End/src/app/[locale]/admin/subscriptions/page.js b/Front-End/src/app/[locale]/admin/subscriptions/page.js index 0e3e3ff..551a710 100644 --- a/Front-End/src/app/[locale]/admin/subscriptions/page.js +++ b/Front-End/src/app/[locale]/admin/subscriptions/page.js @@ -183,7 +183,7 @@ export default function Page({ params: { locale } }) { useEffect(() => { fetchClasses(); fetchStudents(); - }, []); + }, [fichesInscriptionsDataEnCours]); useEffect(() => { const fetchDataAndSetState = () => { @@ -302,9 +302,17 @@ export default function Page({ params: { locale } }) { }) .then(response => response.json()) .then(data => { - console.log('Success:', data); - setFichesInscriptionsDataEnCours(prevState => [...prevState, data]); - setTotalPending(totalPending+1); + console.log('Success:', data); + setFichesInscriptionsDataEnCours(prevState => { + if (prevState && prevState.length > 0) { + return [...prevState, data]; + } + return prevState; + }); + setTotalPending(totalPending+1); + if (updatedData.autoMail) { + sendConfirmFicheInscription(data.eleve.id, updatedData.eleveNom, updatedData.elevePrenom); + } }) .catch((error) => { console.error('Error:', error); @@ -344,7 +352,7 @@ export default function Page({ params: { locale } }) { responsables: [ { mail: updatedData.responsableEmail, - //telephone: telephoneResponsable, + telephone: updatedData.responsableTel, profilAssocie: idProfil // Association entre le reponsable de l'élève et le profil créé par défaut précédemment } ], @@ -363,9 +371,17 @@ export default function Page({ params: { locale } }) { }) .then(response => response.json()) .then(data => { - console.log('Success:', data); - setFichesInscriptionsDataEnCours(prevState => [...prevState, data]); - setTotalPending(totalPending+1); + console.log('Success:', data); + setFichesInscriptionsDataEnCours(prevState => { + if (prevState && prevState.length > 0) { + return [...prevState, data]; + } + return prevState; + }); + setTotalPending(totalPending+1); + if (updatedData.autoMail) { + sendConfirmFicheInscription(data.eleve.id, updatedData.eleveNom, updatedData.elevePrenom); + } }) .catch((error) => { console.error('Error:', error); @@ -623,9 +639,10 @@ const columnsSubscribed = [ isOpen={isOpen} setIsOpen={setIsOpen} title={"Création d'un nouveau dossier d'inscription"} + size='sm:w-1/4' ContentComponent={() => ( - )} /> diff --git a/Front-End/src/components/Inscription/InscriptionForm.js b/Front-End/src/components/Inscription/InscriptionForm.js index 47b262b..f9cbac8 100644 --- a/Front-End/src/components/Inscription/InscriptionForm.js +++ b/Front-End/src/components/Inscription/InscriptionForm.js @@ -1,10 +1,13 @@ import { useState } from 'react'; +import { User, Mail, Phone, UserCheck } from 'lucide-react'; +import InputTextIcon from '@/components/InputTextIcon'; const InscriptionForm = ( { eleves, onSubmit }) => { const [formData, setFormData] = useState({ eleveNom: '', elevePrenom: '', responsableEmail: '', + responsableTel: '', selectedResponsables: [], responsableType: 'new' }); @@ -12,6 +15,13 @@ const InscriptionForm = ( { eleves, onSubmit }) => { const [step, setStep] = useState(1); const [selectedEleve, setSelectedEleve] = useState(''); const [existingResponsables, setExistingResponsables] = useState([]); + const [autoMail, setAutoMail] = useState(false); + const maxStep = 4 + + const handleToggleChange = () => { + setAutoMail(!autoMail); + setFormData({ ...formData, autoMail: !autoMail }); + }; const handleChange = (e) => { const { name, value, type } = e.target; @@ -22,7 +32,7 @@ const InscriptionForm = ( { eleves, onSubmit }) => { }; const nextStep = () => { - if (step < 3) { + if (step < maxStep) { setStep(step + 1); } }; @@ -52,149 +62,192 @@ const InscriptionForm = ( { eleves, onSubmit }) => { }; const submit = () => { - onSubmit(formData); + onSubmit({ ...formData, autoMail }); } - console.log(eleves) - return (
{step === 1 && (

Nouvel élève

- -
)} {step === 2 && (
-

Responsable(s)

-
- - -
- {formData.responsableType === 'new' && ( -
- Responsable(s) +
+ + +
+ {formData.responsableType === 'new' && ( + -
- )} - - {formData.responsableType === 'existing' && ( -
-
- - - - - - - - - {eleves.map((eleve, index) => ( - handleEleveSelection(eleve)} - > - - + )} + + {formData.responsableType === 'existing' && ( +
+
+
NomPrénom
{eleve.nom}{eleve.prenom}
+ + + + - ))} - -
NomPrénom
-
- {selectedEleve && ( -
-

Responsables associés à {selectedEleve.nom} {selectedEleve.prenom} :

- {existingResponsables.map((responsable) => ( -
- -
- ))} + + + {eleves.map((eleve, index) => ( + handleEleveSelection(eleve)} + > + {eleve.nom} + {eleve.prenom} + + ))} + +
- )} -
- )} -
+ {selectedEleve && ( +
+

Responsables associés à {selectedEleve.nom} {selectedEleve.prenom} :

+ {existingResponsables.map((responsable) => ( +
+ +
+ ))} +
+ )} +
+ )} + )} {step === 3 && ( +
+

Téléphone (optionnel)

+ +
+ )} + + {step === maxStep && (

Récapitulatif

-
-

Élève

-

Nom : {formData.eleveNom}

-

Prénom : {formData.elevePrenom}

-
-
-

Responsable(s)

- {formData.responsableType === 'new' && ( -

Email du nouveau responsable : {formData.responsableEmail}

- )} - {formData.responsableType === 'existing' && selectedEleve && ( +
+
+
-

Responsables associés à {selectedEleve.nom} {selectedEleve.prenom} :

-
    - {existingResponsables.filter(responsable => formData.selectedResponsables.includes(responsable.id)).map((responsable) => ( -
  • - {responsable.nom && responsable.prenom ? `${responsable.nom} ${responsable.prenom}` : responsable.mail} -
  • - ))} -
+

Élève

+

Nom : {formData.eleveNom}

+

Prénom : {formData.elevePrenom}

- )} +
+
+
+
+ + {formData.responsableType === 'new' && ( +
+

Responsable

+

Email : {formData.responsableEmail}

+

Téléphone : {formData.responsableTel}

+
+ )} + {formData.responsableType === 'existing' && selectedEleve && ( +
+

Responsable(s)

+

Associé(s) à : {selectedEleve.nom} {selectedEleve.prenom}

+
    + {existingResponsables.filter(responsable => formData.selectedResponsables.includes(responsable.id)).map((responsable) => ( +
  • + {responsable.nom && responsable.prenom ? `${responsable.nom} ${responsable.prenom}` : responsable.mail} +
  • + ))} +
+
+ )} +
+
+
+ +
+ + +
)} @@ -208,7 +261,7 @@ const InscriptionForm = ( { eleves, onSubmit }) => { Précédent )} - {step < 3 ? ( + {step < maxStep ? (