aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-frontend/src/components/CartStatus.tsx
blob: 338e2cb8acba4aaabcab5085a6077cdd9ff0f492 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
import { useSelector } from "react-redux";
import { RootState } from "../store";

const CartStatus = () => {
    const cart = useSelector((state: RootState) => state.cart);
    const total = cart.cart.reduce((acc, item) => acc + item.quantity, 0);
    const price = cart.cart.reduce((acc, item) => acc + (parseFloat(item.estPrice) * item.quantity), 0);

    return <p>You currently have {total} items in your cart, totalling ${price.toFixed(2)} USD</p>;
};

export default CartStatus;