gossage
This commit is contained in:
parent
67016e388f
commit
8a887f7d7e
@ -10,10 +10,6 @@ const MyInvoices = () => {
|
|||||||
|
|
||||||
const mySwal = withReactContent(Swal);
|
const mySwal = withReactContent(Swal);
|
||||||
|
|
||||||
const [alertTitle, setAlertTitle] = useState("");
|
|
||||||
const [alertMessage, setAlertMessage] = useState("");
|
|
||||||
const [showAlert, setShowAlert] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`https://localhost:7292/api/Invoice`, {
|
fetch(`https://localhost:7292/api/Invoice`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -50,7 +46,6 @@ const MyInvoices = () => {
|
|||||||
const deletedId = await response.json();
|
const deletedId = await response.json();
|
||||||
setInvoices(invoices.filter((invoice) => invoice.id !== deletedId));
|
setInvoices(invoices.filter((invoice) => invoice.id !== deletedId));
|
||||||
|
|
||||||
onShowAlert('Suppression de la commande avec succès!', 2000);
|
|
||||||
mySwal.fire({
|
mySwal.fire({
|
||||||
title: `Commande annulée...`,
|
title: `Commande annulée...`,
|
||||||
text: `La commande a été 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 (
|
return (
|
||||||
|
@ -7,16 +7,17 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
import { CartContext } from "../components/Cart";
|
import { CartContext } from "../components/Cart";
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
const ReviewInvoice = () => {
|
const ReviewInvoice = () => {
|
||||||
|
|
||||||
const cookies = new Cookies();
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const mySwal = withReactContent(Swal);
|
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({
|
const [thisInvoice, setThisInvoice] = useState({
|
||||||
firstName: "",
|
firstName: "",
|
||||||
@ -34,8 +35,18 @@ const ReviewInvoice = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const cookies = new Cookies();
|
||||||
const thisInvoice = cookies.get('invoice');
|
const thisInvoice = cookies.get('invoice');
|
||||||
if (thisInvoice != null) {
|
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) => {
|
setThisInvoice((e) => {
|
||||||
return {
|
return {
|
||||||
@ -51,19 +62,9 @@ const ReviewInvoice = () => {
|
|||||||
province: thisInvoice.province,
|
province: thisInvoice.province,
|
||||||
country: thisInvoice.country,
|
country: thisInvoice.country,
|
||||||
postalCode: thisInvoice.postalCode,
|
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 {
|
else {
|
||||||
console.log("No invoice to review!");
|
console.log("No invoice to review!");
|
||||||
@ -119,14 +120,15 @@ const ReviewInvoice = () => {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
const json = JSON.stringify(thisInvoice);
|
const json = JSON.stringify(thisInvoice);
|
||||||
|
console.log(json);
|
||||||
|
|
||||||
const response = await fetch(`https://localhost:7292/api/Invoice`, {
|
const response = await fetch(`https://localhost:7292/api/Invoice`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'text/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'text/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: json
|
body: json
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user