diff --git a/src/components/common/ProductCard/ProductCard.tsx b/src/components/common/ProductCard/ProductCard.tsx index 9e2b7087f..2a15dfb5e 100644 --- a/src/components/common/ProductCard/ProductCard.tsx +++ b/src/components/common/ProductCard/ProductCard.tsx @@ -11,6 +11,8 @@ import LabelCommon from '../LabelCommon/LabelCommon' import s from './ProductCard.module.scss' import ProductNotSell from './ProductNotSell/ProductNotSell' import {useAddProductToCart} from "../../hooks/cart" +import { useCartDrawer } from 'src/components/contexts' +import Router from 'next/router' export interface ProductCardProps extends ProductCard { buttonText?: string isSingleButton?: boolean, @@ -31,21 +33,36 @@ const ProductCardComponent = ({ productVariantId, }: ProductCardProps) => { - const {addProduct,loading,error} = useAddProductToCart() + const {addProduct,loading} = useAddProductToCart() + const { openCartDrawer } = useCartDrawer() + const handleAddToCart = () => { if(productVariantId){ addProduct({variantId:productVariantId,quantity:1},handleAddToCartCallback) } } const handleAddToCartCallback = () => { - + openCartDrawer && openCartDrawer() } + + const handleBuyNowCallback = (success:boolean) => { + if(success){ + Router.push(ROUTE.CHECKOUT) + } + } + + const handleBuyNow = () => { + if(productVariantId){ + addProduct({variantId:productVariantId,quantity:1},handleBuyNowCallback) + } + } + if (isNotSell) { return
- } + return (
@@ -83,7 +100,7 @@ const ProductCardComponent = ({ { isSingleButton ?
- } size='small' >Add to cart + } size='small' onClick={handleAddToCart}>Add to cart
: <> @@ -91,7 +108,7 @@ const ProductCardComponent = ({
- {buttonText} + {buttonText}
}