fix pour que ça update les invoices dans le ui quand on cancel

This commit is contained in:
Victor Turgeon 2022-11-25 12:43:02 -05:00
parent a7f343545f
commit 5d64c7d8ca
3 changed files with 20 additions and 9 deletions

View File

@ -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({

View File

@ -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...`,

View File

@ -758,6 +758,7 @@ a {
width: 50%;
margin: auto;
margin-top: 10px;
margin-right: 10px;
}
.invoice-item-products {