diff --git a/Back-End/GestionInscriptions/views.py b/Back-End/GestionInscriptions/views.py
index 4007bcc..e5f5143 100644
--- a/Back-End/GestionInscriptions/views.py
+++ b/Back-End/GestionInscriptions/views.py
@@ -134,7 +134,7 @@ class FicheInscriptionView(APIView):
di.save()
ficheInscriptions_List=bdd.getAllObjects(FicheInscription)
- return JsonResponse({'totalInscrits':len(ficheInscriptions_List)}, safe=False)
+ return JsonResponse(ficheEleve_serializer.data, safe=False)
return JsonResponse(ficheEleve_serializer.errors, safe=False)
diff --git a/Front-End/src/app/[locale]/admin/students/page.js b/Front-End/src/app/[locale]/admin/students/page.js
index 6b9deae..fc2bb8b 100644
--- a/Front-End/src/app/[locale]/admin/students/page.js
+++ b/Front-End/src/app/[locale]/admin/students/page.js
@@ -24,7 +24,8 @@ import { BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL,
BK_GESTIONINSCRIPTION_ARCHIVE_URL,
BK_GESTIONINSCRIPTION_CLASSES_URL,
BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL,
- BK_GESTIONINSCRIPTION_ELEVES_URL } from '@/utils/Url';
+ BK_GESTIONINSCRIPTION_ELEVES_URL,
+ BK_PROFILE_URL } from '@/utils/Url';
import DjangoCSRFToken from '@/components/DjangoCSRFToken'
import useCsrfToken from '@/hooks/useCsrfToken';
@@ -64,6 +65,10 @@ export default function Page({ params: { locale } }) {
setIsOpen(true);
}
+ const closeModal = () => {
+ setIsOpen(false);
+ }
+
const openModalAssociationEleve = (eleveSelected) => {
setIsOpenAffectationClasse(true);
setEleve(eleveSelected);
@@ -273,6 +278,109 @@ export default function Page({ params: { locale } }) {
fetchData(newPage, itemsPerPage); // Appeler fetchData directement ici
};
+ const createDI = (updatedData) => {
+ if (updatedData.selectedResponsables.length !== 0) {
+ const selectedResponsablesIds = updatedData.selectedResponsables.map(responsableId => responsableId)
+
+ const data = {
+ eleve: {
+ nom: updatedData.eleveNom,
+ prenom: updatedData.elevePrenom,
+ },
+ idResponsables: selectedResponsablesIds
+ };
+
+ const url = `${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}`;
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-CSRFToken': csrfToken
+ },
+ body: JSON.stringify(data),
+ credentials: 'include'
+ })
+ .then(response => response.json())
+ .then(data => {
+ console.log('Success:', data);
+ setFichesInscriptionsDataEnCours(prevState => [...prevState, data]);
+ setTotalPending(totalPending+1);
+ })
+ .catch((error) => {
+ console.error('Error:', error);
+ });
+ }
+ else {
+ // Création d'un profil associé à l'adresse mail du responsable saisie
+ // Le profil est inactif
+ const request = new Request(
+ `${BK_PROFILE_URL}`,
+ {
+ method:'POST',
+ headers: {
+ 'Content-Type':'application/json',
+ 'X-CSRFToken': csrfToken
+ },
+ credentials: 'include',
+ body: JSON.stringify( {
+ email: updatedData.responsableEmail,
+ password: 'Provisoire01!',
+ username: updatedData.responsableEmail,
+ is_active: 0, // On rend le profil inactif : impossible de s'y connecter dans la fenêtre du login tant qu'il ne s'est pas inscrit
+ droit:1
+ }),
+ }
+ );
+ fetch(request).then(response => response.json())
+ .then(response => {
+ console.log('Success:', response);
+ if (response.id) {
+ let idProfil = response.id;
+
+ const data = {
+ eleve: {
+ nom: updatedData.eleveNom,
+ prenom: updatedData.elevePrenom,
+ responsables: [
+ {
+ mail: updatedData.responsableEmail,
+ //telephone: telephoneResponsable,
+ profilAssocie: idProfil // Association entre le reponsable de l'élève et le profil créé par défaut précédemment
+ }
+ ],
+ freres: []
+ }
+ };
+ const url = `${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}`;
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-CSRFToken': csrfToken
+ },
+ body: JSON.stringify(data),
+ credentials: 'include'
+ })
+ .then(response => response.json())
+ .then(data => {
+ console.log('Success:', data);
+ setFichesInscriptionsDataEnCours(prevState => [...prevState, data]);
+ setTotalPending(totalPending+1);
+ })
+ .catch((error) => {
+ console.error('Error:', error);
+ });
+ }
+ })
+ .catch(error => {
+ console.error('Error fetching data:', error);
+ error = error.errorMessage;
+ console.log(error);
+ });
+ }
+ closeModal();
+ }
+
const validateAndAssociate = (updatedData) => {
fetch(`${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}/${eleve.id}`, {
method: 'PUT',
@@ -516,7 +624,9 @@ const columnsSubscribed = [
setIsOpen={setIsOpen}
title={"Création d'un nouveau dossier d'inscription"}
ContentComponent={() => (
-
+
)}
/>
)}
diff --git a/Front-End/src/components/Inscription/InscriptionForm.js b/Front-End/src/components/Inscription/InscriptionForm.js
index 7bc2e2c..47b262b 100644
--- a/Front-End/src/components/Inscription/InscriptionForm.js
+++ b/Front-End/src/components/Inscription/InscriptionForm.js
@@ -1,46 +1,25 @@
-import { useState, useEffect } from 'react';
-import {BK_GESTIONINSCRIPTION_ELEVES_URL,
- BK_PROFILE_URL,
- BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL } from '@/utils/Url';
-import DjangoCSRFToken from '@/components/DjangoCSRFToken'
-import useCsrfToken from '@/hooks/useCsrfToken';
-import { useSearchParams, redirect, useRouter } from 'next/navigation'
+import { useState } from 'react';
+
+const InscriptionForm = ( { eleves, onSubmit }) => {
+ const [formData, setFormData] = useState({
+ eleveNom: '',
+ elevePrenom: '',
+ responsableEmail: '',
+ selectedResponsables: [],
+ responsableType: 'new'
+ });
-const InscriptionForm = () => {
const [step, setStep] = useState(1);
- const [eleveNom, setEleveNom] = useState('');
- const [elevePrenom, setElevePrenom] = useState('');
- const [responsableEmail, setResponsableEmail] = useState('');
- const [responsableType, setResponsableType] = useState('new');
- const [selectedEleve, setSelectedEleve] = useState(null);
+ const [selectedEleve, setSelectedEleve] = useState('');
const [existingResponsables, setExistingResponsables] = useState([]);
- const [allEleves, setAllEleves] = useState([]);
- const [selectedResponsables, setSelectedResponsables] = useState([]);
- const csrfToken = useCsrfToken();
- const router = useRouter();
-
- useEffect(() => {
- const request = new Request(
- `${BK_GESTIONINSCRIPTION_ELEVES_URL}`,
- {
- method:'GET',
- headers: {
- 'Content-Type':'application/json'
- },
- }
- );
- fetch(request).then(response => response.json())
- .then(data => {
- console.log('Success:', data);
- setAllEleves(data);
- })
- .catch(error => {
- console.error('Error fetching data:', error);
- error = error.message;
- console.log(error);
- });
- }, []);
+ const handleChange = (e) => {
+ const { name, value, type } = e.target;
+ setFormData((prevState) => ({
+ ...prevState,
+ [name]: value,
+ }));
+ };
const nextStep = () => {
if (step < 3) {
@@ -56,165 +35,52 @@ const InscriptionForm = () => {
const handleEleveSelection = (eleve) => {
setSelectedEleve(eleve);
+ setFormData((prevData) => ({
+ ...prevData,
+ selectedResponsables: []
+ }));
setExistingResponsables(eleve.responsables);
};
- const handleResponsableSelection = (id) => {
- setSelectedResponsables((prevSelectedResponsables) => {
- const newSelectedResponsables = new Set(prevSelectedResponsables);
- if (newSelectedResponsables.has(id)) {
- newSelectedResponsables.delete(id);
- } else {
- newSelectedResponsables.add(id);
- }
- return Array.from(newSelectedResponsables);
+ const handleResponsableSelection = (responsableId) => {
+ setFormData((prevData) => {
+ const selectedResponsables = prevData.selectedResponsables.includes(responsableId)
+ ? prevData.selectedResponsables.filter(id => id !== responsableId)
+ : [...prevData.selectedResponsables, responsableId];
+ return { ...prevData, selectedResponsables };
});
};
- const resetResponsableEmail = () => {
- setResponsableEmail('');
- };
-
- const submit = function(){
- if (selectedResponsables.length !== 0) {
- const selectedResponsablesIds = selectedResponsables.map(responsableId => responsableId)
-
- const data = {
- eleve: {
- nom: eleveNom,
- prenom: elevePrenom,
- },
- idResponsables: selectedResponsablesIds
- };
-
- console.log(data);
-
- const url = `${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}`;
- fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': csrfToken
- },
- body: JSON.stringify(data),
- credentials: 'include'
- })
- .then(response => response.json())
- .then(data => {
- console.log('Success:', data);
-
- // Ajouter vérifications sur le retour de la commande (saisies incorrecte, ...)
- window.location.reload()
- })
- .catch((error) => {
- console.error('Error:', error);
- });
- }
- else {
- // Création d'un profil associé à l'adresse mail du responsable saisie
- // Le profil est inactif
- const request = new Request(
- `${BK_PROFILE_URL}`,
- {
- method:'POST',
- headers: {
- 'Content-Type':'application/json',
- 'X-CSRFToken': csrfToken
- },
- credentials: 'include',
- body: JSON.stringify( {
- email: responsableEmail,
- password: 'Provisoire01!',
- username: responsableEmail,
- is_active: 0, // On rend le profil inactif : impossible de s'y connecter dans la fenêtre du login tant qu'il ne s'est pas inscrit
- droit:1
- }),
- }
- );
- fetch(request).then(response => response.json())
- .then(response => {
- console.log('Success:', response);
- if (response.id) {
- let idProfil = response.id;
-
- const data = {
- eleve: {
- nom: eleveNom,
- prenom: elevePrenom,
- responsables: [
- {
- mail: responsableEmail,
- //telephone: telephoneResponsable,
- profilAssocie: idProfil // Association entre le reponsable de l'élève et le profil créé par défaut précédemment
- }
- ],
- freres: []
- }
- };
- const url = `${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}`;
- fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': csrfToken
- },
- body: JSON.stringify(data),
- credentials: 'include'
- })
- .then(response => response.json())
- .then(data => {
- console.log('Success:', data);
-
- // Ajouter vérifications sur le retour de la commande (saisies incorrecte, ...)
- window.location.reload()
- })
- .catch((error) => {
- console.error('Error:', error);
- });
- }
- })
- .catch(error => {
- console.error('Error fetching data:', error);
- error = error.errorMessage;
- console.log(error);
- });
- }
-
+ const submit = () => {
+ onSubmit(formData);
}
+ console.log(eleves)
+
return (
-
+
{step === 1 && (
)}
-
{step === 2 && (
Responsable(s)
@@ -224,8 +90,8 @@ const InscriptionForm = () => {
type="radio"
name="responsableType"
value="new"
- checked={responsableType === 'new'}
- onChange={() => setResponsableType('new')}
+ checked={formData.responsableType === 'new'}
+ onChange={handleChange}
className="form-radio h-3 w-3 text-emerald-600 focus:ring-emerald-500 hover:ring-emerald-400 checked:bg-emerald-600 checked:h-3 checked:w-3"
/>
Nouveau Responsable
@@ -235,29 +101,27 @@ const InscriptionForm = () => {
type="radio"
name="responsableType"
value="existing"
- checked={responsableType === 'existing'}
- onChange={() => {
- setResponsableType('existing');
- resetResponsableEmail();
- }}
+ checked={formData.responsableType === 'existing'}
+ onChange={handleChange}
className="form-radio h-3 w-3 text-emerald-600 focus:ring-emerald-500 hover:ring-emerald-400 checked:bg-emerald-600 checked:h-3 checked:w-3"
/>
Responsable Existant
- {responsableType === 'new' && (
+ {formData.responsableType === 'new' && (
setResponsableEmail(e.target.value)}
+ name="responsableEmail"
+ value={formData.responsableEmail}
+ onChange={handleChange}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-emerald-500 focus:border-emerald-500 italic"
/>
)}
- {responsableType === 'existing' && (
+ {formData.responsableType === 'existing' && (
@@ -268,7 +132,7 @@ const InscriptionForm = () => {
- {allEleves.map((eleve, index) => (
+ {eleves.map((eleve, index) => (
{