Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version

This commit is contained in:
MarcEricMartel 2022-10-18 12:07:22 -07:00
commit 55a240be51

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);
};