From d793056d1645c221d02fb821e34ab2c435c387d0 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 13 Nov 2025 16:20:23 +0700 Subject: product variant --- .../components/Product/ProductDesktopVariant.jsx | 151 ++++++----- .../components/Product/ProductMobileVariant.jsx | 281 +++++++++++---------- 2 files changed, 231 insertions(+), 201 deletions(-) diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx index 44ae04bd..6b4ab1e1 100644 --- a/src/lib/product/components/Product/ProductDesktopVariant.jsx +++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx @@ -1,3 +1,4 @@ +import { AlertTriangle } from 'lucide-react'; import { Box, Button, Skeleton, Tooltip } from '@chakra-ui/react'; import { HeartIcon } from '@heroicons/react/24/outline'; import { Info, MessageCircleIcon, Share2Icon } from 'lucide-react'; @@ -249,6 +250,7 @@ const ProductDesktopVariant = ({ }); router.push('/shop/quotation?source=buy'); }; + const hasPrice = Number(product?.price?.price) > 0; const variantSectionRef = useRef(null); const goToVariantSection = () => { @@ -314,6 +316,17 @@ const ProductDesktopVariant = ({ return ( +
+ {!hasPrice && ( +
+ Produk tidak tersedia +
+ )} +
@@ -326,9 +339,21 @@ const ProductDesktopVariant = ({
+ {!hasPrice && ( +
+ +

+ Maaf untuk saat ini Produk yang anda cari tidak tersedia +

+
+ )}

{product?.name}

+
Item Code
@@ -430,73 +455,55 @@ const ProductDesktopVariant = ({
- {product?.isFlashsale > 0 && - product?.price?.discountPercentage > 0 ? ( + {product?.price?.price > 0 && ( <> -
-
- {product?.price?.discountPercentage}% -
-
- {currencyFormat(product?.price?.price)} -
-
- {currencyFormat(product?.price?.priceDiscount)} -
-
-
- Termasuk PPN:{' '} - {currencyFormat( - product?.price?.priceDiscount * process.env.NEXT_PUBLIC_PPN - )} -
- - ) : ( -

- {product?.price?.price > 0 ? ( + {product?.isFlashsale > 0 && + product?.price?.discountPercentage > 0 ? ( <> - {currencyFormat(product?.price?.price)} +
+
+ {product?.price?.discountPercentage}% +
+
+ {currencyFormat(product?.price?.price)} +
+
+ {currencyFormat(product?.price?.priceDiscount)} +
+
Termasuk PPN:{' '} {currencyFormat( - product?.price?.price * process.env.NEXT_PUBLIC_PPN + product?.price?.priceDiscount * + process.env.NEXT_PUBLIC_PPN )}
) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - +

+ {currencyFormat(product?.price?.price)} +
+ Termasuk PPN:{' '} + {currencyFormat( + product?.price?.price * process.env.NEXT_PUBLIC_PPN + )} +
+

)} - + )} +
@@ -518,43 +525,40 @@ const ProductDesktopVariant = ({ if (['e', 'E', '+', '-', '.'].includes(e.key)) e.preventDefault(); }} - className='w-24 h-10 text-center border border-gray-300 rounded focus:outline-none' + className='w-24 h-10 text-center border border-gray-300 rounded focus:outline-none disabled:bg-gray-100 disabled:text-gray-400' + disabled={!hasPrice} />
- {/* - Stock : {product?.sla?.qty}{' '} - */} - - Stock : {fakeStock}{' '} + Stock : {hasPrice ? fakeStock : 'Habis'}
+
- {qtyPickUp > 0 && ( + {qtyPickUp > 0 && hasPrice && (
- {qtyPickUp > 0 && ( + {/* {qtyPickUp > 0 && ( <>
* {qtyPickUp} barang bisa di pickup
- )} + )} */}
@@ -586,6 +593,9 @@ const ProductDesktopVariant = ({ onClick={() => handleBuy(product.id)} className='w-full' colorScheme='red' + isDisabled={ + !product?.price?.price || product?.price?.price <= 0 + } > Beli @@ -595,6 +605,7 @@ const ProductDesktopVariant = ({ color={'red'} colorScheme='white' className='w-full border-2 p-2 gap-1 mt-2 hover:bg-slate-100 flex items-center' + isDisabled={!product?.price?.price || product?.price?.price <= 0} > + {/* Watermark jika produk nonaktif */} + {/* {(!product?.price?.price || product?.price?.price <= 0) && ( +
+ + NONAKTIF + +
+ )} */}
{product.name} diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index 4cfc63ca..e6c2204b 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -183,10 +183,20 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { return ( - {/* PRICE & ACTIONS: tetap punyamu, hanya hapus input number lama */} - {/* ===== BAR BAWAH (fixed) ===== */} +
+ {!product.price.price > 0 && ( +
+ Produk tidak tersedia +
+ )} +
+ {/* ===== BAR BAWAH ===== */}
- {/* HARGA & PPN (logikamu tetap) */} + {/* HARGA & PPN */} {activeVariant.isFlashSale && activeVariant?.price?.discountPercentage > 0 ? ( <> @@ -220,80 +230,65 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { )}
- ) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - - )} + ) : null}
)} - {/* ⬇️ TAMBAHKAN BLOK INI DI DALAM BAR: STOK & STEPPER */}
-
-
- {/* Stock : {activeVariant?.stock ?? 0} */} - Stock : {fakeStock}{' '} -
- {qtyPickUp > 0 && ( -
- * {qtyPickUp} barang bisa di pickup + {product?.price?.price > 0 && ( +
+
+ {/* Stock : {activeVariant?.stock ?? 0} */} + Stock : {fakeStock}{' '}
- )} -
+ {qtyPickUp > 0 && ( +
+ * {qtyPickUp} barang bisa di pickup +
+ )} +
+ )}
-
- - setQuantityInput(e.target.value)} - className='h-10 w-16 text-center text-lg outline-none border-x + {product?.price?.price > 0 && ( +
+ + setQuantityInput(e.target.value)} + className='h-10 w-16 text-center text-lg outline-none border-x [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none' - /> - -
+ /> + +
+ )}
@@ -306,6 +301,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { className='flex items-center justify-center p-2 border-2 hover:bg-slate-100' variant='outline' title='Lihat Dokumen' + isDisabled={product?.price?.price <= 0} > { className='flex-1' colorScheme='red' variant='outline' - isDisabled={product.stock === 0} + isDisabled={product?.price?.price <= 0} > Keranjang @@ -333,7 +329,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { } className='flex-1' colorScheme='red' - isDisabled={product.stock === 0} + isDisabled={product?.price?.price <= 0} > Beli @@ -396,87 +392,92 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { active={informationTab == 'specification'} className='rounded border border-gray_r-6 divide-y divide-gray_r-6' > - - - {isLoadingSLA ? ( - - ) : product?.sla?.slaDate != '-' ? ( -
-
- -
- - ) : ( - '-' - )} - - + {product?.sla?.slaDate} +
+
+ +
+ + ) : ( + '-' + )} + + + )} + SKU-{product?.id} {activeVariant?.code || '-'} - - {activeVariant?.stock > 0 && ( - -
Ready Stock
-
- {activeVariant?.stock > 5 ? '> 5' : '< 5'} -
-
- )} - {activeVariant?.stock == 0 && ( - - Tanya Stok - - )} -
+ {product?.price?.price > 0 && ( + + {activeVariant?.stock > 0 && ( + +
Ready Stock
+
+ {activeVariant?.stock > 5 ? '> 5' : '< 5'} +
+
+ )} + {activeVariant?.stock == 0 && ( + + Tanya Stok + + )} +
+ )} - {activeVariant?.weight > 0 && ( + {activeVariant?.weight > -1 && ( {activeVariant?.weight} KG )} - {activeVariant?.weight == 0 && ( + {activeVariant?.weight == -1 && ( { true ), })} - className='text-danger-500 font-medium' + className={`text-danger-501 font-medium ${ + !product?.price?.price || product?.price?.price <= 0 + ? 'pointer-events-none opacity-50 cursor-default' + : '' + }`} > Tanya Berat -- cgit v1.2.3