react-version #1

Merged
memartel_loc merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
Showing only changes of commit a61c40ae79 - Show all commits

View File

@ -21,9 +21,6 @@ const Inventaire = () => {
}, []);
const handleAddItem = async (morceau) => {
console.log(morceau);
const response = await fetch(`https://localhost:7292/api/Product`, {
method: 'POST',
headers: {
@ -33,7 +30,8 @@ const Inventaire = () => {
body: JSON.stringify(morceau)
})
const newMorceau = response.json();
const newMorceau = await response.json();
console.log(newMorceau);
if (response.ok)
setMorceaux([...morceaux, { ...newMorceau }]);
@ -45,8 +43,12 @@ const Inventaire = () => {
const response = await fetch(`https://localhost:7292/api/Product?id=${id}`, { method: 'DELETE', mode: 'cors' });
if (response.ok)
setMorceaux(morceaux.filter((morceau) => morceau.id !== id))
const deletedId = await response.json();
if (response.ok){
setMorceaux(morceaux.filter((morceau) => morceau.id !== deletedId));
console.log("DELETE de: "+deletedId +" avec succès!");
}
else
console.log("Erreur leur du DELETE de " + id);
};