diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-25 16:40:59 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-25 16:40:59 +0700 |
| commit | dc5e9f0f6a1b3fd2211f6daf87c055abe47f0023 (patch) | |
| tree | 9e4773f266d67528ac4c8e840ca7ebe21c03967f /src/lib | |
| parent | 915443e3f3a7dcf567fbf5a1dff7c6d6647d11b5 (diff) | |
default activevariant
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/product/components/Product/ProductMobile.jsx | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx index 46a6af75..3f13f980 100644 --- a/src/lib/product/components/Product/ProductMobile.jsx +++ b/src/lib/product/components/Product/ProductMobile.jsx @@ -57,6 +57,35 @@ 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]) } @@ -79,6 +108,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { hasProgram: variant.hasProgram }) } + console.log('ini adalah active', activeVariant) }, [selectedVariant, product]) const validAction = () => { @@ -111,23 +141,6 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { router.push(`/shop/checkout?productId=${activeVariant.id}&quantity=${quantity}`) } - 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) - } - fetchData() - }, [product]) - const productSimilarQuery = [ product?.name, `fq=-product_id_i:${product.id}`, @@ -274,7 +287,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { <Spinner aria-label='Alternate spinner button example' /> <span className='pl-3'>Loading...</span> </Button> - ) : activeVariant?.sla?.slaDate != '-' ? ( + ) : selectedVariant ? activeVariant?.sla?.slaDate != '-' ? ( <button type='button' title={`Masa Persiapan Barang ${activeVariant?.sla?.slaDate}`} @@ -307,7 +320,7 @@ const ProductMobile = ({ product, wishlist, toggleWishlist }) => { </svg> </div> </button> - ) : ( + ):('-') : ( '-' )} </span> |
