diff options
Diffstat (limited to 'src-migrate/modules/product-detail')
3 files changed, 60 insertions, 13 deletions
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 280e4a7a..95bc1d88 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -15,7 +15,8 @@ import { useProductCartContext } from '@/contexts/ProductCartContext'; import { createSlug } from '~/libs/slug'; import formatCurrency from '~/libs/formatCurrency'; import { useProductDetail } from '../stores/useProductDetail'; - +import { gtagAddToCart } from '@/core/utils/googleTag'; +import axios from 'axios'; type Props = { variantId: number | null; quantity?: number; @@ -50,6 +51,38 @@ const AddToCart = ({ isLoading, setIsloading, } = useProductCartContext(); + const [activeVariant, setActiveVariant] = useState({ + id: 0, + code: '', + name: '', + price: '', + stock: '', + weight: '', + isFlashSale: false, + }); + + useEffect(() => { + const fetchData = async () => { + if (variantId) { + let response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=${variantId}` + ); + let productVariant = response.data; + if (productVariant) { + setActiveVariant({ + id: productVariant[0].id, + code: productVariant[0].code, + name: productVariant[0].name, + price: productVariant[0].price.price, + stock: productVariant[0].stockTotal, + weight: productVariant[0].weight, + isFlashSale: productVariant[0].isFlashsale, + }); + } + } + }; + fetchData(); + }, [variantId]); const productSimilarQuery = [ product?.name, @@ -101,6 +134,8 @@ const AddToCart = ({ setRefreshCart(true); setAddCartAlert(true); + gtagAddToCart(activeVariant, quantity); + toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx index 9348bbfb..850c2d9d 100644 --- a/src-migrate/modules/product-detail/components/PriceAction.tsx +++ b/src-migrate/modules/product-detail/components/PriceAction.tsx @@ -163,7 +163,7 @@ const PriceAction = ({ product }: Props) => { </span> */} </div> <div> - {selectedVariant?.is_in_bu && ( + {qtyPickUp > 0 && ( <Link href='/panduan-pick-up-service' className='group'> <Image src='/images/PICKUP-NOW.png' diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index b036cc2d..4667e086 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -66,7 +66,11 @@ const ProductDetail = ({ product }: Props) => { if (typeof auth === 'object') { setIsApproval(auth?.feature?.soApproval); } - setSelectedVariant(product?.variants[0]) + const selectedVariant = + product?.variants?.find((variant) => variant.is_in_bu) || + product?.variants?.[0]; + setSelectedVariant(selectedVariant); + // setSelectedVariant(product?.variants[0]) }, []); return ( @@ -102,7 +106,12 @@ const ProductDetail = ({ product }: Props) => { )} <div className='h-4 md:h-10' /> - {!!activeVariantId && !isApproval && <ProductPromoSection product={product} productId={activeVariantId} />} + {!!activeVariantId && !isApproval && ( + <ProductPromoSection + product={product} + productId={activeVariantId} + /> + )} {/* <div className={style['section-card']}> <h2 className={style['heading']}> @@ -117,15 +126,18 @@ const ProductDetail = ({ product }: Props) => { <div className={style['section-card']}> <h2 className={style['heading']}>Informasi Produk</h2> <div className='h-4' /> - <div - className={style['description']} - dangerouslySetInnerHTML={{ - __html: - !product.description || product.description == '<p><br></p>' - ? 'Belum ada deskripsi' - : product.description, - }} - /> + <div className='overflow-x-auto'> + <div + className={style['description']} + dangerouslySetInnerHTML={{ + __html: + !product.description || + product.description == '<p><br></p>' + ? 'Belum ada deskripsi' + : product.description, + }} + /> + </div> </div> </div> </div> |
