refactor: refactoring du FRONT page subscribe

This commit is contained in:
Luc SORIGNET
2025-01-12 14:37:49 +01:00
parent 58fe509734
commit 427b6c7588
25 changed files with 671 additions and 652 deletions

View File

@ -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) => (
<div className="flex justify-center items-center h-full">
<StatusLabel etat={row.etat} onChange={(newStatus) => updateStatusAction(row.eleve.id, newStatus)} showDropdown={false} />
<StatusLabel etat={row.status} onChange={(newStatus) => updateStatusAction(row.student.id, newStatus)} showDropdown={false} />
</div>
)
},
{ name: t('files'), transform: (row) => (
{ name: t('files'), transform: (row) =>
(row.registerForms != null) &&(
<ul>
<li className="flex items-center gap-2">
<FileText size={16} />
<a href={ `${BASE_URL}${row.fichierInscription}`} target='_blank'>{row.fichierInscription.split('/').pop()}</a>
<a href={ `${BASE_URL}${row.registerForms}`} target='_blank'>{row.registerForms?.split('/').pop()}</a>
</li>
</ul>
) },
@ -472,53 +367,53 @@ const columns = [
<DropdownMenu
buttonContent={<MoreVertical size={20} className="text-gray-400 hover:text-gray-600" />}
items={[
...(row.etat === 1 ? [{
...(row.status === 1 ? [{
label: (
<>
<Send size={16} className="mr-2" /> 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: (
<>
<Edit size={16} className="mr-2" /> 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: (
<>
<Edit size={16} className="mr-2" /> 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: (
<>
<CheckCircle size={16} className="mr-2" /> Valider
</>
),
onClick: () => openModalAssociationEleve(row.eleve),
onClick: () => openModalAssociationEleve(row.student),
}] : []),
...(row.etat === 5 ? [{
...(row.status === 5 ? [{
label: (
<>
<CheckCircle size={16} className="mr-2" /> Rattacher
</>
),
onClick: () => openModalAssociationEleve(row.eleve),
onClick: () => openModalAssociationEleve(row.student),
}] : []),
...(row.etat !== 6 ? [{
...(row.status !== 6 ? [{
label: (
<>
<Trash2 size={16} className="mr-2 text-red-700" /> 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) => (
<div className="flex justify-center items-center h-full">
<StatusLabel etat={row.etat} onChange={(newStatus) => updateStatusAction(row.eleve.id, newStatus)} showDropdown={false} />
</div>
)
{ 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) =>
(
<div className="flex justify-center items-center h-full">
<StatusLabel etat={row.status} onChange={(newStatus) => updateStatusAction(row.student.id, newStatus)} showDropdown={false} />
</div>
)
},
{ name: t('files'), transform: (row) =>
(
(row.registerForm != null) &&(
<ul>
<li className="flex items-center gap-2">
<FileText size={16} />
<a href={ `${BASE_URL}${row.fichierInscription}`} target='_blank'>{row.fichierInscription.split('/').pop()}</a>
<a href={ `${BASE_URL}${row.registerForm}`} target='_blank'>{row.registerForm?.split('/').pop()}</a>
</li>
</ul>
) },
@ -557,14 +453,14 @@ const columnsSubscribed = [
<CheckCircle size={16} className="mr-2" /> Rattacher
</>
),
onClick: () => openModalAssociationEleve(row.eleve)
onClick: () => openModalAssociationEleve(row.student)
},
{ label: (
<>
<Trash2 size={16} className="mr-2 text-red-700" /> 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) => (
<div className="flex items-center justify-center gap-2">
{
row.file && (
<a href={`${BASE_URL}${row.file}`} target='_blank' className="text-blue-500 hover:text-blue-700">
<Download size={16} />
</a>
</a>)
}
<button onClick={() => handleFileDelete(row.id)} className="text-red-500 hover:text-red-700">
<Trash2 size={16} />
</button>
@ -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={() => (
<InscriptionForm eleves={eleves}
onSubmit={createDI}
<InscriptionForm students={students}
onSubmit={createRF}
/>
)}
/>
@ -821,24 +682,13 @@ const handleFileUpload = (file, fileName) => {
title="Affectation à une classe"
ContentComponent={() => (
<AffectationClasseForm
eleve={eleve}
onSubmit={validateAndAssociate}
student={student}
onSubmit={affectationClassFormSubmitHandler}
classes={classes}
/>
)}
/>
)}
{isUploadModalOpen && (
<Modal
isOpen={isUploadModalOpen}
setIsOpen={setIsUploadModalOpen}
title="Uploader un nouveau fichier"
size='sm:w-1/4'
ContentComponent={() => (
<FileUpload onFileUpload={handleFileUpload} />
)}
/>
)}
</div>
);
}