mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Ajout de la configuration des tarifs de l'école [#18]
This commit is contained in:
committed by
Luc SORIGNET
parent
147a70135d
commit
5a0e65bb75
@ -1,28 +1,22 @@
|
||||
'use client'
|
||||
import React, { useState, useEffect } from 'react';
|
||||
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 { 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 { School, Calendar, DollarSign } from 'lucide-react'; // Import de l'icône DollarSign
|
||||
import StructureManagement from '@/components/Structure/Configuration/StructureManagement';
|
||||
import ScheduleManagement from '@/components/Structure/Planning/ScheduleManagement';
|
||||
import FeesManagement from '@/components/Structure/Configuration/FeesManagement';
|
||||
import DjangoCSRFToken from '@/components/DjangoCSRFToken';
|
||||
import useCsrfToken from '@/hooks/useCsrfToken';
|
||||
import { ClassesProvider } from '@/context/ClassesContext';
|
||||
import { fetchSpecialities, fetchTeachers, fetchClasses, fetchSchedules } from '@/app/lib/schoolAction';
|
||||
import { fetchSpecialities, fetchTeachers, fetchClasses, fetchSchedules, fetchDiscounts, fetchFees, fetchTuitionFees } from '@/app/lib/schoolAction';
|
||||
import SidebarTabs from '@/components/SidebarTabs';
|
||||
|
||||
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 [fees, setFees] = useState([]);
|
||||
const [discounts, setDiscounts] = useState([]);
|
||||
const [tuitionFees, setTuitionFees] = useState([]);
|
||||
|
||||
const csrfToken = useCsrfToken();
|
||||
|
||||
@ -38,6 +32,15 @@ export default function Page() {
|
||||
|
||||
// Fetch data for schedules
|
||||
handleSchedules();
|
||||
|
||||
// Fetch data for fees
|
||||
handleFees();
|
||||
|
||||
// Fetch data for discounts
|
||||
handleDiscounts();
|
||||
|
||||
// Fetch data for TuitionFee
|
||||
handleTuitionFees();
|
||||
}, []);
|
||||
|
||||
const handleSpecialities = () => {
|
||||
@ -45,9 +48,7 @@ export default function Page() {
|
||||
.then(data => {
|
||||
setSpecialities(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching specialities:', error);
|
||||
});
|
||||
.catch(error => console.error('Error fetching specialities:', error));
|
||||
};
|
||||
|
||||
const handleTeachers = () => {
|
||||
@ -55,9 +56,7 @@ export default function Page() {
|
||||
.then(data => {
|
||||
setTeachers(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching teachers:', error);
|
||||
});
|
||||
.catch(error => console.error('Error fetching teachers:', error));
|
||||
};
|
||||
|
||||
const handleClasses = () => {
|
||||
@ -65,9 +64,7 @@ export default function Page() {
|
||||
.then(data => {
|
||||
setClasses(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching classes:', error);
|
||||
});
|
||||
.catch(error => console.error('Error fetching classes:', error));
|
||||
};
|
||||
|
||||
const handleSchedules = () => {
|
||||
@ -75,13 +72,35 @@ export default function Page() {
|
||||
.then(data => {
|
||||
setSchedules(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching classes:', error);
|
||||
});
|
||||
.catch(error => console.error('Error fetching schedules:', error));
|
||||
};
|
||||
|
||||
const handleCreate = (url, newData, setDatas) => {
|
||||
fetch(url, {
|
||||
const handleFees = () => {
|
||||
fetchFees()
|
||||
.then(data => {
|
||||
setFees(data);
|
||||
})
|
||||
.catch(error => console.error('Error fetching fees:', error));
|
||||
};
|
||||
|
||||
const handleDiscounts = () => {
|
||||
fetchDiscounts()
|
||||
.then(data => {
|
||||
setDiscounts(data);
|
||||
})
|
||||
.catch(error => console.error('Error fetching discounts:', error));
|
||||
};
|
||||
|
||||
const handleTuitionFees = () => {
|
||||
fetchTuitionFees()
|
||||
.then(data => {
|
||||
setTuitionFees(data);
|
||||
})
|
||||
.catch(error => console.error('Error fetching tuition fees', error));
|
||||
};
|
||||
|
||||
const handleCreate = (url, newData, setDatas, setErrors) => {
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -90,18 +109,28 @@ export default function Page() {
|
||||
body: JSON.stringify(newData),
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(errorData => {
|
||||
throw errorData;
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Succes :', data);
|
||||
setDatas(prevState => [...prevState, data]);
|
||||
setErrors({});
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur :', error);
|
||||
setErrors(error);
|
||||
console.error('Error creating data:', error);
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
const handleEdit = (url, id, updatedData, setDatas) => {
|
||||
fetch(`${url}/${id}`, {
|
||||
const handleEdit = (url, id, updatedData, setDatas, setErrors) => {
|
||||
return fetch(`${url}/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -110,15 +139,41 @@ export default function Page() {
|
||||
body: JSON.stringify(updatedData),
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return response.json().then(errorData => {
|
||||
throw errorData;
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
setDatas(prevState => prevState.map(item => item.id === id ? data : item));
|
||||
setErrors({});
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Erreur :', error);
|
||||
setErrors(error);
|
||||
console.error('Error editing data:', error);
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (url, id, setDatas) => {
|
||||
fetch(`${url}/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
setDatas(prevState => prevState.filter(item => item.id !== id));
|
||||
})
|
||||
.catch(error => console.error('Error deleting data:', error));
|
||||
};
|
||||
const handleUpdatePlanning = (url, planningId, updatedData) => {
|
||||
fetch(`${url}/${planningId}`, {
|
||||
method: 'PUT',
|
||||
@ -139,35 +194,11 @@ export default function Page() {
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (url, id, setDatas) => {
|
||||
fetch(`${url}/${id}`, {
|
||||
method:'DELETE',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Success:', data);
|
||||
setDatas(prevState => prevState.filter(item => item.id !== id));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
error = error.errorMessage;
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='p-8'>
|
||||
<DjangoCSRFToken csrfToken={csrfToken} />
|
||||
|
||||
<TabsStructure activeTab={activeTab} setActiveTab={setActiveTab} tabs={tabs} />
|
||||
|
||||
{activeTab === 'Configuration' && (
|
||||
<>
|
||||
const tabs = [
|
||||
{
|
||||
id: 'Configuration',
|
||||
label: "Configuration de l'école",
|
||||
content: (
|
||||
<StructureManagement
|
||||
specialities={specialities}
|
||||
setSpecialities={setSpecialities}
|
||||
@ -177,18 +208,49 @@ export default function Page() {
|
||||
setClasses={setClasses}
|
||||
handleCreate={handleCreate}
|
||||
handleEdit={handleEdit}
|
||||
handleDelete={handleDelete} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'Schedule' && (
|
||||
handleDelete={handleDelete}
|
||||
/>
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'Schedule',
|
||||
label: "Gestion de l'emploi du temps",
|
||||
content: (
|
||||
<ClassesProvider>
|
||||
<ScheduleManagement
|
||||
handleUpdatePlanning={handleUpdatePlanning}
|
||||
classes={classes}
|
||||
/>
|
||||
</ClassesProvider>
|
||||
)}
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'Fees',
|
||||
label: 'Tarifications',
|
||||
content: (
|
||||
<FeesManagement
|
||||
fees={fees}
|
||||
setFees={setFees}
|
||||
discounts={discounts}
|
||||
setDiscounts={setDiscounts}
|
||||
tuitionFees={tuitionFees}
|
||||
setTuitionFees={setTuitionFees}
|
||||
handleCreate={handleCreate}
|
||||
handleEdit={handleEdit}
|
||||
handleDelete={handleDelete}
|
||||
/>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='p-8'>
|
||||
<DjangoCSRFToken csrfToken={csrfToken} />
|
||||
|
||||
<div className="w-full p-4">
|
||||
<SidebarTabs tabs={tabs} />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user