diff --git a/Front-End/src/app/[locale]/admin/layout.js b/Front-End/src/app/[locale]/admin/layout.js index b30edd1..c35aac9 100644 --- a/Front-End/src/app/[locale]/admin/layout.js +++ b/Front-End/src/app/[locale]/admin/layout.js @@ -16,15 +16,15 @@ import { import DropdownMenu from '@/components/DropdownMenu'; import Logo from '@/components/Logo'; import { - FR_ADMIN_HOME_URL, - FR_ADMIN_SUBSCRIPTIONS_URL, - FR_ADMIN_STRUCTURE_URL, - FR_ADMIN_GRADES_URL, - FR_ADMIN_PLANNING_URL, - FR_ADMIN_SETTINGS_URL + FE_ADMIN_HOME_URL, + FE_ADMIN_SUBSCRIPTIONS_URL, + FE_ADMIN_STRUCTURE_URL, + FE_ADMIN_GRADES_URL, + FE_ADMIN_PLANNING_URL, + FE_ADMIN_SETTINGS_URL } from '@/utils/Url'; -import { disconnect } from '@/app/lib/actions'; +import { disconnect } from '@/app/lib/authAction'; export default function Layout({ children, @@ -32,12 +32,12 @@ export default function Layout({ const t = useTranslations('sidebar'); const sidebarItems = { - "admin": { "id": "admin", "name": t('dashboard'), "url": FR_ADMIN_HOME_URL, "icon": Home }, - "subscriptions": { "id": "subscriptions", "name": t('subscriptions'), "url": FR_ADMIN_SUBSCRIPTIONS_URL, "icon": Users }, - "structure": { "id": "structure", "name": t('structure'), "url": FR_ADMIN_STRUCTURE_URL, "icon": Building }, - "grades": { "id": "grades", "name": t('grades'), "url": FR_ADMIN_GRADES_URL, "icon": FileText }, - "planning": { "id": "planning", "name": t('planning'), "url": FR_ADMIN_PLANNING_URL, "icon": Calendar }, - "settings": { "id": "settings", "name": t('settings'), "url": FR_ADMIN_SETTINGS_URL, "icon": Settings } + "admin": { "id": "admin", "name": t('dashboard'), "url": FE_ADMIN_HOME_URL, "icon": Home }, + "subscriptions": { "id": "subscriptions", "name": t('subscriptions'), "url": FE_ADMIN_SUBSCRIPTIONS_URL, "icon": Users }, + "structure": { "id": "structure", "name": t('structure'), "url": FE_ADMIN_STRUCTURE_URL, "icon": Building }, + "grades": { "id": "grades", "name": t('grades'), "url": FE_ADMIN_GRADES_URL, "icon": FileText }, + "planning": { "id": "planning", "name": t('planning'), "url": FE_ADMIN_PLANNING_URL, "icon": Calendar }, + "settings": { "id": "settings", "name": t('settings'), "url": FE_ADMIN_SETTINGS_URL, "icon": Settings } }; const pathname = usePathname(); diff --git a/Front-End/src/app/[locale]/admin/page.js b/Front-End/src/app/[locale]/admin/page.js index 85e18fa..0a1f2f3 100644 --- a/Front-End/src/app/[locale]/admin/page.js +++ b/Front-End/src/app/[locale]/admin/page.js @@ -4,7 +4,7 @@ import React, { useState, useEffect } from 'react'; import { useTranslations } from 'next-intl'; import { Users, Clock, CalendarCheck, School, TrendingUp, UserCheck } from 'lucide-react'; import Loader from '@/components/Loader'; -import { BK_GESTIONENSEIGNANTS_CLASSES_URL } from '@/utils/Url'; +import { BE_SCHOOL_SCHOOLCLASSES_URL } from '@/utils/Url'; import ClasseDetails from '@/components/ClasseDetails'; // Composant StatCard pour afficher une statistique @@ -59,7 +59,7 @@ export default function DashboardPage() { const [classes, setClasses] = useState([]); const fetchClasses = () => { - fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`) + fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`) .then(response => response.json()) .then(data => { setClasses(data); diff --git a/Front-End/src/app/[locale]/admin/structure/page.js b/Front-End/src/app/[locale]/admin/structure/page.js index 06ec2f1..7ae7b2f 100644 --- a/Front-End/src/app/[locale]/admin/structure/page.js +++ b/Front-End/src/app/[locale]/admin/structure/page.js @@ -4,10 +4,10 @@ import { School, Calendar } from 'lucide-react'; import TabsStructure from '@/components/Structure/Configuration/TabsStructure'; import ScheduleManagement from '@/components/Structure/Planning/ScheduleManagement' import StructureManagement from '@/components/Structure/Configuration/StructureManagement' -import { BK_GESTIONENSEIGNANTS_SPECIALITES_URL, - BK_GESTIONENSEIGNANTS_CLASSES_URL, - BK_GESTIONENSEIGNANTS_TEACHERS_URL, - BK_GESTIONENSEIGNANTS_PLANNINGS_URL } from '@/utils/Url'; +import { BE_SCHOOL_SPECIALITIES_URL, + BE_SCHOOL_SCHOOLCLASSES_URL, + BE_SCHOOL_TEACHERS_URL, + BE_SCHOOL_PLANNINGS_URL } from '@/utils/Url'; import DjangoCSRFToken from '@/components/DjangoCSRFToken' import useCsrfToken from '@/hooks/useCsrfToken'; import { ClassesProvider } from '@/context/ClassesContext'; @@ -34,13 +34,13 @@ export default function Page() { // Fetch data for classes fetchClasses(); - + // Fetch data for schedules fetchSchedules(); }, []); const fetchSpecialities = () => { - fetch(`${BK_GESTIONENSEIGNANTS_SPECIALITES_URL}`) + fetch(`${BE_SCHOOL_SPECIALITIES_URL}`) .then(response => response.json()) .then(data => { setSpecialities(data); @@ -51,7 +51,7 @@ export default function Page() { }; const fetchTeachers = () => { - fetch(`${BK_GESTIONENSEIGNANTS_TEACHERS_URL}`) + fetch(`${BE_SCHOOL_TEACHERS_URL}`) .then(response => response.json()) .then(data => { setTeachers(data); @@ -62,7 +62,7 @@ export default function Page() { }; const fetchClasses = () => { - fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`) + fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`) .then(response => response.json()) .then(data => { setClasses(data); @@ -73,7 +73,7 @@ export default function Page() { }; const fetchSchedules = () => { - fetch(`${BK_GESTIONENSEIGNANTS_PLANNINGS_URL}`) + fetch(`${BE_SCHOOL_PLANNINGS_URL}`) .then(response => response.json()) .then(data => { setSchedules(data); @@ -141,13 +141,13 @@ export default function Page() { console.error('Erreur :', error); }); }; - + const handleDelete = (url, id, setDatas) => { fetch(`${url}/${id}`, { method:'DELETE', headers: { - 'Content-Type':'application/json', + 'Content-Type':'application/json', 'X-CSRFToken': csrfToken }, credentials: 'include' @@ -172,12 +172,12 @@ export default function Page() { {activeTab === 'Configuration' && ( <> - + /> )} diff --git a/Front-End/src/app/[locale]/admin/subscriptions/components/FileUpload.js b/Front-End/src/app/[locale]/admin/subscriptions/components/FileUpload.js index beab467..db1c60b 100644 --- a/Front-End/src/app/[locale]/admin/subscriptions/components/FileUpload.js +++ b/Front-End/src/app/[locale]/admin/subscriptions/components/FileUpload.js @@ -34,11 +34,11 @@ export default function FileUpload({ onFileUpload }) { }; const handleUpload = () => { - if (file) { + onFileUpload(file, fileName); setFile(null); setFileName(''); - } + }; return ( @@ -66,8 +66,8 @@ export default function FileUpload({ onFileUpload }) { /> diff --git a/Front-End/src/app/[locale]/admin/subscriptions/editInscription/page.js b/Front-End/src/app/[locale]/admin/subscriptions/editInscription/page.js index 1149b3b..4f2eaa5 100644 --- a/Front-End/src/app/[locale]/admin/subscriptions/editInscription/page.js +++ b/Front-End/src/app/[locale]/admin/subscriptions/editInscription/page.js @@ -2,9 +2,9 @@ import React, { useState, useEffect } from 'react'; import { useSearchParams } from 'next/navigation'; import InscriptionFormShared from '@/components/Inscription/InscriptionFormShared'; -import { FR_ADMIN_SUBSCRIPTIONS_URL, - BK_GESTIONINSCRIPTION_ELEVE_URL, - BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL } from '@/utils/Url'; +import { FE_ADMIN_SUBSCRIPTIONS_URL, + BE_SUBSCRIPTION_STUDENT_URL, + BE_SUBSCRIPTION_REGISTERFORM_URL } from '@/utils/Url'; import useCsrfToken from '@/hooks/useCsrfToken'; import { mockStudent } from '@/data/mockStudent'; @@ -13,7 +13,7 @@ const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; export default function Page() { const searchParams = useSearchParams(); const idProfil = searchParams.get('id'); - const idEleve = searchParams.get('idEleve'); // Changé de codeDI à idEleve + const studentId = searchParams.get('studentId'); // Changé de codeDI à studentId const [initialData, setInitialData] = useState(null); const [isLoading, setIsLoading] = useState(true); @@ -24,7 +24,7 @@ export default function Page() { setInitialData(mockStudent); setIsLoading(false); } else { - fetch(`${BK_GESTIONINSCRIPTION_ELEVE_URL}/${idEleve}`) // Utilisation de idEleve au lieu de codeDI + fetch(`${BE_SUBSCRIPTION_STUDENT_URL}/${studentId}`) // Utilisation de studentId au lieu de codeDI .then(response => response.json()) .then(data => { console.log('Fetched data:', data); // Pour le débogage @@ -49,7 +49,7 @@ export default function Page() { setIsLoading(false); }); } - }, [idEleve]); // Dépendance changée à idEleve + }, [studentId]); // Dépendance changée à studentId const handleSubmit = async (data) => { if (useFakeData) { @@ -58,7 +58,7 @@ export default function Page() { } try { - const response = await fetch(`${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}/${idEleve}`, { // Utilisation de idEleve + const response = await fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${studentId}`, { // Utilisation de studentId method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -72,7 +72,7 @@ export default function Page() { const result = await response.json(); console.log('Success:', result); // Redirection après succès - window.location.href = FR_ADMIN_SUBSCRIPTIONS_URL; + window.location.href = FE_ADMIN_SUBSCRIPTIONS_URL; } catch (error) { console.error('Error:', error); alert('Une erreur est survenue lors de la mise à jour des données'); @@ -84,7 +84,7 @@ export default function Page() { initialData={initialData} csrfToken={csrfToken} onSubmit={handleSubmit} - cancelUrl={FR_ADMIN_SUBSCRIPTIONS_URL} + cancelUrl={FE_ADMIN_SUBSCRIPTIONS_URL} isLoading={isLoading} /> ); diff --git a/Front-End/src/app/[locale]/admin/subscriptions/page.js b/Front-End/src/app/[locale]/admin/subscriptions/page.js index cc94eec..67e3a13 100644 --- a/Front-End/src/app/[locale]/admin/subscriptions/page.js +++ b/Front-End/src/app/[locale]/admin/subscriptions/page.js @@ -9,25 +9,33 @@ import { Search } from 'lucide-react'; import Popup from '@/components/Popup'; import Loader from '@/components/Loader'; import AlertWithModal from '@/components/AlertWithModal'; -import Button from '@/components/Button'; import DropdownMenu from "@/components/DropdownMenu"; -import { swapFormatDate } from '@/utils/Date'; import { formatPhoneNumber } from '@/utils/Telephone'; -import { MoreVertical, Send, Edit, Trash2, FileText, ChevronUp, UserPlus, CheckCircle, Plus, Download } from 'lucide-react'; +import { MoreVertical, Send, Edit, Trash2, FileText, CheckCircle, Plus, Download } from 'lucide-react'; import Modal from '@/components/Modal'; import InscriptionForm from '@/components/Inscription/InscriptionForm' import AffectationClasseForm from '@/components/AffectationClasseForm' import FileUpload from './components/FileUpload'; -import { BASE_URL, BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL, - BK_GESTIONINSCRIPTION_SEND_URL, - FR_ADMIN_SUBSCRIPTIONS_EDIT_URL, - BK_GESTIONINSCRIPTION_ARCHIVE_URL, - BK_GESTIONENSEIGNANTS_CLASSES_URL, - BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL, - BK_GESTIONINSCRIPTION_FICHERSINSCRIPTION_URL , - BK_GESTIONINSCRIPTION_ELEVES_URL, - BK_PROFILE_URL } from '@/utils/Url'; +import { + PENDING, + SUBSCRIBED, + ARCHIVED, + fetchRegisterForm, + createRegisterForm, + sendRegisterForm, + archiveRegisterForm, + fetchRegisterFormFileTemplate, + deleteRegisterFormFileTemplate, + fetchStudents, + editRegisterForm } from "@/app/lib/subscriptionAction" + +import { fetchClasses } from '@/app/lib/schoolAction'; +import { createProfile } from '@/app/lib/authAction'; + +import { + BASE_URL, + FE_ADMIN_SUBSCRIPTIONS_EDIT_URL } from '@/utils/Url'; import DjangoCSRFToken from '@/components/DjangoCSRFToken' import useCsrfToken from '@/hooks/useCsrfToken'; @@ -56,14 +64,13 @@ export default function Page({ params: { locale } }) { const [itemsPerPage, setItemsPerPage] = useState(5); // Définir le nombre d'éléments par page const [fichiers, setFichiers] = useState([]); - const [nomFichier, setNomFichier] = useState(''); - const [fichier, setFichier] = useState(null); + const [isOpen, setIsOpen] = useState(false); const [isOpenAffectationClasse, setIsOpenAffectationClasse] = useState(false); - const [eleve, setEleve] = useState(''); + const [student, setStudent] = useState(''); const [classes, setClasses] = useState([]); - const [eleves, setEleves] = useState([]); + const [students, setEleves] = useState([]); const csrfToken = useCsrfToken(); @@ -77,152 +84,90 @@ export default function Page({ params: { locale } }) { const openModalAssociationEleve = (eleveSelected) => { setIsOpenAffectationClasse(true); - setEleve(eleveSelected); + setStudent(eleveSelected); } - // Modifier la fonction fetchData pour inclure le terme de recherche - const fetchData = (page, pageSize, search = '') => { - const url = `${BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL}/pending?page=${page}&page_size=${pageSize}&search=${search}`; - fetch(url, { - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) - .then(data => { - setIsLoading(false); - if (data) { - const { fichesInscriptions, count } = data; - if (ficheInscriptions) { - setFichesInscriptionsDataEnCours(fichesInscriptions); - } - const calculatedTotalPages = count === 0 ? 1 : Math.ceil(count / pageSize); - setTotalPending(count); - setTotalPages(calculatedTotalPages); - } - console.log('Success PENDING:', data); - }) - .catch(error => { - console.error('Error fetching data:', error); - setIsLoading(false); - }); - }; - const fetchDataSubscribed = () => { - fetch(`${BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL}/subscribed`, { - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) - .then(data => { - setIsLoading(false); - if (data) { - const { fichesInscriptions, count } = data; - setTotalSubscribed(count); - if (fichesInscriptions) { - setFichesInscriptionsDataInscrits(fichesInscriptions); - } - } - console.log('Success SUBSCRIBED:', data); - }) - .catch(error => { - console.error('Error fetching data:', error); - setIsLoading(false); - }); - }; + const requestErrorHandler = (err)=>{ + setIsLoading(false); + } - const fetchDataArchived = () => { - fetch(`${BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL}/archived`, { - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) - .then(data => { - setIsLoading(false); - if (data) { - const { fichesInscriptions, count } = data; - setTotalArchives(count); - if (fichesInscriptions) { - setFichesInscriptionsDataArchivees(fichesInscriptions); - } - } - console.log('Success ARCHIVED:', data); - }) - .catch(error => { - console.error('Error fetching data:', error); - setIsLoading(false); - }); - }; + const registerFormPendingDataHandler = (data) => { + setIsLoading(false); + if (data) { + const { registerForms, count } = data; + if (registerForms) { + setFichesInscriptionsDataEnCours(registerForms); + } + const calculatedTotalPages = count === 0 ? 1 : Math.ceil(count / pageSize); + setTotalPending(count); + setTotalPages(calculatedTotalPages); + } + } - const fetchClasses = () => { - fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`) - .then(response => response.json()) - .then(data => { + const registerFormSubscribedDataHandler = (data) => { + setIsLoading(false); + if (data) { + const { registerForms, count } = data; + setTotalSubscribed(count); + if (registerForms) { + setFichesInscriptionsDataInscrits(registerForms); + } + } + } + +const registerFormArchivedDataHandler = (data) => { + setIsLoading(false); + if (data) { + const { registerForms, count } = data; + setTotalArchives(count); + if (registerForms) { + setFichesInscriptionsDataArchivees(registerForms); + } + } +} + + + + + useEffect(() => { + fetchRegisterFormFileTemplate() + .then((data)=> {setFichiers(data)}) + .catch((err)=>{ err = err.message; console.log(err);}); + }, []); + + useEffect(() => { + fetchClasses() + .then(data => { setClasses(data); console.log("Success CLASSES : ", data) }) .catch(error => { console.error('Error fetching classes:', error); }); - }; - - const fetchStudents = () => { - 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 STUDENTS:', data); - setEleves(data); - }) - .catch(error => { - console.error('Error fetching data:', error); - error = error.message; - console.log(error); + fetchStudents() + .then(data => { + console.log('Success STUDENTS:', data); + setEleves(data); + }) + .catch(error => { + console.error('Error fetching data:', error); + error = error.message; + console.log(error); }); - }; - - useEffect(() => { - const fetchFichiers = () => { - const request = new Request( - `${BK_GESTIONINSCRIPTION_FICHERSINSCRIPTION_URL}`, - { - method:'GET', - headers: { - 'Content-Type':'application/json' - }, - } - ); - fetch(request).then(response => response.json()) - .then(data => { - console.log('Success FILES:', data); - setFichiers(data); - }) - .catch(error => { - console.error('Error fetching data:', error); - error = error.message; - console.log(error); - }); - - }; - - fetchFichiers(); - }, []); - useEffect(() => { - fetchClasses(); - fetchStudents(); }, [fichesInscriptionsDataEnCours]); useEffect(() => { const fetchDataAndSetState = () => { if (!useFakeData) { - fetchData(currentPage, itemsPerPage, searchTerm); - fetchDataSubscribed(); - fetchDataArchived(); + fetchRegisterForm(PENDING, currentPage, itemsPerPage, searchTerm) + .then(registerFormPendingDataHandler) + .catch(requestErrorHandler) + fetchRegisterForm(SUBSCRIBED) + .then(registerFormSubscribedDataHandler) + .catch(requestErrorHandler) + fetchRegisterForm(ARCHIVED) + .then(registerFormArchivedDataHandler) + .catch(requestErrorHandler) } else { setTimeout(() => { setFichesInscriptionsDataEnCours(mockFicheInscription); @@ -239,7 +184,9 @@ export default function Page({ params: { locale } }) { // Modifier le useEffect pour la recherche useEffect(() => { const timeoutId = setTimeout(() => { - fetchData(currentPage, itemsPerPage, searchTerm); + fetchRegisterForm(PENDING, currentPage, itemsPerPage, searchTerm) + .then(registerFormPendingDataHandler) + .catch(requestErrorHandler) }, 500); // Debounce la recherche return () => clearTimeout(timeoutId); @@ -250,13 +197,7 @@ export default function Page({ params: { locale } }) { visible: true, message: `Attentions ! \nVous êtes sur le point d'archiver le dossier d'inscription de ${nom} ${prenom}\nÊtes-vous sûr(e) de vouloir poursuivre l'opération ?`, onConfirm: () => { - const url = `${BK_GESTIONINSCRIPTION_ARCHIVE_URL}/${id}`; - fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) + archiveRegisterForm(id) .then(data => { console.log('Success:', data); setFicheInscriptions(ficheInscriptions.filter(fiche => fiche.id !== id)); @@ -271,18 +212,12 @@ export default function Page({ params: { locale } }) { }); }; - const sendConfirmFicheInscription = (id, nom, prenom) => { + const sendConfirmRegisterForm = (id, nom, prenom) => { setPopup({ visible: true, message: `Avertissement ! \nVous êtes sur le point d'envoyer un dossier d'inscription à ${nom} ${prenom}\nÊtes-vous sûr(e) de vouloir poursuivre l'opération ?`, onConfirm: () => { - const url = `${BK_GESTIONINSCRIPTION_SEND_URL}/${id}`; - fetch(url, { - headers: { - 'Content-Type': 'application/json', - }, - }).then(response => response.json()) - .then(data => { + sendRegisterForm(id).then(data => { console.log('Success:', data); setMailSent(true); }) @@ -292,15 +227,19 @@ export default function Page({ params: { locale } }) { } }); }; - + const affectationClassFormSubmitHandler = (formdata)=> { + editRegisterForm(student.id,formData, csrfToken) + .then(data => { + console.log('Success:', data); + }) + .catch(error => { + console.error('Error :', error); + }); + } const updateStatusAction = (id, newStatus) => { console.log('Edit fiche inscription with id:', id); }; - const handleLetterClick = (letter) => { - setFilter(letter); - }; - const handleSearchChange = (event) => { setSearchTerm(event.target.value); }; @@ -310,28 +249,20 @@ 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 createRF = (updatedData) => { + console.log("updateDATA",updatedData); + if (updatedData.selectedGuardians.length !== 0) { + const selectedGuardiansIds = updatedData.selectedGuardians.map(guardianId => guardianId) const data = { - eleve: { - nom: updatedData.eleveNom, - prenom: updatedData.elevePrenom, + student: { + last_name: updatedData.studentLastName, + first_name: updatedData.studentFirstName, }, - idResponsables: selectedResponsablesIds + idGuardians: selectedGuardiansIds }; - const url = `${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}`; - fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrfToken - }, - body: JSON.stringify(data), - credentials: 'include' - }) + createRegisterForm(data,csrfToken) .then(response => response.json()) .then(data => { console.log('Success:', data); @@ -343,7 +274,7 @@ export default function Page({ params: { locale } }) { }); setTotalPending(totalPending+1); if (updatedData.autoMail) { - sendConfirmFicheInscription(data.eleve.id, updatedData.eleveNom, updatedData.elevePrenom); + sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName); } }) .catch((error) => { @@ -353,55 +284,35 @@ export default function Page({ params: { locale } }) { 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:2 // Profil PARENT - }), - } - ); - fetch(request).then(response => response.json()) + const data = { + email: updatedData.guardianEmail, + password: 'Provisoire01!', + username: updatedData.guardianEmail, + 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:2 // Profil PARENT + } + createProfile(data,csrfToken) .then(response => { console.log('Success:', response); if (response.id) { - let idProfil = response.id; + let idProfile = response.id; const data = { - eleve: { - nom: updatedData.eleveNom, - prenom: updatedData.elevePrenom, - responsables: [ + student: { + last_name: updatedData.studentLastName, + first_name: updatedData.studentFirstName, + guardians: [ { - mail: updatedData.responsableEmail, - telephone: updatedData.responsableTel, - profilAssocie: idProfil // Association entre le reponsable de l'élève et le profil créé par défaut précédemment + email: updatedData.guardianEmail, + phone: updatedData.guardianPhone, + associated_profile: idProfile // Association entre le responsable de l'élève et le profil créé par défaut précédemment } ], - freres: [] + sibling: [] } }; - 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()) + + createRegisterForm(data,csrfToken) .then(data => { console.log('Success:', data); setFichesInscriptionsDataEnCours(prevState => { @@ -412,7 +323,7 @@ export default function Page({ params: { locale } }) { }); setTotalPending(totalPending+1); if (updatedData.autoMail) { - sendConfirmFicheInscription(data.eleve.id, updatedData.eleveNom, updatedData.elevePrenom); + sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName); } }) .catch((error) => { @@ -429,42 +340,26 @@ export default function Page({ params: { locale } }) { closeModal(); } - const validateAndAssociate = (updatedData) => { - fetch(`${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}/${eleve.id}`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrfToken - }, - body: JSON.stringify(updatedData), - credentials: 'include' - }) - .then(response => response.json()) - .then(data => { - console.log('Succès :', data); - }) - .catch(error => { - console.error('Erreur :', error); - }); - } + const columns = [ - { name: t('studentName'), transform: (row) => row.eleve.nom }, - { name: t('studentFistName'), transform: (row) => row.eleve.prenom }, - { name: t('mainContactMail'), transform: (row) => row.eleve.responsables[0].mail }, - { name: t('phone'), transform: (row) => formatPhoneNumber(row.eleve.responsables[0].telephone) }, - { name: t('lastUpdateDate'), transform: (row) => row.dateMAJ_formattee}, + { name: t('studentName'), transform: (row) => row.student.last_name }, + { name: t('studentFistName'), transform: (row) => row.student.first_name }, + { name: t('mainContactMail'), transform: (row) => row.student.guardians[0].email }, + { name: t('phone'), transform: (row) => formatPhoneNumber(row.student.guardians[0].phone) }, + { name: t('lastUpdateDate'), transform: (row) => row.formatted_last_update}, { name: t('registrationFileStatus'), transform: (row) => (
- updateStatusAction(row.eleve.id, newStatus)} showDropdown={false} /> + updateStatusAction(row.student.id, newStatus)} showDropdown={false} />
) }, - { name: t('files'), transform: (row) => ( + { name: t('files'), transform: (row) => + (row.registerForms != null) &&( ) }, @@ -472,53 +367,53 @@ const columns = [ } items={[ - ...(row.etat === 1 ? [{ + ...(row.status === 1 ? [{ label: ( <> Envoyer ), - onClick: () => sendConfirmFicheInscription(row.eleve.id, row.eleve.nom, row.eleve.prenom), + onClick: () => sendConfirmRegisterForm(row.student.id, row.student.last_name, row.student.first_name), }] : []), - ...(row.etat === 1 ? [{ + ...(row.status === 1 ? [{ label: ( <> Modifier ), - onClick: () => window.location.href = `${FR_ADMIN_SUBSCRIPTIONS_EDIT_URL}?idEleve=${row.eleve.id}&id=1`, + onClick: () => window.location.href = `${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&id=1`, }] : []), - ...(row.etat === 2 ? [{ + ...(row.status === 2 ? [{ label: ( <> Modifier ), - onClick: () => window.location.href = `${FR_ADMIN_SUBSCRIPTIONS_EDIT_URL}?idEleve=${row.eleve.id}&id=1`, + onClick: () => window.location.href = `${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&id=1`, }] : []), - ...(row.etat === 3 ? [{ + ...(row.status === 3 ? [{ label: ( <> Valider ), - onClick: () => openModalAssociationEleve(row.eleve), + onClick: () => openModalAssociationEleve(row.student), }] : []), - ...(row.etat === 5 ? [{ + ...(row.status === 5 ? [{ label: ( <> Rattacher ), - onClick: () => openModalAssociationEleve(row.eleve), + onClick: () => openModalAssociationEleve(row.student), }] : []), - ...(row.etat !== 6 ? [{ + ...(row.status !== 6 ? [{ label: ( <> Archiver ), - onClick: () => archiveFicheInscription(row.eleve.id, row.eleve.nom, row.eleve.prenom), + onClick: () => archiveFicheInscription(row.student.id, row.student.last_name, row.student.first_name), }] : []), ]} buttonClassName="text-gray-400 hover:text-gray-600" @@ -529,22 +424,23 @@ const columns = [ ]; const columnsSubscribed = [ - { name: t('studentName'), transform: (row) => row.eleve.nom }, - { name: t('studentFistName'), transform: (row) => row.eleve.prenom }, - { name: t('lastUpdateDate'), transform: (row) => row.dateMAJ_formattee}, - { name: t('class'), transform: (row) => row.eleve.classeAssocieeName}, - { name: t('registrationFileStatus'), transform: (row) => ( -
- updateStatusAction(row.eleve.id, newStatus)} showDropdown={false} /> -
- ) + { name: t('studentName'), transform: (row) => row.student.last_name }, + { name: t('studentFistName'), transform: (row) => row.student.first_name }, + { name: t('lastUpdateDate'), transform: (row) => row.updated_date_formated}, + { name: t('class'), transform: (row) => row.student.first_name}, + { name: t('registrationFileStatus'), transform: (row) => + ( +
+ updateStatusAction(row.student.id, newStatus)} showDropdown={false} /> +
+ ) }, { name: t('files'), transform: (row) => - ( + (row.registerForm != null) &&( ) }, @@ -557,14 +453,14 @@ const columnsSubscribed = [ Rattacher ), - onClick: () => openModalAssociationEleve(row.eleve) + onClick: () => openModalAssociationEleve(row.student) }, { label: ( <> Archiver ), - onClick: () => archiveFicheInscription(row.eleve.id, row.eleve.nom, row.eleve.prenom), + onClick: () => archiveFicheInscription(row.student.id, row.student.last_name, row.student.first_name), } ]} buttonClassName="text-gray-400 hover:text-gray-600" @@ -575,13 +471,7 @@ const columnsSubscribed = [ ]; const handleFileDelete = (fileId) => { - fetch(`${BK_GESTIONINSCRIPTION_FICHERSINSCRIPTION_URL}/${fileId}`, { - method: 'DELETE', - headers: { - 'X-CSRFToken': csrfToken, - }, - credentials: 'include', - }) + deleteRegisterFormFileTemplate(fileId,csrfToken) .then(response => { if (response.ok) { setFichiers(fichiers.filter(fichier => fichier.id !== fileId)); @@ -598,12 +488,15 @@ const handleFileDelete = (fileId) => { const columnsFiles = [ { name: 'Nom du fichier', transform: (row) => row.name }, - { name: 'Date de création', transform: (row) => row.date_ajout }, + { name: 'Date de création', transform: (row) => row.last_update }, { name: 'Actions', transform: (row) => (
+ { + row.file && ( - + ) + } @@ -611,51 +504,19 @@ const columnsFiles = [ ) }, ]; -const [isUploadModalOpen, setIsUploadModalOpen] = useState(false); -const [uploadFile, setUploadFile] = useState(null); -const [uploadFileName, setUploadFileName] = useState(''); -const [fileName, setFileName] = useState(''); - -const openUploadModal = () => { - setIsUploadModalOpen(true); -}; - -const closeUploadModal = () => { - setIsUploadModalOpen(false); - setUploadFile(null); - setUploadFileName(''); - setFileName(''); -}; - -const handleFileChange = (event) => { - const file = event.target.files[0]; - setUploadFile(file); - setUploadFileName(file ? file.name : ''); -}; - -const handleFileNameChange = (event) => { - setFileName(event.target.value); -}; - const handleFileUpload = (file, fileName) => { - if (!file || !fileName) { - alert('Veuillez sélectionner un fichier et entrer un nom de fichier.'); + if ( !fileName) { + alert('Veuillez entrer un nom de fichier.'); return; } - const formData = new FormData(); - formData.append('file', file); - formData.append('name', fileName); - fetch(`${BK_GESTIONINSCRIPTION_FICHERSINSCRIPTION_URL}`, { - method: 'POST', - body: formData, - headers: { - 'X-CSRFToken': csrfToken, - }, - credentials: 'include', - }) - .then(response => response.json()) + const formData = new FormData(); + if(file){ + formData.append('fichier', file); + } + formData.append('nom', fileName); + createRegisterFormFileTemplate(formData,csrfToken) .then(data => { console.log('Success:', data); setFichiers([...fichiers, data]); @@ -808,8 +669,8 @@ const handleFileUpload = (file, fileName) => { title={"Création d'un nouveau dossier d'inscription"} size='sm:w-1/4' ContentComponent={() => ( - )} /> @@ -821,24 +682,13 @@ const handleFileUpload = (file, fileName) => { title="Affectation à une classe" ContentComponent={() => ( )} /> )} - {isUploadModalOpen && ( - ( - - )} - /> - )}
); } diff --git a/Front-End/src/app/[locale]/parents/editInscription/page.js b/Front-End/src/app/[locale]/parents/editInscription/page.js index f817e7b..08b2d4a 100644 --- a/Front-End/src/app/[locale]/parents/editInscription/page.js +++ b/Front-End/src/app/[locale]/parents/editInscription/page.js @@ -3,10 +3,10 @@ import React, { useState, useEffect } from 'react'; import InscriptionFormShared from '@/components/Inscription/InscriptionFormShared'; import { useSearchParams, redirect, useRouter } from 'next/navigation'; import useCsrfToken from '@/hooks/useCsrfToken'; -import { FR_PARENTS_HOME_URL, - BK_GESTIONINSCRIPTION_ELEVE_URL, - BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL, - BK_GESTIONINSCRIPTION_RECUPEREDERNIER_RESPONSABLE_URL } from '@/utils/Url'; +import { FE_PARENTS_HOME_URL, + BE_SUBSCRIPTION_STUDENT_URL, + BE_SUBSCRIPTION_REGISTERFORM_URL, + BE_SUBSCRIPTION_LAST_GUARDIAN_URL } from '@/utils/Url'; import { mockStudent } from '@/data/mockStudent'; const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; @@ -14,7 +14,7 @@ const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; export default function Page() { const searchParams = useSearchParams(); const idProfil = searchParams.get('id'); - const idEleve = searchParams.get('idEleve'); + const studentId = searchParams.get('studentId'); const router = useRouter(); const [initialData, setInitialData] = useState(null); @@ -24,8 +24,8 @@ export default function Page() { const [lastIdResponsable, setLastIdResponsable] = useState(1); useEffect(() => { - if (!idEleve || !idProfil) { - console.error('Missing idEleve or idProfil'); + if (!studentId || !idProfil) { + console.error('Missing studentId or idProfil'); return; } @@ -36,9 +36,9 @@ export default function Page() { } else { Promise.all([ // Fetch eleve data - fetch(`${BK_GESTIONINSCRIPTION_ELEVE_URL}/${idEleve}`), + fetch(`${BE_SUBSCRIPTION_STUDENT_URL}/${studentId}`), // Fetch last responsable ID - fetch(BK_GESTIONINSCRIPTION_RECUPEREDERNIER_RESPONSABLE_URL) + fetch(BE_SUBSCRIPTION_LAST_GUARDIAN_URL) ]) .then(async ([eleveResponse, responsableResponse]) => { const eleveData = await eleveResponse.json(); @@ -74,7 +74,7 @@ export default function Page() { setIsLoading(false); }); } - }, [idEleve, idProfil]); + }, [studentId, idProfil]); const handleSubmit = async (data) => { if (useFakeData) { @@ -83,7 +83,7 @@ export default function Page() { } try { - const response = await fetch(`${BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL}/${idEleve}`, { + const response = await fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${studentId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', @@ -95,7 +95,7 @@ export default function Page() { const result = await response.json(); console.log('Success:', result); - router.push(FR_PARENTS_HOME_URL); + router.push(FE_PARENTS_HOME_URL); } catch (error) { console.error('Error:', error); } @@ -106,7 +106,7 @@ export default function Page() { initialData={initialData} csrfToken={csrfToken} onSubmit={handleSubmit} - cancelUrl={FR_PARENTS_HOME_URL} + cancelUrl={FE_PARENTS_HOME_URL} isLoading={isLoading} /> ); diff --git a/Front-End/src/app/[locale]/parents/layout.js b/Front-End/src/app/[locale]/parents/layout.js index a78766d..29bdc94 100644 --- a/Front-End/src/app/[locale]/parents/layout.js +++ b/Front-End/src/app/[locale]/parents/layout.js @@ -5,7 +5,7 @@ import DropdownMenu from '@/components/DropdownMenu'; import { useRouter } from 'next/navigation'; // Ajout de l'importation import { Bell, User, MessageSquare, LogOut, Settings, Home } from 'lucide-react'; // Ajout de l'importation de l'icône Home import Logo from '@/components/Logo'; // Ajout de l'importation du composant Logo -import { FR_PARENTS_HOME_URL,FR_PARENTS_MESSAGERIE_URL,FR_PARENTS_SETTINGS_URL, BK_GESTIONINSCRIPTION_MESSAGES_URL } from '@/utils/Url'; // Ajout de l'importation de l'URL de la page d'accueil parent +import { FE_PARENTS_HOME_URL,FE_PARENTS_MESSAGERIE_URL,FE_PARENTS_SETTINGS_URL, BE_GESTIONINSCRIPTION_MESSAGES_URL } from '@/utils/Url'; // Ajout de l'importation de l'URL de la page d'accueil parent import useLocalStorage from '@/hooks/useLocalStorage'; export default function Layout({ @@ -19,7 +19,7 @@ export default function Layout({ useEffect(() => { setUserId(userId); - fetch(`${BK_GESTIONINSCRIPTION_MESSAGES_URL}/${userId}`, { + fetch(`${BE_GESTIONINSCRIPTION_MESSAGES_URL}/${userId}`, { headers: { 'Content-Type': 'application/json', }, @@ -33,7 +33,7 @@ export default function Layout({ .catch(error => { console.error('Error fetching data:', error); }); - + }, []); return ( @@ -49,7 +49,7 @@ export default function Layout({
@@ -58,7 +58,7 @@ export default function Layout({
diff --git a/Front-End/src/app/[locale]/users/password/new/page.js b/Front-End/src/app/[locale]/users/password/new/page.js index c8aa160..07099f4 100644 --- a/Front-End/src/app/[locale]/users/password/new/page.js +++ b/Front-End/src/app/[locale]/users/password/new/page.js @@ -9,7 +9,7 @@ import Loader from '@/components/Loader'; // Importez le composant Loader import Button from '@/components/Button'; // Importez le composant Button import Popup from '@/components/Popup'; // Importez le composant Popup import { User } from 'lucide-react'; // Importez directement les icônes nécessaires -import { BK_NEW_PASSWORD_URL,FR_USERS_LOGIN_URL } from '@/utils/Url'; +import { BE_AUTH_NEW_PASSWORD_URL,FE_USERS_LOGIN_URL } from '@/utils/Url'; import useCsrfToken from '@/hooks/useCsrfToken'; const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; @@ -35,7 +35,7 @@ export default function Page() { }, 1000); // Simule un délai de traitement } else { const request = new Request( - `${BK_NEW_PASSWORD_URL}`, + `${BE_AUTH_NEW_PASSWORD_URL}`, { method: 'POST', headers: { @@ -93,7 +93,7 @@ export default function Page() {
-
{ setPopupVisible(false); - router.push(`${FR_USERS_LOGIN_URL}`); + router.push(`${FE_USERS_LOGIN_URL}`); }} onCancel={() => setPopupVisible(false)} /> @@ -136,7 +136,7 @@ export default function Page() {
-
diff --git a/Front-End/src/app/[locale]/users/subscribe/page.js b/Front-End/src/app/[locale]/users/subscribe/page.js index f5b3634..b724a0b 100644 --- a/Front-End/src/app/[locale]/users/subscribe/page.js +++ b/Front-End/src/app/[locale]/users/subscribe/page.js @@ -10,7 +10,7 @@ import Loader from '@/components/Loader'; // Importez le composant Loader import Button from '@/components/Button'; // Importez le composant Button import Popup from '@/components/Popup'; // Importez le composant Popup import { User, KeySquare } from 'lucide-react'; // Importez directement les icônes nécessaires -import { BK_REGISTER_URL, FR_USERS_LOGIN_URL } from '@/utils/Url'; +import { BE_AUTH_REGISTER_URL, FE_USERS_LOGIN_URL } from '@/utils/Url'; import useCsrfToken from '@/hooks/useCsrfToken'; const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; @@ -41,7 +41,7 @@ export default function Page() { setErrorMessage("") setIsLoading(false); } else { - const url= `${BK_REGISTER_URL}`; + const url= `${BE_AUTH_REGISTER_URL}`; fetch(url, { headers: { 'Content-Type': 'application/json', @@ -100,11 +100,11 @@ export default function Page() { } } else { const request = new Request( - `${BK_REGISTER_URL}`, + `${BE_AUTH_REGISTER_URL}`, { method:'POST', headers: { - 'Content-Type':'application/json', + 'Content-Type':'application/json', 'X-CSRFToken': csrfToken }, credentials: 'include', @@ -164,14 +164,14 @@ export default function Page() {
-
+
{ setPopupVisible(false); - router.push(`${FR_USERS_LOGIN_URL}`); + router.push(`${FE_USERS_LOGIN_URL}`); }} onCancel={() => setPopupVisible(false)} /> diff --git a/Front-End/src/app/lib/actions.js b/Front-End/src/app/lib/actions.js deleted file mode 100644 index 5ee83b0..0000000 --- a/Front-End/src/app/lib/actions.js +++ /dev/null @@ -1,39 +0,0 @@ - -import { - BK_LOGIN_URL, - FR_USERS_LOGIN_URL , - FR_ADMIN_HOME_URL, - FR_ADMIN_SUBSCRIPTIONS_URL, - FR_ADMIN_CLASSES_URL, - FR_ADMIN_GRADES_URL, - FR_ADMIN_PLANNING_URL, - FR_ADMIN_TEACHERS_URL, - FR_ADMIN_SETTINGS_URL -} from '@/utils/Url'; - -import {mockUser} from "@/data/mockUsersData"; - -const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; - - -/** - * Disconnects the user after confirming the action. - * If `NEXT_PUBLIC_USE_FAKE_DATA` environment variable is set to 'true', it will log a fake disconnect and redirect to the login URL. - * Otherwise, it will send a PUT request to the backend to update the user profile and then redirect to the login URL. - * - * @function - * @name disconnect - * @returns {void} - */ -export function disconnect () { - if (confirm("\nÊtes-vous sûr(e) de vouloir vous déconnecter ?")) { - - if (useFakeData) { - console.log('Fake disconnect:', mockUser); - router.push(`${FR_USERS_LOGIN_URL}`); - } else { - console.log('Fake disconnect:', mockUser); - router.push(`${FR_USERS_LOGIN_URL}`); - } - } - }; diff --git a/Front-End/src/app/lib/authAction.js b/Front-End/src/app/lib/authAction.js new file mode 100644 index 0000000..bce3624 --- /dev/null +++ b/Front-End/src/app/lib/authAction.js @@ -0,0 +1,67 @@ + +import { + BE_AUTH_LOGIN_URL, + BE_AUTH_PROFILE_URL, + FE_USERS_LOGIN_URL , +} from '@/utils/Url'; + +import {mockUser} from "@/data/mockUsersData"; + +const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true'; + + +/** + * Disconnects the user after confirming the action. + * If `NEXT_PUBLIC_USE_FAKE_DATA` environment variable is set to 'true', it will log a fake disconnect and redirect to the login URL. + * Otherwise, it will send a PUT request to the backend to update the user profile and then redirect to the login URL. + * + * @function + * @name disconnect + * @returns {void} + */ +export const disconnect = () => { + if (confirm("\nÊtes-vous sûr(e) de vouloir vous déconnecter ?")) { + + if (useFakeData) { + console.log('Fake disconnect:', mockUser); + router.push(`${FE_USERS_LOGIN_URL}`); + } else { + console.log('Fake disconnect:', mockUser); + router.push(`${FE_USERS_LOGIN_URL}`); + } + } + }; + + +export const createProfile = (data,csrfToken) => { +const request = new Request( + `${BE_AUTH_PROFILE_URL}`, + { + method:'POST', + headers: { + 'Content-Type':'application/json', + 'X-CSRFToken': csrfToken + }, + credentials: 'include', + body: JSON.stringify(data), + } + ); + return fetch(request).then(response => response.json()) +} + + +export const updateProfile = (id, data, csrfToken) => { + const request = new Request( + `${BE_AUTH_PROFILE_URL}/${id}`, + { + method:'PUT', + headers: { + 'Content-Type':'application/json', + 'X-CSRFToken': csrfToken + }, + credentials: 'include', + body: JSON.stringify(data), + } + ); + return fetch(request).then(response => response.json()) +} \ No newline at end of file diff --git a/Front-End/src/app/lib/schoolAction.js b/Front-End/src/app/lib/schoolAction.js new file mode 100644 index 0000000..fceb666 --- /dev/null +++ b/Front-End/src/app/lib/schoolAction.js @@ -0,0 +1,9 @@ +import { + BE_SCHOOL_SCHOOLCLASSES_URL +} from '@/utils/Url'; + + export const fetchClasses = () => { + return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`) + .then(response => response.json()) + + }; \ No newline at end of file diff --git a/Front-End/src/app/lib/subscriptionAction.js b/Front-End/src/app/lib/subscriptionAction.js new file mode 100644 index 0000000..b6fc8bb --- /dev/null +++ b/Front-End/src/app/lib/subscriptionAction.js @@ -0,0 +1,123 @@ +import { + BE_SUBSCRIPTION_STUDENTS_URL, + BE_SUBSCRIPTION_ARCHIVE_URL, + BE_SUBSCRIPTION_SEND_URL, + BE_SUBSCRIPTION_REGISTERFORM_URL, + BE_SUBSCRIPTION_REGISTERFORMS_URL, + BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL +} from '@/utils/Url'; + +export const PENDING = 'pending'; +export const SUBSCRIBED = 'subscribed'; +export const ARCHIVED = 'archived'; + + +export const fetchRegisterForm = (type=PENDING, page='', pageSize='', search = '') => { + let url = `${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${type}`; + if (page !== '' && pageSize !== '') { + url = `${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${type}?page=${page}&search=${search}`; + } + return fetch(url, { + headers: { + 'Content-Type': 'application/json', + }, + }).then(response => response.json()) + }; + +export const editRegisterForm=(id, data, csrfToken)=>{ + + return fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfToken + }, + body: JSON.stringify(data), + credentials: 'include' + }) + .then(response => response.json()) + +}; + +export const createRegisterForm=(data, csrfToken)=>{ + const url = `${BE_SUBSCRIPTION_REGISTERFORM_URL}`; + return fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfToken + }, + body: JSON.stringify(data), + credentials: 'include' + }) + .then(response => response.json()) +} + +export const archiveRegisterForm = (id) => { + const url = `${BE_SUBSCRIPTION_ARCHIVE_URL}/${id}`; + return fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }).then(response => response.json()) +} + +export const sendRegisterForm = (id) => { + const url = `${BE_SUBSCRIPTION_SEND_URL}/${id}`; + return fetch(url, { + headers: { + 'Content-Type': 'application/json', + }, + }).then(response => response.json()) + +} + +export const fetchRegisterFormFileTemplate = () => { + const request = new Request( + `${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}`, + { + method:'GET', + headers: { + 'Content-Type':'application/json' + }, + } + ); + return fetch(request).then(response => response.json()) +}; + +export const createRegisterFormFileTemplate = (data,csrfToken) => { + + fetch(`${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}`, { + method: 'POST', + body: data, + headers: { + 'X-CSRFToken': csrfToken, + }, + credentials: 'include', + }) + .then(response => response.json()) +} + +export const deleteRegisterFormFileTemplate = (fileId,csrfToken) => { + return fetch(`${BE_SUBSCRIPTION_REGISTERFORMFILE_TEMPLATE_URL}/${fileId}`, { + method: 'DELETE', + headers: { + 'X-CSRFToken': csrfToken, + }, + credentials: 'include', + }) +} +export const fetchStudents = () => { + const request = new Request( + `${BE_SUBSCRIPTION_STUDENTS_URL}`, + { + method:'GET', + headers: { + 'Content-Type':'application/json' + }, + } + ); + return fetch(request).then(response => response.json()) + +}; diff --git a/Front-End/src/components/Inscription/InscriptionForm.js b/Front-End/src/components/Inscription/InscriptionForm.js index 79d8edb..9414a19 100644 --- a/Front-End/src/components/Inscription/InscriptionForm.js +++ b/Front-End/src/components/Inscription/InscriptionForm.js @@ -4,20 +4,20 @@ import InputTextIcon from '@/components/InputTextIcon'; import ToggleSwitch from '@/components/ToggleSwitch'; import Button from '@/components/Button'; -const InscriptionForm = ( { eleves, onSubmit }) => { +const InscriptionForm = ( { students, onSubmit }) => { const [formData, setFormData] = useState({ - eleveNom: '', - elevePrenom: '', - responsableEmail: '', - responsableTel: '', - selectedResponsables: [], + studentLastName: '', + studentFirstName: '', + guardianEmail: '', + guardianPhone: '', + selectedGuardians: [], responsableType: 'new', autoMail: false }); const [step, setStep] = useState(1); - const [selectedEleve, setSelectedEleve] = useState(''); - const [existingResponsables, setExistingResponsables] = useState([]); + const [selectedStudent, setSelectedEleve] = useState(''); + const [existingGuardians, setExistingGuardians] = useState([]); const maxStep = 4 const handleToggleChange = () => { @@ -44,21 +44,21 @@ const InscriptionForm = ( { eleves, onSubmit }) => { } }; - const handleEleveSelection = (eleve) => { - setSelectedEleve(eleve); + const handleEleveSelection = (student) => { + setSelectedEleve(student); setFormData((prevData) => ({ ...prevData, - selectedResponsables: [] + selectedGuardians: [] })); - setExistingResponsables(eleve.responsables); + setExistingGuardians(student.guardians); }; - const handleResponsableSelection = (responsableId) => { + const handleResponsableSelection = (guardianId) => { setFormData((prevData) => { - const selectedResponsables = prevData.selectedResponsables.includes(responsableId) - ? prevData.selectedResponsables.filter(id => id !== responsableId) - : [...prevData.selectedResponsables, responsableId]; - return { ...prevData, selectedResponsables }; + const selectedGuardians = prevData.selectedGuardians.includes(guardianId) + ? prevData.selectedGuardians.filter(id => id !== guardianId) + : [...prevData.selectedGuardians, guardianId]; + return { ...prevData, selectedGuardians }; }); }; @@ -72,20 +72,20 @@ const InscriptionForm = ( { eleves, onSubmit }) => {

Nouvel élève

@@ -121,11 +121,11 @@ const InscriptionForm = ( { eleves, onSubmit }) => {
{formData.responsableType === 'new' && ( @@ -142,33 +142,33 @@ const InscriptionForm = ( { eleves, onSubmit }) => { - {eleves.map((eleve, index) => ( + {students.map((student, index) => ( handleEleveSelection(eleve)} + key={student.id} + className={`cursor-pointer ${selectedStudent && selectedStudent.id === student.id ? 'bg-emerald-600 text-white' : index % 2 === 0 ? 'bg-emerald-100' : ''}`} + onClick={() => handleEleveSelection(student)} > - {eleve.nom} - {eleve.prenom} + {student.last_name} + {student.first_name} ))} - {selectedEleve && ( + {selectedStudent && (
-

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

- {existingResponsables.map((responsable) => ( -
+

Responsables associés à {selectedStudent.last_name} {selectedStudent.first_name} :

+ {existingGuardians.map((guardian) => ( +
@@ -184,11 +184,11 @@ const InscriptionForm = ( { eleves, onSubmit }) => {

Téléphone (optionnel)

@@ -210,8 +210,8 @@ const InscriptionForm = ( { eleves, onSubmit }) => { - {formData.eleveNom} - {formData.elevePrenom} + {formData.studentLastName} + {formData.studentFirstName} @@ -228,15 +228,15 @@ const InscriptionForm = ( { eleves, onSubmit }) => { - {formData.responsableEmail} - {formData.responsableTel} + {formData.guardianEmail} + {formData.guardianPhone} )} - {formData.responsableType === 'existing' && selectedEleve && ( + {formData.responsableType === 'existing' && selectedStudent && (
-

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

+

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

@@ -246,11 +246,11 @@ const InscriptionForm = ( { eleves, onSubmit }) => { - {existingResponsables.filter(responsable => formData.selectedResponsables.includes(responsable.id)).map((responsable) => ( - - - - + {existingGuardians.filter(guardian => formData.selectedGuardians.includes(guardian.id)).map((guardian) => ( + + + + ))} @@ -281,15 +281,15 @@ const InscriptionForm = ( { eleves, onSubmit }) => {
{responsable.nom}{responsable.prenom}{responsable.mail}
{guardian.last_name}{guardian.first_name}{guardian.email}
{}} + /> + + + {/* Boutons de contrôle */}