diff options
author | 2024-09-05 18:48:49 +0100 | |
---|---|---|
committer | 2024-09-05 18:48:49 +0100 | |
commit | 41cff3f854104490fa112bdd8836522c97ca9f5f (patch) | |
tree | c89d20a42e6fcba1228475a7fb3c66cbd058e5fd | |
parent | Add CardStatus component (diff) |
Add item to cart slice on button press in StoreItem
-rw-r--r-- | thallium-frontend/src/components/StoreItem.tsx | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/thallium-frontend/src/components/StoreItem.tsx b/thallium-frontend/src/components/StoreItem.tsx index a7bd52b..0cd4da2 100644 --- a/thallium-frontend/src/components/StoreItem.tsx +++ b/thallium-frontend/src/components/StoreItem.tsx @@ -3,6 +3,11 @@ import styled from "styled-components"; import { Template, Variant } from "../api/templates"; import Button from "./forms/Button"; +import { addCartItem } from "../slices/cart"; +import store from "../store"; + +import { toast } from "react-toastify"; + interface StoreItemProps { template: Template; } @@ -270,6 +275,17 @@ const StoreItem: React.FC<StoreItemProps> = ({ template }: StoreItemProps) => { <CartButton disabled={selectedVariant === null} + onClick={() => { + if (selectedVariant) { + store.dispatch(addCartItem({ + product_template_id: template.template_id, + variant_id: selectedVariant.variant_id, + estPrice: selectedVariant.price, + })); + + toast("Item added to cart!"); + } + }} >Add to Cart</CartButton> </StoreItemContainer> ); |