diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-09-15 01:41:26 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-09-15 01:41:26 +0000 |
| commit | edb2eda7b2cc4115e3d9f90a4ff9721454b1c8a9 (patch) | |
| tree | c6c045bb69e7651e048542491aa57d8d6be5f2b5 /src/lib/product/components/Product/ProductMobile.jsx | |
| parent | 4adc8375819bc84e71cd956f262160f4d0079431 (diff) | |
| parent | cf8daf7dd3a66084dfafdde1d9bf9d0d94fe42a7 (diff) | |
Merged in CR/migrasi_product_detail_to_solr (pull request #65)
CR/migrasi product detail to solr
Diffstat (limited to 'src/lib/product/components/Product/ProductMobile.jsx')
| -rw-r--r-- | src/lib/product/components/Product/ProductMobile.jsx | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index 56f20aac..6b0b27a5 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -83,35 +83,6 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { }) useEffect(() => { - const fetchData = async () => { - const promises = product.variants.map(async (variant) => { - const dataSLA = await odooApi('GET', `/api/v1/product_variant/${variant.id}/stock`) - return { - ...variant, - sla: dataSLA - } - }) - const variantData = await Promise.all(promises) - product.variants = variantData - - setIsLoadingSLA(false) - if (product.variants.length === 1) { - setActiveVariant({ - id: product.variants[0].id, - code: product.variants[0].code, - name: product.variants[0].parent.name, - price: product.variants[0].price, - stock: product.variants[0].stock, - weight: product.variants[0].weight, - sla: product.variants[0].sla, - hasProgram: product.variants[0].hasProgram - }) - } - } - fetchData() - }, [product]) - - useEffect(() => { if (!selectedVariant && variantOptions.length == 1) { setSelectedVariant(variantOptions[0]) } @@ -123,16 +94,23 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { const variantAttributes = variant.attributes.length > 0 ? ' - ' + variant.attributes.join(', ') : '' - setActiveVariant({ + const newActiveVariant = { id: variant.id, code: variant.code, name: variant.parent.name + variantAttributes, price: variant.price, stock: variant.stock, weight: variant.weight, - sla: variant.sla, hasProgram: variant.hasProgram - }) + } + + setActiveVariant(newActiveVariant) + + const fetchSLA = async () => { + const dataSLA = await odooApi('GET', `/api/v1/product_variant/${variant.id}/stock`) + setActiveVariant({ ...newActiveVariant, sla: dataSLA }) + } + fetchSLA() } }, [selectedVariant, product]) @@ -208,7 +186,9 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { height={10} /> <span className='text-white text-lg font-semibold'> - {product.flashSale.tag || 'FLASH SALE'} + {product?.flashSale?.tag != 'false' || product?.flashSale?.tag + ? product?.flashSale?.tag + : 'FLASH SALE'} </span> </div> <div> @@ -353,12 +333,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { > <SpecificationContent label='Ketersediaan'> <span> - {isLoadingSLA ? ( - <Button color='gray'> - <Spinner aria-label='Alternate spinner button example' /> - <span className='pl-3'>Loading...</span> - </Button> - ) : selectedVariant ? ( + {selectedVariant ? ( activeVariant?.sla?.slaDate != '-' ? ( <button type='button' @@ -410,13 +385,13 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { <span>{activeVariant?.code || '-'}</span> </SpecificationContent> <SpecificationContent label='Stok'> - {activeVariant?.stock > 0 && ( + {activeVariant?.sla?.qty > 0 && ( <span className='flex gap-x-1.5'> <div className='badge-solid-red'>Ready Stock</div> - <div className='badge-gray'>{activeVariant?.stock > 5 ? '> 5' : '< 5'}</div> + <div className='badge-gray'>{activeVariant?.sla?.qty}</div> </span> )} - {activeVariant?.stock == 0 && ( + {activeVariant?.sla?.qty == 0 && ( <a href={whatsappUrl('product', { name: product.name, |
