From 42829a0907590139ecf4328a7a9ff9f6504a9113 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 1 Aug 2024 13:40:57 +0700
Subject: <iman> update pop up cart

---
 src-migrate/modules/product-promo/components/AddToCart.tsx | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

(limited to 'src-migrate/modules/product-promo/components/AddToCart.tsx')

diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx
index 488f3f98..aae5cfc0 100644
--- a/src-migrate/modules/product-promo/components/AddToCart.tsx
+++ b/src-migrate/modules/product-promo/components/AddToCart.tsx
@@ -15,6 +15,7 @@ import Link from 'next/link'
 import LazyLoad from 'react-lazy-load'
 import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar';
 import { IProductDetail } from '~/types/product';
+import { useProductCartContext } from '@/contexts/ProductCartContext'
 
 type Props = {
   promotion: IPromotion
@@ -24,13 +25,13 @@ type Props = {
 type Status = 'idle' | 'loading' | 'success'
 
 const ProductPromoAddToCart = ({product, promotion }: Props) => {
-  console.log("promotion",promotion)
   const auth = getAuth()
   const toast = useToast()
   const router = useRouter()
 
   const [status, setStatus] = useState<Status>('idle')
-  
+  const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } =
+    useProductCartContext()
   const productSimilarQuery = [
     promotion?.name,
     `fq=-product_id_i:${promotion.products[0].product_id}`,
@@ -58,6 +59,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => {
     })
     setStatus('idle')
     setAddCartAlert(true);
+    setRefreshCart(true);
     toast({
       title: 'Tambah ke keranjang',
       description: 'Berhasil menambahkan barang ke keranjang belanja',
@@ -66,9 +68,6 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => {
       isClosable: true,
       position: 'top',
     })
-    // setTimeout(() => {
-    //   window.location.reload();
-    // }, 1500);
   }
 
   useEffect(() => {
@@ -116,9 +115,6 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => {
           active={addCartAlert}
           close={() => {
             setAddCartAlert(false);
-            setTimeout(() => {
-              window.location.reload();
-            }, 1500);
           }}
         >
           <div className='flex mt-4'>
-- 
cgit v1.2.3

