From 8a887f7d7eaf9a7b14875c552aabe98dd46eea34 Mon Sep 17 00:00:00 2001 From: DavidBelisle <79233327+DavidBelisle@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:56:52 -0500 Subject: [PATCH] gossage --- .../src/pages/MyInvoices.js | 14 -------- .../src/pages/ReviewInvoice.js | 34 ++++++++++--------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js index a26d777..0af3bc2 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/MyInvoices.js @@ -9,10 +9,6 @@ const MyInvoices = () => { const [invoices, setInvoices] = useState([]); const mySwal = withReactContent(Swal); - - const [alertTitle, setAlertTitle] = useState(""); - const [alertMessage, setAlertMessage] = useState(""); - const [showAlert, setShowAlert] = useState(false); useEffect(() => { fetch(`https://localhost:7292/api/Invoice`, { @@ -50,7 +46,6 @@ const MyInvoices = () => { const deletedId = await response.json(); setInvoices(invoices.filter((invoice) => invoice.id !== deletedId)); - onShowAlert('Suppression de la commande avec succès!', 2000); mySwal.fire({ title: `Commande annulée...`, text: `La commande a été annulée!`, @@ -70,15 +65,6 @@ const MyInvoices = () => { }; - const onShowAlert = (title, message, time) => { - - setAlertTitle(title); - setAlertMessage(message); - setShowAlert(true); - - window.setTimeout(() => { setShowAlert(false); }, time); - } - return ( diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js index d832088..335bd5c 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js @@ -7,16 +7,17 @@ import { useNavigate } from "react-router-dom"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { CartContext } from "../components/Cart"; +import { useRef } from "react"; const ReviewInvoice = () => { - const cookies = new Cookies(); + const navigate = useNavigate(); const mySwal = withReactContent(Swal); - const cart = useContext(CartContext); + const cart = useRef(useContext(CartContext)); - const [products, setProducts] = useState([]); + //const [products, setProducts] = useState([]); const [thisInvoice, setThisInvoice] = useState({ firstName: "", @@ -34,8 +35,18 @@ const ReviewInvoice = () => { }); useEffect(() => { + const cookies = new Cookies(); const thisInvoice = cookies.get('invoice'); if (thisInvoice != null) { + var dic = {}; + + if (cart.current.items.length > 0) { + cart.current.items.forEach((item) => + dic[item.id] = item.qty + ) + } + + //dic[5] = 1; setThisInvoice((e) => { return { @@ -51,19 +62,9 @@ const ReviewInvoice = () => { province: thisInvoice.province, country: thisInvoice.country, postalCode: thisInvoice.postalCode, - prodQuant: thisInvoice.prodQuant + prodQuant: dic } }) - - // var prods = []; - // Object.keys(thisInvoice.prodQuant).map((k) => { - // fetch(`https://localhost:7292/api/Product?id=${k}`) - // .then(async (response) => { - // prods.push({ product: await response.json(), quantity: thisInvoice.prodQuant[k] }); - // }).then(() => { - // setProducts(prods.sort((a, b) => a.product.id - b.product.id)); - // }) - // }); } else { console.log("No invoice to review!"); @@ -119,14 +120,15 @@ const ReviewInvoice = () => { // }); const json = JSON.stringify(thisInvoice); + console.log(json); const response = await fetch(`https://localhost:7292/api/Invoice`, { method: 'POST', credentials: 'include', mode: 'cors', headers: { - 'Accept': 'text/json', - 'Content-Type': 'text/json' + 'Accept': 'application/json', + 'Content-Type': 'application/json' }, body: json })