From 5d64c7d8ca4900ddac032978132d08b26845872b Mon Sep 17 00:00:00 2001 From: Victor Turgeon Date: Fri, 25 Nov 2022 12:43:02 -0500 Subject: [PATCH] =?UTF-8?q?fix=20pour=20que=20=C3=A7a=20update=20les=20inv?= =?UTF-8?q?oices=20dans=20le=20ui=20quand=20on=20cancel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grosses-mitaines-ui/src/pages/Invoices.js | 15 +++++++++++---- .../grosses-mitaines-ui/src/pages/MyInvoices.js | 13 ++++++++----- .../grosses-mitaines-ui/src/stylesheets/site.css | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Invoices.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Invoices.js index eccb20b..4b11d8a 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Invoices.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Invoices.js @@ -24,7 +24,7 @@ const Invoices = () => { var json = await response.json(); setInvoices(json); } - else{ + else { console.log("Erreur lors de la requête des invoices"); } }); @@ -47,10 +47,17 @@ const Invoices = () => { credentials: 'include' }).then(async (response) => { if (response.ok) { - const deletedId = await response.json(); - setInvoices(invoices.filter((invoice) => invoice.id !== deletedId)); + const deletedInvoice = await response.json(); + var newInvoice = invoices.find(x => x.id == deletedInvoice.id); + console.log(newInvoice); + newInvoice.status = deletedInvoice.status; + setInvoices([...(invoices.filter(x => x.id !== newInvoice.id)), { ...newInvoice }].sort((a, b) => a.id - b.id)); - onShowAlert('Annulation de la commande avec succès!', 2000); + mySwal.fire({ + title: `Commande annulée...`, + text: `La commande a été annulée!`, + icon: 'success', + }); } else { mySwal.fire({ diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js index 6d62068..6ba10f8 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js @@ -7,9 +7,9 @@ import withReactContent from "sweetalert2-react-content"; const MyInvoices = () => { const [invoices, setInvoices] = useState([]); - + const mySwal = withReactContent(Swal); - + useEffect(() => { fetch(`https://localhost:7292/api/Invoice`, { method: 'GET', @@ -20,7 +20,7 @@ const MyInvoices = () => { var json = await response.json(); setInvoices(json); } - else{ + else { console.log("Erreur lors de la requête des invoices"); } }); @@ -43,8 +43,11 @@ const MyInvoices = () => { credentials: 'include' }).then(async (response) => { if (response.ok) { - const deletedId = await response.json(); - setInvoices(invoices.filter((invoice) => invoice.id !== deletedId)); + const deletedInvoice = await response.json(); + var newInvoice = invoices.find(x => x.id == deletedInvoice.id); + console.log(newInvoice); + newInvoice.status = deletedInvoice.status; + setInvoices([...(invoices.filter(x => x.id !== newInvoice.id)), { ...newInvoice }].sort((a, b) => a.id - b.id)); mySwal.fire({ title: `Commande annulée...`, diff --git a/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css b/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css index d82ca7e..b1504b5 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css +++ b/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css @@ -758,6 +758,7 @@ a { width: 50%; margin: auto; margin-top: 10px; + margin-right: 10px; } .invoice-item-products {