diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-08-04 06:41:13 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-08-04 06:41:13 +0000 |
| commit | 3e4551692d60f3399e6ddf59528725a63f578f57 (patch) | |
| tree | c277d619ddc0f8fd790bcad35ba1115c37859923 /src/lib/product/components/Product/ProductDesktop.jsx | |
| parent | 76b277555adb635d61c70b6c77293139b20105f3 (diff) | |
| parent | 9595223471946520f5c156e24eceb577fae4c901 (diff) | |
Merged in CR/flash_sale (pull request #36)
CR/flash sale
Diffstat (limited to 'src/lib/product/components/Product/ProductDesktop.jsx')
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 71 |
1 files changed, 52 insertions, 19 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 123ee708..187ab3c9 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -36,6 +36,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const [promotionType, setPromotionType] = useState(false) const [promotionActiveId, setPromotionActiveId] = useState(null) const [selectVariantPromoActive, setSelectVariantPromoActive] = useState(null) + const [backgorundFlashSale, setBackgorundFlashSale] = useState(null) const getLowestPrice = useCallback(() => { const prices = product.variants.map((variant) => variant.price) @@ -50,6 +51,16 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { setLowestPrice(lowest) }, [getLowestPrice]) + useEffect(() => { + const getBackgound = async () => { + const get = await odooApi('GET', '/api/v1/banner?type=flash-sale-background-banner') + setBackgorundFlashSale(get[0].image) + } + getBackgound() + }, []) + + console.log('ini set', backgorundFlashSale) + const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) const variantQuantityRefs = useRef([]) @@ -57,7 +68,7 @@ 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 } @@ -109,6 +120,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 @@ -177,21 +197,32 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { <div className='w-5/12'> <div className='relative mb-2'> {product?.flashSale?.remainingTime > 0 && ( - <div className='absolute bottom-0 bg-red-600 w-full h-15 grid'> - <div className='flex gap-x-2 items-center p-2'> - <div className='bg-yellow-400 rounded-full p-1 h-9 w-20 flex items-center justify-center '> - <span className='text-lg font-bold'>{product.lowestPrice.discountPercentage}%</span> - </div> - <div className='bg-red-600 border border-solid border-yellow-400 rounded-full h-9 p-2 flex w-[50%] items-center justify-center gap-x-4'> - <ImageNext - src='/images/ICON_FLASH_SALE_WEBSITE_INDOTEKNIK.svg' - width={17} - height={10} - /> - <span className='text-white text-lg font-semibold'>{product.flashSale.tag || 'FLASH SALE'}</span> - </div> - <div> - <CountDown2 initialTime={product.flashSale.remainingTime} /> + <div className={`absolute bottom-0 w-full`}> + <div className='absolute bottom-0 w-full h-full'> + <ImageNext src={backgorundFlashSale || '/images/GAMBAR-BG-FLASH-SALE.jpg'} width={1000} height={100} /> + </div> + <div className='relative'> + <div className='flex gap-x-2 items-center p-2'> + <div className='bg-yellow-400 rounded-full p-1 h-9 w-20 flex items-center justify-center '> + <span className='text-lg font-bold'> + {product.lowestPrice.discountPercentage}% + </span> + </div> + <div + className={`bg-red-600 border border-solid border-yellow-400 rounded-full h-9 p-2 flex w-[50%] items-center justify-center gap-x-4`} + > + <ImageNext + src='/images/ICON_FLASH_SALE_WEBSITE_INDOTEKNIK.svg' + width={17} + height={10} + /> + <span className='text-white text-lg font-semibold'> + {product.flashSale.tag || 'FLASH SALE'} + </span> + </div> + <div> + <CountDown2 initialTime={product.flashSale.remainingTime} /> + </div> </div> </div> </div> @@ -416,7 +447,9 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { width={15} height={10} /> - <span className='text-white text-xs font-semibold'>FLASH SALE</span> + <span className='text-white text-xs font-semibold'> + {product.flashSale.tag || 'FLASH SALE'} + </span> </div> )} </div> @@ -456,7 +489,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} /> <button @@ -623,7 +656,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} /> </td> |
