refactor: Partie FRONT / School

This commit is contained in:
N3WT DE COMPET
2025-01-12 16:45:41 +01:00
parent 41aa9d55d3
commit 24352efad3
25 changed files with 217 additions and 186 deletions

View File

@ -11,6 +11,7 @@ import { BE_SCHOOL_SPECIALITIES_URL,
import DjangoCSRFToken from '@/components/DjangoCSRFToken'
import useCsrfToken from '@/hooks/useCsrfToken';
import { ClassesProvider } from '@/context/ClassesContext';
import { fetchSpecialities, fetchTeachers, fetchClasses, fetchSchedules } from '@/app/lib/schoolAction';
export default function Page() {
const [specialities, setSpecialities] = useState([]);
@ -27,21 +28,20 @@ export default function Page() {
useEffect(() => {
// Fetch data for specialities
fetchSpecialities();
handleSpecialities();
// Fetch data for teachers
fetchTeachers();
handleTeachers();
// Fetch data for classes
fetchClasses();
handleClasses();
// Fetch data for schedules
fetchSchedules();
handleSchedules();
}, []);
const fetchSpecialities = () => {
fetch(`${BE_SCHOOL_SPECIALITIES_URL}`)
.then(response => response.json())
const handleSpecialities = () => {
fetchSpecialities()
.then(data => {
setSpecialities(data);
})
@ -50,9 +50,8 @@ export default function Page() {
});
};
const fetchTeachers = () => {
fetch(`${BE_SCHOOL_TEACHERS_URL}`)
.then(response => response.json())
const handleTeachers = () => {
fetchTeachers()
.then(data => {
setTeachers(data);
})
@ -61,9 +60,8 @@ export default function Page() {
});
};
const fetchClasses = () => {
fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
.then(response => response.json())
const handleClasses = () => {
fetchClasses()
.then(data => {
setClasses(data);
})
@ -72,9 +70,8 @@ export default function Page() {
});
};
const fetchSchedules = () => {
fetch(`${BE_SCHOOL_PLANNINGS_URL}`)
.then(response => response.json())
const handleSchedules = () => {
fetchSchedules()
.then(data => {
setSchedules(data);
})
@ -142,7 +139,6 @@ export default function Page() {
});
};
const handleDelete = (url, id, setDatas) => {
fetch(`${url}/${id}`, {
method:'DELETE',

View File

@ -1,9 +1,26 @@
import {
BE_SCHOOL_SCHOOLCLASSES_URL
BE_SCHOOL_SPECIALITIES_URL,
BE_SCHOOL_TEACHERS_URL,
BE_SCHOOL_SCHOOLCLASSES_URL,
BE_SCHOOL_PLANNINGS_URL
} from '@/utils/Url';
export const fetchClasses = () => {
return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
.then(response => response.json())
export const fetchSpecialities = () => {
return fetch(`${BE_SCHOOL_SPECIALITIES_URL}`)
.then(response => response.json())
};
};
export const fetchTeachers = () => {
return fetch(`${BE_SCHOOL_TEACHERS_URL}`)
.then(response => response.json())
};
export const fetchClasses = () => {
return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
.then(response => response.json())
};
export const fetchSchedules = () => {
return fetch(`${BE_SCHOOL_PLANNINGS_URL}`)
.then(response => response.json())
};