From ba70a6d4ca828b08be4b8a27d3abb3868d85668f Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 4 Aug 2023 09:34:45 +0700 Subject: fixing validasi variant qty --- src/lib/product/components/Product/ProductDesktop.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 7e1d0d3b..3b21db6b 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -54,9 +54,10 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const setVariantQuantityRef = (variantId) => (element) => { if (element) { let variantIndex = product.variants.findIndex((varian) => varian.id == variantId) - product.variants[variantIndex].quantity = element.value + product.variants[variantIndex].quantity = element?.value } variantQuantityRefs.current[variantId] = element + } const validQuantity = (quantity) => { @@ -106,6 +107,15 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { setAddCartAlert(true) } + const handleQuantityChange = (variantId) => (event) => { + const { value } = event.target; + const variantIndex = product.variants.findIndex((variant) => variant.id === variantId); + if (variantIndex !== -1) { + product.variants[variantIndex].quantity = parseInt(value, 10); // Pastikan untuk mengubah ke tipe number jika diperlukan + // Lakukan sesuatu jika nilai quantity diubah + } + }; + const handleBuy = (variant) => { const quantity = variantQuantityRefs.current[variant].value if (!validQuantity(quantity)) return @@ -579,7 +589,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { type='number' className='form-input w-16 py-2 text-center bg-gray_r-1' ref={setVariantQuantityRef(variant.id)} - onChange={setVariantQuantityRef(variant.id)} + onChange={handleQuantityChange(variant.id)} defaultValue={1} /> -- cgit v1.2.3 From 47d81f5b23a96611db07f92203d03fc761a68db9 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 4 Aug 2023 09:36:50 +0700 Subject: ketinggalan --- src/lib/product/components/Product/ProductDesktop.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 3b21db6b..372ad3ba 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -422,7 +422,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { type='number' className='form-input w-16 py-2 text-center bg-gray_r-1' ref={setVariantQuantityRef(product.variants[0].id)} - onChange={setVariantQuantityRef(product.variants[0].id)} + onChange={handleQuantityChange(product.variants[0].id)} defaultValue={1} /> - ) : selectedVariant ? activeVariant?.sla?.slaDate != '-' ? ( - - ):('-') : ( + {activeVariant?.sla?.slaDate} + +
+ +
+ + ) : ( + '-' + ) + ) : ( '-' )} diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index 9e559358..d33516dd 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -7,14 +7,25 @@ import whatsappUrl from '@/core/utils/whatsappUrl' import ImageNext from 'next/image' import Product from './Product/Product' import { useRouter } from 'next/router' +import { useEffect, useState } from 'react' +import odooApi from '@/core/api/odooApi' const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { const router = useRouter() - console.log('ini route', router) + + const [backgorundFlashSale, setBackgorundFlashSale] = useState(null) + const callForPriceWhatsapp = whatsappUrl('product', { name: product.name, url: createSlug('/shop/product/', product.name, product.id, true) }) + useEffect(() => { + const getBackgound = async () => { + const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner') + setBackgorundFlashSale(get[0].image) + } + getBackgound() + }, []) if (variant == 'vertical') { return ( @@ -29,18 +40,27 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { className='w-full object-contain object-center h-36 sm:h-48' /> {router.pathname != '/' && product?.flashSale?.id > 0 && ( -
-
-
- {product?.lowestPrice.discountPercentage}% -
-
- - {product?.flashSale?.tag} +
+
+ +
+
+
+
+ + {product?.lowestPrice.discountPercentage}% + +
+
+ + + {product?.flashSale?.tag} + +
@@ -52,20 +72,20 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { )}
- {product?.manufacture?.name ? ( - - {product.manufacture.name} - - ) : ( -
-
- )} + {product?.manufacture?.name ? ( + + {product.manufacture.name} + + ) : ( +
-
+ )} Date: Fri, 4 Aug 2023 13:36:47 +0700 Subject: add backgorund image mobile --- src/lib/product/components/Product/ProductMobile.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index f0264542..d25d0861 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -45,7 +45,9 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { useEffect(() => { const getBackgound = async () => { const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner') - setBackgorundFlashSale(get[0].image) + if (get.length > 0) { + setBackgorundFlashSale(get[0].image) + } } getBackgound() }, []) @@ -171,7 +173,11 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { {product?.flashSale?.remainingTime > 0 && (
- +
-- cgit v1.2.3