summaryrefslogtreecommitdiff
path: root/src-migrate/modules
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-08-01 09:21:35 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-08-01 09:21:35 +0000
commit4eab7ee5ce33b73a7c6d4fb6311af1f29afd0f93 (patch)
treed48a05c1586c2dcb403b2abacd5a970b06887f67 /src-migrate/modules
parent7907b4a3acd3f5f4270f2ac1743600bc7a077503 (diff)
parent42829a0907590139ecf4328a7a9ff9f6504a9113 (diff)
Merged in Feature/iman-cart-popup (pull request #199)
Feature/iman cart popup
Diffstat (limited to 'src-migrate/modules')
-rw-r--r--src-migrate/modules/product-detail/components/AddToCart.tsx13
-rw-r--r--src-migrate/modules/product-promo/components/AddToCart.tsx12
2 files changed, 11 insertions, 14 deletions
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx
index b2fed55d..644d5b90 100644
--- a/src-migrate/modules/product-detail/components/AddToCart.tsx
+++ b/src-migrate/modules/product-detail/components/AddToCart.tsx
@@ -10,6 +10,7 @@ import LazyLoad from 'react-lazy-load';
import ProductSimilar from '../../../../src/lib/product/components/ProductSimilar';
import { IProductDetail } from '~/types/product';
import ImageNext from 'next/image';
+import { useProductCartContext } from '@/contexts/ProductCartContext'
type Props = {
variantId: number | null,
@@ -31,7 +32,9 @@ const AddToCart = ({
isClosable: true
})
const [product, setProducts] = useState(products);
-
+ const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } =
+ useProductCartContext()
+
const productSimilarQuery = [
product?.name,
`fq=-product_id_i:${product.id}`,
@@ -53,7 +56,7 @@ const AddToCart = ({
typeof auth !== 'object'
) return;
setAddCartAlert(true);
-
+ setRefreshCart(true);
toast.promise(
upsertUserCart({
userId: auth.id,
@@ -100,10 +103,8 @@ const AddToCart = ({
active={addCartAlert}
close={() => {
setAddCartAlert(false);
- setTimeout(() => {
- window.location.reload();
- }, 1500);
- }}
+ }
+ }
>
<div className='flex mt-4'>
<div className='w-[10%]'>
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'>