Skip to content
Snippets Groups Projects
Commit de659e3e authored by Princelle Maxime's avatar Princelle Maxime :gay_pride_flag:
Browse files

:bug: fix cart totalPrice

parent 1daeaea6
1 merge request!7🔀 V1
import {Fragment, useContext} from 'react'
import {Fragment, useContext, useEffect, useState} from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { ArrowLeftIcon, EmojiSadIcon } from '@heroicons/react/outline';
......@@ -15,6 +15,19 @@ const Cart = () => {
return `${price.toFixed(2)} €`;
}
let [totalPrice, setTotalPrice] = useState(0);
useEffect(() => {
// Update cart totalPrice
let totalPrice = 0;
cartState.cart.forEach((product) => {
if (product.quantity) {
totalPrice += product.price * product.quantity;
}
});
setTotalPrice(totalPrice);
}, [cartState]);
return (
// S'abonne au contexte
<Transition.Root show={cartState.showCart} as={Fragment}>
......@@ -138,7 +151,7 @@ const Cart = () => {
<dl className="-my-4 text-sm divide-y divide-gray-200">
<div className="py-4 flex items-center justify-between">
<dt className="text-gray-600">Total : </dt>
<dd className="font-medium text-gray-900">{renderPrice(0)}</dd>
<dd className="font-medium text-gray-900">{renderPrice(totalPrice)}</dd>
</div>
</dl>
</div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment