From d4f4e64ca2d96d0f7ec1243fff0f33eacab955d0 Mon Sep 17 00:00:00 2001
From: Joe Banks <joe@jb3.dev>
Date: Thu, 5 Sep 2024 18:48:30 +0100
Subject: Add CardStatus component

---
 thallium-frontend/src/components/CartStatus.tsx | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 thallium-frontend/src/components/CartStatus.tsx

(limited to 'thallium-frontend/src/components/CartStatus.tsx')

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;
-- 
cgit v1.2.3

