feat: Mise à jour du modèle (possibilité d'associer une réduciton à un

frais d'inscription [#18]
This commit is contained in:
N3WT DE COMPET
2025-01-20 20:42:51 +01:00
parent 5a0e65bb75
commit 8d1a41e269
9 changed files with 224 additions and 151 deletions

View File

@ -99,7 +99,7 @@ export default function Page() {
.catch(error => console.error('Error fetching tuition fees', error));
};
const handleCreate = (url, newData, setDatas, setErrors) => {
const handleCreate = (url, newData, setDatas) => {
return fetch(url, {
method: 'POST',
headers: {
@ -119,17 +119,15 @@ export default function Page() {
})
.then(data => {
setDatas(prevState => [...prevState, data]);
setErrors({});
return data;
})
.catch(error => {
setErrors(error);
console.error('Error creating data:', error);
throw error;
});
};
const handleEdit = (url, id, updatedData, setDatas, setErrors) => {
const handleEdit = (url, id, updatedData, setDatas) => {
return fetch(`${url}/${id}`, {
method: 'PUT',
headers: {
@ -149,18 +147,16 @@ export default function Page() {
})
.then(data => {
setDatas(prevState => prevState.map(item => item.id === id ? data : item));
setErrors({});
return data;
})
.catch(error => {
setErrors(error);
console.error('Error editing data:', error);
throw error;
});
};
const handleDelete = (url, id, setDatas) => {
fetch(`${url}/${id}`, {
return fetch(`${url}/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
@ -168,12 +164,24 @@ export default function Page() {
},
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.filter(item => item.id !== id));
return data;
})
.catch(error => console.error('Error deleting data:', error));
.catch(error => {
console.error('Error deleting data:', error);
throw error;
});
};
const handleUpdatePlanning = (url, planningId, updatedData) => {
fetch(`${url}/${planningId}`, {
method: 'PUT',