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