mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Gestion multi-profil multi-école
This commit is contained in:
@ -16,6 +16,7 @@ import Modal from '@/components/Modal';
|
||||
import InscriptionForm from '@/components/Inscription/InscriptionForm'
|
||||
import AffectationClasseForm from '@/components/AffectationClasseForm'
|
||||
import { getSession } from 'next-auth/react';
|
||||
import { useEstablishment } from '@/context/EstablishmentContext';
|
||||
|
||||
import {
|
||||
PENDING,
|
||||
@ -50,7 +51,6 @@ import {
|
||||
|
||||
import DjangoCSRFToken from '@/components/DjangoCSRFToken'
|
||||
import { useCsrfToken } from '@/context/CsrfContext';
|
||||
import { ESTABLISHMENT_ID } from '@/utils/Url';
|
||||
import logger from '@/utils/logger';
|
||||
|
||||
export default function Page({ params: { locale } }) {
|
||||
@ -87,9 +87,8 @@ export default function Page({ params: { locale } }) {
|
||||
const [tuitionFees, setTuitionFees] = useState([]);
|
||||
const [groups, setGroups] = useState([]);
|
||||
|
||||
const [establishmentId, setEstablishmentId] = useState(null);
|
||||
|
||||
const csrfToken = useCsrfToken();
|
||||
const { selectedEstablishmentId } = useEstablishment();
|
||||
|
||||
const openModal = () => {
|
||||
setIsOpen(true);
|
||||
@ -167,23 +166,11 @@ const registerFormArchivedDataHandler = (data) => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getSession()
|
||||
.then(session => {
|
||||
if (session && session.user) {
|
||||
setEstablishmentId(session.user.establishment);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error fetching session:', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (establishmentId) {
|
||||
if (selectedEstablishmentId) {
|
||||
const fetchInitialData = () => {
|
||||
Promise.all([
|
||||
fetchClasses(),
|
||||
fetchStudents(establishmentId) // Utiliser l'ID de l'établissement ici
|
||||
fetchClasses(selectedEstablishmentId),
|
||||
fetchStudents(selectedEstablishmentId) // Utiliser l'ID de l'établissement ici
|
||||
])
|
||||
.then(([classesData, studentsData]) => {
|
||||
setClasses(classesData);
|
||||
@ -198,21 +185,21 @@ useEffect(() => {
|
||||
|
||||
fetchInitialData();
|
||||
}
|
||||
}, [establishmentId]);
|
||||
}, [selectedEstablishmentId]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (establishmentId) {
|
||||
if (selectedEstablishmentId) {
|
||||
const fetchDataAndSetState = () => {
|
||||
setIsLoading(true);
|
||||
Promise.all([
|
||||
fetchRegisterForms(establishmentId, PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
fetchRegisterForms(selectedEstablishmentId, PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
.then(registerFormPendingDataHandler)
|
||||
.catch(requestErrorHandler),
|
||||
fetchRegisterForms(establishmentId, SUBSCRIBED)
|
||||
fetchRegisterForms(selectedEstablishmentId, SUBSCRIBED)
|
||||
.then(registerFormSubscribedDataHandler)
|
||||
.catch(requestErrorHandler),
|
||||
fetchRegisterForms(establishmentId, ARCHIVED)
|
||||
fetchRegisterForms(selectedEstablishmentId, ARCHIVED)
|
||||
.then(registerFormArchivedDataHandler)
|
||||
.catch(requestErrorHandler),
|
||||
fetchRegistrationTemplateMaster()
|
||||
@ -222,27 +209,27 @@ useEffect(() => {
|
||||
.catch(err => {
|
||||
logger.debug(err.message);
|
||||
}),
|
||||
fetchRegistrationDiscounts()
|
||||
fetchRegistrationDiscounts(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setRegistrationDiscounts(data);
|
||||
})
|
||||
.catch(requestErrorHandler),
|
||||
fetchTuitionDiscounts()
|
||||
fetchTuitionDiscounts(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setTuitionDiscounts(data);
|
||||
})
|
||||
.catch(requestErrorHandler),
|
||||
fetchRegistrationFees()
|
||||
fetchRegistrationFees(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setRegistrationFees(data);
|
||||
})
|
||||
.catch(requestErrorHandler),
|
||||
fetchTuitionFees()
|
||||
fetchTuitionFees(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setTuitionFees(data);
|
||||
})
|
||||
.catch(requestErrorHandler),
|
||||
fetchRegistrationFileGroups()
|
||||
fetchRegistrationFileGroups(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setGroups(data);
|
||||
})
|
||||
@ -263,20 +250,20 @@ useEffect(() => {
|
||||
|
||||
fetchDataAndSetState();
|
||||
}
|
||||
}, [establishmentId, reloadFetch, currentPage, searchTerm]);
|
||||
}, [selectedEstablishmentId, reloadFetch, currentPage, searchTerm]);
|
||||
|
||||
useEffect(() => {
|
||||
if (establishmentId) {
|
||||
if (selectedEstablishmentId) {
|
||||
const fetchDataAndSetState = () => {
|
||||
|
||||
setIsLoading(true);
|
||||
fetchRegisterForms(establishmentId, PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
fetchRegisterForms(selectedEstablishmentId, PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
.then(registerFormPendingDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
fetchRegisterForms(establishmentId, SUBSCRIBED)
|
||||
fetchRegisterForms(selectedEstablishmentId, SUBSCRIBED)
|
||||
.then(registerFormSubscribedDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
fetchRegisterForms(establishmentId, ARCHIVED)
|
||||
fetchRegisterForms(selectedEstablishmentId, ARCHIVED)
|
||||
.then(registerFormArchivedDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
fetchRegistrationTemplateMaster()
|
||||
@ -545,7 +532,7 @@ useEffect(()=>{
|
||||
const columns = [
|
||||
{ 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('mainContactMail'), transform: (row) => row.student.guardians[0].associated_profile_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) => (
|
||||
|
||||
Reference in New Issue
Block a user