4
0
forked from crowetic/commerce

Open cart sidebar after adding an item

This commit is contained in:
Luis Alvarez 2020-10-07 15:30:25 -05:00
parent e874f43abc
commit ee1051c2ca

View File

@ -6,6 +6,7 @@ import { Swatch } from '@components/product'
import { Colors } from '@components/ui/types' import { Colors } from '@components/ui/types'
import type { Product } from '@lib/bigcommerce/api/operations/get-product' import type { Product } from '@lib/bigcommerce/api/operations/get-product'
import useAddItem from '@lib/bigcommerce/cart/use-add-item' import useAddItem from '@lib/bigcommerce/cart/use-add-item'
import { useUI } from '@components/ui/context'
interface ProductData { interface ProductData {
name: string name: string
@ -27,12 +28,14 @@ const COLORS: Colors[] = ['pink', 'black', 'white']
const ProductView: FC<Props> = ({ product, productData, className }) => { const ProductView: FC<Props> = ({ product, productData, className }) => {
const addItem = useAddItem() const addItem = useAddItem()
const addToCart = () => { const { openSidebar } = useUI()
const addToCart = async () => {
// TODO: loading state by awating the promise // TODO: loading state by awating the promise
addItem({ await addItem({
productId: product.entityId, productId: product.entityId,
variantId: product.variants.edges?.[0]?.node.entityId!, variantId: product.variants.edges?.[0]?.node.entityId!,
}) })
openSidebar()
} }
return ( return (