react-version #1

Merged
memartel_loc merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
2 changed files with 18 additions and 30 deletions
Showing only changes of commit 8a887f7d7e - Show all commits

View File

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

View File

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