diff options
author | 2024-09-05 18:48:30 +0100 | |
---|---|---|
committer | 2024-09-05 18:48:30 +0100 | |
commit | d4f4e64ca2d96d0f7ec1243fff0f33eacab955d0 (patch) | |
tree | 2644b8532aab6ab4f9bcb8465ab183c366b027c4 | |
parent | Add cart slice (diff) |
Add CardStatus component
-rw-r--r-- | thallium-frontend/src/components/CartStatus.tsx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/thallium-frontend/src/components/CartStatus.tsx b/thallium-frontend/src/components/CartStatus.tsx new file mode 100644 index 0000000..338e2cb --- /dev/null +++ b/thallium-frontend/src/components/CartStatus.tsx @@ -0,0 +1,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; |