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

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

View File

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

View File

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