From ee1051c2ca069d57b7b4904af6346091acba8344 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Wed, 7 Oct 2020 15:30:25 -0500 Subject: [PATCH] Open cart sidebar after adding an item --- components/product/ProductView/ProductView.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index fcbbd22ea..4117027aa 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -6,6 +6,7 @@ import { Swatch } from '@components/product' import { Colors } from '@components/ui/types' import type { Product } from '@lib/bigcommerce/api/operations/get-product' import useAddItem from '@lib/bigcommerce/cart/use-add-item' +import { useUI } from '@components/ui/context' interface ProductData { name: string @@ -27,12 +28,14 @@ const COLORS: Colors[] = ['pink', 'black', 'white'] const ProductView: FC = ({ product, productData, className }) => { const addItem = useAddItem() - const addToCart = () => { + const { openSidebar } = useUI() + const addToCart = async () => { // TODO: loading state by awating the promise - addItem({ + await addItem({ productId: product.entityId, variantId: product.variants.edges?.[0]?.node.entityId!, }) + openSidebar() } return (