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 20 additions and 10 deletions
Showing only changes of commit a33c04b71f - Show all commits

View File

@ -10,7 +10,8 @@ export const CartContext = createContext({
removeOneFromCart: () => { },
deleteFromCart: () => { },
getTotalCost: () => { },
addToCart: () => { }
addToCart: () => { },
emptyCart: () => { }
});
export function CartProvider({ children }) {
@ -27,7 +28,7 @@ export function CartProvider({ children }) {
}, []);
useEffect(() => {
cookies.set('cart', cartProducts, { path: '/', SameSite: 'strict', secure: true, maxAge: 2592000 })
cookies.set('cart', cartProducts, { path: '/', SameSite: 'strict', secure: true, maxAge: 2592000 });
}, [cartProducts]);
@ -101,6 +102,11 @@ export function CartProvider({ children }) {
return totalCost;
};
function emptyCart() {
cookies.remove('cart', { path: '/', domain: "localhost"});
setCartProducts([]);
}
const contextValue = {
items: cartProducts,
getProductQuantity,
@ -109,7 +115,8 @@ export function CartProvider({ children }) {
removeOneFromCart,
deleteFromCart,
getTotalCost,
addToCart
addToCart,
emptyCart
};
return (

View File

@ -6,7 +6,7 @@ import { Row, Col, Button } from "react-bootstrap";
import { useNavigate } from "react-router-dom";
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
import CartProvider from "../components/Cart";
import { CartContext } from "../components/Cart";
const ReviewInvoice = () => {
@ -14,9 +14,9 @@ const ReviewInvoice = () => {
const navigate = useNavigate();
const mySwal = withReactContent(Swal);
const cart = useContext(CartProvider);
const cart = useContext(CartContext);
//const [products, setProducts] = useState([]);
const [products, setProducts] = useState([]);
const [thisInvoice, setThisInvoice] = useState({
firstName: "",
@ -55,7 +55,7 @@ const ReviewInvoice = () => {
}
})
//var prods = [];
// var prods = [];
// Object.keys(thisInvoice.prodQuant).map((k) => {
// fetch(`https://localhost:7292/api/Product?id=${k}`)
// .then(async (response) => {
@ -135,9 +135,12 @@ const ReviewInvoice = () => {
title: 'Commande envoyée avec succès!',
timer: 2000,
icon: "success"
})
cart.items = [];
navigate('./Morceaux');
}).then(
() => {
cart.emptyCart();
navigate('/morceaux');
}
)
}
else {
console.log("Erreur de creation la commande #" + thisInvoice.id);