aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-09-11 16:29:51 +0100
committerGravatar Joe Banks <[email protected]>2024-09-11 16:29:51 +0100
commit601339c4ad62bd5cde4ce27f51b28cb54b839a50 (patch)
tree38063610b6ba50aaa8dd8b5c4fb46656a35b0794
parentFetch current voucher token from store when fetched (diff)
Add component for store cart state
-rw-r--r--thallium-frontend/src/components/CartStatus.tsx20
1 files changed, 19 insertions, 1 deletions
diff --git a/thallium-frontend/src/components/CartStatus.tsx b/thallium-frontend/src/components/CartStatus.tsx
index 338e2cb..8fd54d9 100644
--- a/thallium-frontend/src/components/CartStatus.tsx
+++ b/thallium-frontend/src/components/CartStatus.tsx
@@ -1,12 +1,30 @@
import { useSelector } from "react-redux";
import { RootState } from "../store";
+import styled from "styled-components";
+import Button from "./forms/Button";
+import { useNavigate } from "react-router-dom";
+
+const StatusHolder = styled.span`
+ margin-top: 1rem;
+ margin-bottom: 1rem;
+
+`;
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>;
+ const navigate = useNavigate();
+
+ return <>
+ <StatusHolder>You currently have {total} item{total !== 1 ? "s" : null} in your cart, totalling ${price.toFixed(2)} USD</StatusHolder>
+ {total > 0 ? <Button onClick={() => {
+ navigate("/checkout");
+ }}>
+ Checkout &gt;
+ </Button> : null}
+ </>;
};
export default CartStatus;