mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
refactor: Création de nouveaux composants / update formulaire de
création de classe (#2)
This commit is contained in:
@ -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_GESTIONINSCRIPTION_CLASSES_URL } from '@/utils/Url';
|
||||
import { BK_GESTIONENSEIGNANTS_CLASSES_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_GESTIONINSCRIPTION_CLASSES_URL}`)
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setClasses(data);
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
'use client'
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import SpecialitiesSection from '@/components/SpecialitiesSection'
|
||||
import ClassesSection from '@/components/ClassesSection'
|
||||
import TeachersSection from '@/components/TeachersSection';
|
||||
import { BK_GESTIONINSCRIPTION_SPECIALITES_URL,
|
||||
BK_GESTIONINSCRIPTION_CLASSES_URL,
|
||||
BK_GESTIONINSCRIPTION_SPECIALITE_URL,
|
||||
BK_GESTIONINSCRIPTION_CLASSE_URL,
|
||||
BK_GESTIONINSCRIPTION_TEACHERS_URL,
|
||||
BK_GESTIONINSCRIPTION_TEACHER_URL } from '@/utils/Url';
|
||||
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 DjangoCSRFToken from '@/components/DjangoCSRFToken'
|
||||
import useCsrfToken from '@/hooks/useCsrfToken';
|
||||
|
||||
@ -16,6 +15,12 @@ export default function Page() {
|
||||
const [specialities, setSpecialities] = useState([]);
|
||||
const [classes, setClasses] = useState([]);
|
||||
const [teachers, setTeachers] = useState([]);
|
||||
const [schedules, setSchedules] = useState([]);
|
||||
const [activeTab, setActiveTab] = useState('Configuration');
|
||||
const tabs = [
|
||||
{ id: 'Configuration', title: "Configuration de l'école", icon: School },
|
||||
{ id: 'Schedule', title: "Gestion de l'emploi du temps", icon: Calendar },
|
||||
];
|
||||
|
||||
const csrfToken = useCsrfToken();
|
||||
|
||||
@ -28,10 +33,13 @@ export default function Page() {
|
||||
|
||||
// Fetch data for classes
|
||||
fetchClasses();
|
||||
|
||||
// Fetch data for schedules
|
||||
fetchSchedules();
|
||||
}, []);
|
||||
|
||||
const fetchSpecialities = () => {
|
||||
fetch(`${BK_GESTIONINSCRIPTION_SPECIALITES_URL}`)
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_SPECIALITES_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setSpecialities(data);
|
||||
@ -42,7 +50,7 @@ export default function Page() {
|
||||
};
|
||||
|
||||
const fetchTeachers = () => {
|
||||
fetch(`${BK_GESTIONINSCRIPTION_TEACHERS_URL}`)
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_TEACHERS_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setTeachers(data);
|
||||
@ -53,7 +61,7 @@ export default function Page() {
|
||||
};
|
||||
|
||||
const fetchClasses = () => {
|
||||
fetch(`${BK_GESTIONINSCRIPTION_CLASSES_URL}`)
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setClasses(data);
|
||||
@ -63,6 +71,17 @@ export default function Page() {
|
||||
});
|
||||
};
|
||||
|
||||
const fetchSchedules = () => {
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_PLANNINGS_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setSchedules(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching classes:', error);
|
||||
});
|
||||
};
|
||||
|
||||
const handleCreate = (url, newData, setDatas) => {
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
@ -102,6 +121,26 @@ export default function Page() {
|
||||
});
|
||||
};
|
||||
|
||||
const handleUpdatePlanning = (url, id, updatedData) => {
|
||||
fetch(`${url}/${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('Planning mis à jour avec succès :', data);
|
||||
//setDatas(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur :', error);
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (url, id, setDatas) => {
|
||||
fetch(`${url}/${id}`, {
|
||||
method:'DELETE',
|
||||
@ -127,30 +166,33 @@ export default function Page() {
|
||||
<div className='p-8'>
|
||||
<DjangoCSRFToken csrfToken={csrfToken} />
|
||||
|
||||
<SpecialitiesSection
|
||||
specialities={specialities}
|
||||
setSpecialities={setSpecialities}
|
||||
handleCreate={(newData) => handleCreate(`${BK_GESTIONINSCRIPTION_SPECIALITE_URL}`, newData, setSpecialities)}
|
||||
handleEdit={(id, updatedData) => handleEdit(`${BK_GESTIONINSCRIPTION_SPECIALITE_URL}`, id, updatedData, setSpecialities)}
|
||||
handleDelete={(id) => handleDelete(`${BK_GESTIONINSCRIPTION_SPECIALITE_URL}`, id, setSpecialities)}
|
||||
/>
|
||||
<TabsStructure activeTab={activeTab} setActiveTab={setActiveTab} tabs={tabs} />
|
||||
|
||||
<TeachersSection
|
||||
teachers={teachers}
|
||||
specialities={specialities}
|
||||
handleCreate={(newData) => handleCreate(`${BK_GESTIONINSCRIPTION_TEACHER_URL}`, newData, setTeachers)}
|
||||
handleEdit={(id, updatedData) => handleEdit(`${BK_GESTIONINSCRIPTION_TEACHER_URL}`, id, updatedData, setTeachers)}
|
||||
handleDelete={(id) => handleDelete(`${BK_GESTIONINSCRIPTION_TEACHER_URL}`, id, setTeachers)}
|
||||
/>
|
||||
{activeTab === 'Configuration' && (
|
||||
<>
|
||||
<StructureManagement
|
||||
specialities={specialities}
|
||||
setSpecialities={setSpecialities}
|
||||
teachers={teachers}
|
||||
setTeachers={setTeachers}
|
||||
classes={classes}
|
||||
setClasses={setClasses}
|
||||
handleCreate={handleCreate}
|
||||
handleEdit={handleEdit}
|
||||
handleDelete={handleDelete} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<ClassesSection
|
||||
classes={classes}
|
||||
specialities={specialities}
|
||||
teachers={teachers}
|
||||
handleCreate={(newData) => handleCreate(`${BK_GESTIONINSCRIPTION_CLASSE_URL}`, newData, setClasses)}
|
||||
handleEdit={(id, updatedData) => handleEdit(`${BK_GESTIONINSCRIPTION_CLASSE_URL}`, id, updatedData, setClasses)}
|
||||
handleDelete={(id) => handleDelete(`${BK_GESTIONINSCRIPTION_CLASSE_URL}`, id, setClasses)}
|
||||
/>
|
||||
{activeTab === 'Schedule' && (
|
||||
<ScheduleManagement
|
||||
schedules={schedules}
|
||||
setSchedules={setSchedules}
|
||||
handleUpdatePlanning={handleUpdatePlanning}
|
||||
specialities={specialities}
|
||||
teachers={teachers}
|
||||
classes={classes}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -22,7 +22,7 @@ import { BK_GESTIONINSCRIPTION_FICHESINSCRIPTION_URL,
|
||||
BK_GESTIONINSCRIPTION_SEND_URL,
|
||||
FR_ADMIN_SUBSCRIPTIONS_EDIT_URL,
|
||||
BK_GESTIONINSCRIPTION_ARCHIVE_URL,
|
||||
BK_GESTIONINSCRIPTION_CLASSES_URL,
|
||||
BK_GESTIONENSEIGNANTS_CLASSES_URL,
|
||||
BK_GESTIONINSCRIPTION_FICHEINSCRIPTION_URL,
|
||||
BK_GESTIONINSCRIPTION_ELEVES_URL,
|
||||
BK_PROFILE_URL } from '@/utils/Url';
|
||||
@ -147,7 +147,7 @@ export default function Page({ params: { locale } }) {
|
||||
};
|
||||
|
||||
const fetchClasses = () => {
|
||||
fetch(`${BK_GESTIONINSCRIPTION_CLASSES_URL}`)
|
||||
fetch(`${BK_GESTIONENSEIGNANTS_CLASSES_URL}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setClasses(data);
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
|
||||
import {NextIntlClientProvider} from 'next-intl';
|
||||
import {getMessages} from 'next-intl/server';
|
||||
import "@/css/tailwind.css";
|
||||
|
||||
|
||||
export const metadata = {
|
||||
title: "N3WT-SCHOOL",
|
||||
description: "Gestion de l'école",
|
||||
@ -21,10 +21,7 @@ export const metadata = {
|
||||
},
|
||||
};
|
||||
|
||||
export default async function RootLayout({ children, params: {locale}}) {
|
||||
|
||||
// Providing all messages to the client
|
||||
// side is the easiest way to get started
|
||||
export default async function RootLayout({ children, params: { locale } }) {
|
||||
const messages = await getMessages();
|
||||
|
||||
return (
|
||||
@ -37,5 +34,3 @@ export default async function RootLayout({ children, params: {locale}}) {
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user