This commit is contained in:
DavidBelisle 2022-11-23 16:56:52 -05:00
parent 67016e388f
commit 8a887f7d7e
2 changed files with 18 additions and 30 deletions

View File

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

View File

@ -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
})