From ff972e0c46c81a38cddac2368000d3fc92756235 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 12 Sep 2023 10:44:19 +0700
Subject: bugs fix if flashsale tag false

---
 src/lib/product/components/Product/ProductMobile.jsx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src/lib/product/components/Product/ProductMobile.jsx')

diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx
index 56f20aac..9c0630a6 100644
--- a/src/lib/product/components/Product/ProductMobile.jsx
+++ b/src/lib/product/components/Product/ProductMobile.jsx
@@ -208,7 +208,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>
-- 
cgit v1.2.3


From 8bb683d2c695f0df292f6a7965efcbf3abd72a3d Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 13 Sep 2023 11:04:52 +0700
Subject: Add lazy load on stock product

---
 .../product/components/Product/ProductMobile.jsx   | 55 ++++++----------------
 1 file changed, 14 insertions(+), 41 deletions(-)

(limited to 'src/lib/product/components/Product/ProductMobile.jsx')

diff --git a/src/lib/product/components/Product/ProductMobile.jsx b/src/lib/product/components/Product/ProductMobile.jsx
index 9c0630a6..6b0b27a5 100644
--- a/src/lib/product/components/Product/ProductMobile.jsx
+++ b/src/lib/product/components/Product/ProductMobile.jsx
@@ -82,35 +82,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])
 
@@ -355,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'
@@ -412,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,
-- 
cgit v1.2.3

