From 702f43a7190d65c2370e7019311cc26c2cc0eafd Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 6 Jun 2023 17:01:23 +0700
Subject: program promotion

---
 .../product/components/Product/ProductDesktop.jsx  | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 75b37b9d..c3addbb9 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -14,6 +14,7 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
 import ProductCard from '../ProductCard'
 import productSimilarApi from '../../api/productSimilarApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
+import PromotionType from '@/lib/promotinProgram/components/PromotionType'
 
 const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const router = useRouter()
@@ -21,6 +22,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const [lowestPrice, setLowestPrice] = useState(null)
 
   const [addCartAlert, setAddCartAlert] = useState(false)
+  const [promotionType, setPromotionType] = useState(false)
 
   const getLowestPrice = useCallback(() => {
     const prices = product.variants.map((variant) => variant.price)
@@ -156,6 +158,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                     )}
                   </div>
                 </div>
+                <div className='pt-3'>
+                  <div className='text-h-lg font-semibold'>Promotion Program</div>
+                  <div className='flex mt-3'>
+                    <PromotionType></PromotionType>
+                  </div>
+                </div>
               </div>
             </div>
 
@@ -229,6 +237,16 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 </span>
               )}
             </h3>
+            <div className='mt-5'>
+              <button
+                type='button'
+                onClick={() => setPromotionType(true)}
+                className='text-gray-900 flex items-center justify-center rounded-lg bg-white border font-medium border-gray-300  hover:bg-gray-100 py-2.5 h-[50px] w-[100%]'
+              >
+                <span className='text-left'>%</span>
+                <span className='text-left ml-5'>Makin Hemat Pakai Promo </span>
+              </button>
+            </div>
             {product.variants.length > 1 ? (
               <button
                 type='button'
@@ -402,6 +420,16 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
             </LazyLoad>
           </div>
         </BottomPopup>
+        <BottomPopup
+          className='!w-[32%]'
+          title='Pakai Promo'
+          active={promotionType}
+          close={() => setPromotionType(false)}
+        >
+          <div className='flex mt-4'>
+            <PromotionType></PromotionType>
+          </div>
+        </BottomPopup>
       </div>
     </DesktopView>
   )
-- 
cgit v1.2.3


From eb4ae7be05ed97bd02b7f3e9cc56393f435188e2 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 14 Jun 2023 13:22:20 +0700
Subject: layout promotion program di detail product dan layout modal popup

---
 .../product/components/Product/ProductDesktop.jsx  | 24 +++++++++-------------
 1 file changed, 10 insertions(+), 14 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index c3addbb9..f1a001a6 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -15,9 +15,12 @@ import ProductCard from '../ProductCard'
 import productSimilarApi from '../../api/productSimilarApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import PromotionType from '@/lib/promotinProgram/components/PromotionType'
+import useAuth from '@/core/hooks/useAuth'
 
 const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const router = useRouter()
+  const auth = useAuth()
+  const { slug } = router.query
 
   const [lowestPrice, setLowestPrice] = useState(null)
 
@@ -55,6 +58,10 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   }
 
   const handleAddToCart = (variantId) => {
+    if(!auth) {
+      router.push(`/login?next=/shop/product/${slug}`)
+      return
+    }
     const quantity = variantQuantityRefs.current[variantId].value
     if (!validQuantity(quantity)) return
     updateItemCart({
@@ -159,8 +166,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                   </div>
                 </div>
                 <div className='pt-3'>
-                  <div className='text-h-lg font-semibold'>Promotion Program</div>
-                  <div className='flex mt-3'>
+                  <div className='flex mt-1'>
                     <PromotionType></PromotionType>
                   </div>
                 </div>
@@ -237,7 +243,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 </span>
               )}
             </h3>
-            <div className='mt-5'>
+            {/* <div className='mt-5'>
               <button
                 type='button'
                 onClick={() => setPromotionType(true)}
@@ -246,7 +252,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 <span className='text-left'>%</span>
                 <span className='text-left ml-5'>Makin Hemat Pakai Promo </span>
               </button>
-            </div>
+            </div> */}
             {product.variants.length > 1 ? (
               <button
                 type='button'
@@ -420,16 +426,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
             </LazyLoad>
           </div>
         </BottomPopup>
-        <BottomPopup
-          className='!w-[32%]'
-          title='Pakai Promo'
-          active={promotionType}
-          close={() => setPromotionType(false)}
-        >
-          <div className='flex mt-4'>
-            <PromotionType></PromotionType>
-          </div>
-        </BottomPopup>
       </div>
     </DesktopView>
   )
-- 
cgit v1.2.3


From 637c22f1886cecf7307ced88dc951134d466a3fa Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 19 Jun 2023 15:46:03 +0700
Subject: checkout

---
 .../product/components/Product/ProductDesktop.jsx  | 47 ++++++++++++++++++----
 1 file changed, 40 insertions(+), 7 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index f1a001a6..d9c95327 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -1,4 +1,5 @@
 import Image from '@/core/components/elements/Image/Image'
+import ImageNext from 'next/image'
 import Link from '@/core/components/elements/Link/Link'
 import DesktopView from '@/core/components/views/DesktopView'
 import currencyFormat from '@/core/utils/currencyFormat'
@@ -58,7 +59,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   }
 
   const handleAddToCart = (variantId) => {
-    if(!auth) {
+    if (!auth) {
       router.push(`/login?next=/shop/product/${slug}`)
       return
     }
@@ -165,11 +166,13 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                     )}
                   </div>
                 </div>
-                <div className='pt-3'>
-                  <div className='flex mt-1'>
-                    <PromotionType></PromotionType>
+                {product.variants.length <= 1 && (
+                  <div className='pt-3'>
+                    <div className='flex mt-1'>
+                      <PromotionType></PromotionType>
+                    </div>
                   </div>
-                </div>
+                )}
               </div>
             </div>
 
@@ -328,7 +331,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                   </tr>
                 </thead>
                 <tbody>
-                  {product.variants.map((variant) => (
+                  {product.variants.map((variant, index) => (
                     <tr key={variant.id}>
                       <td>{variant.code}</td>
                       <td>{variant.attributes.join(', ') || '-'}</td>
@@ -367,6 +370,27 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                         />
                       </td>
                       <td className='flex gap-x-3'>
+                        {index == 0 ? (
+                          <ImageNext
+                            src='/images/noun-applied-check2.svg'
+                            alt=''
+                            height={60}
+                            width={60}
+                            onClick={() => setPromotionType(true)}
+                            className='cursor-pointer'
+                          ></ImageNext>
+                        ) : (
+                          <div className='w-[60px] flex justify-center'>
+                            <ImageNext
+                              src='/images/noun-discount-5796402.svg'
+                              alt=''
+                              height={30}
+                              width={30}
+                              onClick={() => setPromotionType(true)}
+                              className='cursor-pointer'
+                            ></ImageNext>
+                          </div>
+                        )}
                         <button
                           type='button'
                           onClick={() => handleAddToCart(variant.id)}
@@ -396,7 +420,16 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
             <ProductSimilar query={productSimilarQuery} />
           </LazyLoad>
         </div>
-
+        <BottomPopup
+          className=' !h-[75%]'
+          title='Pakai Promo'
+          active={promotionType}
+          close={() => setPromotionType(false)}
+        >
+          <div className='flex mt-4'>
+            <PromotionType isModal={true}></PromotionType>
+          </div>
+        </BottomPopup>
         <BottomPopup
           className='!container'
           title='Berhasil Ditambahkan'
-- 
cgit v1.2.3


From 62c6c84dfae2564e92e2b3228c67d2fb12f5c3e5 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 22 Jun 2023 15:08:05 +0700
Subject: get promotion progrm

---
 src/lib/product/components/Product/ProductDesktop.jsx | 13 +++++++++++++
 1 file changed, 13 insertions(+)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index d9c95327..c1243a50 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -17,6 +17,7 @@ import productSimilarApi from '../../api/productSimilarApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import PromotionType from '@/lib/promotinProgram/components/PromotionType'
 import useAuth from '@/core/hooks/useAuth'
+import odooApi from '@/core/api/odooApi'
 
 const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const router = useRouter()
@@ -36,6 +37,13 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     return lowest
   }, [product])
 
+  useEffect(() => {
+    if(product.variants.length > 1){
+      const listProgram = getPromotionProgram(product.variants[0].id)
+      console.log('promotion list', listProgram)
+    }
+  },[product])
+
   useEffect(() => {
     const lowest = getLowestPrice()
     setLowestPrice(lowest)
@@ -486,4 +494,9 @@ const TabContent = ({ children, active, className = '', ...props }) => (
   </div>
 )
 
+const getPromotionProgram = async ({id}) => {
+  const listProgram = await odooApi('GET', `/api/v1/product_variant/${id}/promotions`)
+
+  return listProgram
+}
 export default ProductDesktop
-- 
cgit v1.2.3


From 592bb7f73a93f07db26efb985518505e0958c5f0 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 22 Jun 2023 15:34:40 +0700
Subject: get program list

---
 src/lib/product/components/Product/ProductDesktop.jsx | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index c1243a50..9fa5412d 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -28,6 +28,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
 
   const [addCartAlert, setAddCartAlert] = useState(false)
   const [promotionType, setPromotionType] = useState(false)
+  const [promotionList, setPromotionList] = useState(null)
 
   const getLowestPrice = useCallback(() => {
     const prices = product.variants.map((variant) => variant.price)
@@ -38,11 +39,15 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   }, [product])
 
   useEffect(() => {
-    if(product.variants.length > 1){
-      const listProgram = getPromotionProgram(product.variants[0].id)
-      console.log('promotion list', listProgram)
+    if(product.variants.length == 1){
+      const id = product.variants[0].id
+      const listProgram  = async () => {
+        const programs = await getPromotionProgram({id})
+        setPromotionList(programs)
+      } 
+      listProgram()
     }
-  },[product])
+  },[])
 
   useEffect(() => {
     const lowest = getLowestPrice()
-- 
cgit v1.2.3


From 88be517479704ee6b40334e0cabcfc86b824419b Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 23 Jun 2023 09:00:49 +0700
Subject: log

---
 src/lib/product/components/Product/ProductDesktop.jsx | 1 +
 1 file changed, 1 insertion(+)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 9fa5412d..25b12911 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -44,6 +44,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
       const listProgram  = async () => {
         const programs = await getPromotionProgram({id})
         setPromotionList(programs)
+        console.log('list program', promotionList)
       } 
       listProgram()
     }
-- 
cgit v1.2.3


From 84ae09f61f05f212ec098da1fd4ed14960119527 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 27 Jun 2023 09:07:22 +0700
Subject: promotion detail

---
 .../product/components/Product/ProductDesktop.jsx  | 48 ++++++++--------------
 1 file changed, 16 insertions(+), 32 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 25b12911..507d676c 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -28,7 +28,8 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
 
   const [addCartAlert, setAddCartAlert] = useState(false)
   const [promotionType, setPromotionType] = useState(false)
-  const [promotionList, setPromotionList] = useState(null)
+  const [promotionActiveId, setPromotionActiveId] = useState(null)
+  const [quantity, setQuantity] = useState(null)
 
   const getLowestPrice = useCallback(() => {
     const prices = product.variants.map((variant) => variant.price)
@@ -38,18 +39,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     return lowest
   }, [product])
 
-  useEffect(() => {
-    if(product.variants.length == 1){
-      const id = product.variants[0].id
-      const listProgram  = async () => {
-        const programs = await getPromotionProgram({id})
-        setPromotionList(programs)
-        console.log('list program', promotionList)
-      } 
-      listProgram()
-    }
-  },[])
-
   useEffect(() => {
     const lowest = getLowestPrice()
     setLowestPrice(lowest)
@@ -60,6 +49,9 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const variantQuantityRefs = useRef([])
 
   const setVariantQuantityRef = (variantId) => (element) => {
+    if (element) {
+      setQuantity(element.value)
+    }
     variantQuantityRefs.current[variantId] = element
   }
 
@@ -82,6 +74,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     updateItemCart({
       productId: variantId,
       quantity,
+      programLineId:promotionActiveId,
       selected: true
     })
     setAddCartAlert(true)
@@ -183,7 +176,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 {product.variants.length <= 1 && (
                   <div className='pt-3'>
                     <div className='flex mt-1'>
-                      <PromotionType></PromotionType>
+                      <PromotionType
+                        variantId={product.variants[0].id}
+                        setPromotionActiveId={setPromotionActiveId}
+                        promotionActiveId={promotionActiveId}
+                        quantity={quantity}
+                      ></PromotionType>
                     </div>
                   </div>
                 )}
@@ -260,16 +258,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 </span>
               )}
             </h3>
-            {/* <div className='mt-5'>
-              <button
-                type='button'
-                onClick={() => setPromotionType(true)}
-                className='text-gray-900 flex items-center justify-center rounded-lg bg-white border font-medium border-gray-300  hover:bg-gray-100 py-2.5 h-[50px] w-[100%]'
-              >
-                <span className='text-left'>%</span>
-                <span className='text-left ml-5'>Makin Hemat Pakai Promo </span>
-              </button>
-            </div> */}
             {product.variants.length > 1 ? (
               <button
                 type='button'
@@ -284,6 +272,7 @@ const ProductDesktop = ({ product, 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)}
                   defaultValue={1}
                 />
                 <button
@@ -434,16 +423,16 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
             <ProductSimilar query={productSimilarQuery} />
           </LazyLoad>
         </div>
-        <BottomPopup
+        {/* <BottomPopup
           className=' !h-[75%]'
           title='Pakai Promo'
           active={promotionType}
           close={() => setPromotionType(false)}
         >
           <div className='flex mt-4'>
-            <PromotionType isModal={true}></PromotionType>
+            <PromotionType isModal={true} ></PromotionType>
           </div>
-        </BottomPopup>
+        </BottomPopup> */}
         <BottomPopup
           className='!container'
           title='Berhasil Ditambahkan'
@@ -500,9 +489,4 @@ const TabContent = ({ children, active, className = '', ...props }) => (
   </div>
 )
 
-const getPromotionProgram = async ({id}) => {
-  const listProgram = await odooApi('GET', `/api/v1/product_variant/${id}/promotions`)
-
-  return listProgram
-}
 export default ProductDesktop
-- 
cgit v1.2.3


From 927022b91855dba6d64365b68b4d20551256e7db Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 27 Jun 2023 16:47:16 +0700
Subject: product detail mobile & cart

---
 src/lib/product/components/Product/ProductDesktop.jsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 507d676c..d15e84d1 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -423,7 +423,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
             <ProductSimilar query={productSimilarQuery} />
           </LazyLoad>
         </div>
-        {/* <BottomPopup
+        <BottomPopup
           className=' !h-[75%]'
           title='Pakai Promo'
           active={promotionType}
@@ -432,7 +432,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
           <div className='flex mt-4'>
             <PromotionType isModal={true} ></PromotionType>
           </div>
-        </BottomPopup> */}
+        </BottomPopup>
         <BottomPopup
           className='!container'
           title='Berhasil Ditambahkan'
-- 
cgit v1.2.3


From cb69cf4e6633bb9192cd7bdc0a0063541f67102f Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 5 Jul 2023 17:01:24 +0700
Subject: promotion program cart dan variant

---
 .../product/components/Product/ProductDesktop.jsx  | 73 +++++++++++++++++-----
 1 file changed, 56 insertions(+), 17 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index d15e84d1..946529ce 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -19,17 +19,19 @@ import PromotionType from '@/lib/promotinProgram/components/PromotionType'
 import useAuth from '@/core/hooks/useAuth'
 import odooApi from '@/core/api/odooApi'
 
-const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
+const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
   const router = useRouter()
   const auth = useAuth()
   const { slug } = router.query
 
+  const [quantityActive, setQuantity] = useState(null)
   const [lowestPrice, setLowestPrice] = useState(null)
+  const [product, setProducts] = useState(products)
 
   const [addCartAlert, setAddCartAlert] = useState(false)
   const [promotionType, setPromotionType] = useState(false)
   const [promotionActiveId, setPromotionActiveId] = useState(null)
-  const [quantity, setQuantity] = useState(null)
+  const [selectVariantPromoActive, setSelectVariantPromoActive] = useState(null)
 
   const getLowestPrice = useCallback(() => {
     const prices = product.variants.map((variant) => variant.price)
@@ -50,11 +52,13 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
 
   const setVariantQuantityRef = (variantId) => (element) => {
     if (element) {
-      setQuantity(element.value)
+      let variantIndex = product.variants.findIndex((varian) => varian.id == variantId)
+      product.variants[variantIndex].quantity = element.value
     }
     variantQuantityRefs.current[variantId] = element
   }
 
+
   const validQuantity = (quantity) => {
     let isValid = true
     if (!quantity || quantity < 1 || isNaN(parseInt(quantity))) {
@@ -70,13 +74,25 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
       return
     }
     const quantity = variantQuantityRefs.current[variantId].value
+
     if (!validQuantity(quantity)) return
-    updateItemCart({
-      productId: variantId,
-      quantity,
-      programLineId:promotionActiveId,
-      selected: true
-    })
+    if(product.variants.length > 1){
+      let variantIndex = product.variants.findIndex((varian) => varian.id == variantId)
+      updateItemCart({
+        productId: variantId,
+        quantity,
+        programLineId: product.variants[variantIndex].programActive,
+        selected: true
+      })
+    }{
+      updateItemCart({
+        productId: variantId,
+        quantity,
+        programLineId: promotionActiveId,
+        selected: true
+      })
+    }
+   
     setAddCartAlert(true)
   }
 
@@ -97,6 +113,11 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     }
   }
 
+  const handlePromoClick = (variantId) => {
+    setSelectVariantPromoActive(variantId)
+    setPromotionType(true)
+  }
+
   const productSimilarQuery = [
     product?.name,
     `fq=-product_id_i:${product.id}`,
@@ -180,7 +201,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                         variantId={product.variants[0].id}
                         setPromotionActiveId={setPromotionActiveId}
                         promotionActiveId={promotionActiveId}
-                        quantity={quantity}
+                        quantity={quantityActive}
                       ></PromotionType>
                     </div>
                   </div>
@@ -369,30 +390,40 @@ const ProductDesktop = ({ product, 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)}
                           defaultValue={1}
                         />
                       </td>
                       <td className='flex gap-x-3'>
-                        {index == 0 ? (
+                        {variant.programActive ? (
                           <ImageNext
                             src='/images/noun-applied-check2.svg'
                             alt=''
                             height={60}
                             width={60}
-                            onClick={() => setPromotionType(true)}
+                            onClick={() => handlePromoClick(variant.id)}
                             className='cursor-pointer'
                           ></ImageNext>
                         ) : (
-                          <div className='w-[60px] flex justify-center'>
+                          variant.hasProgram ? ( <div className='w-[60px] flex justify-center'>
+                          <ImageNext
+                            src='/images/noun-discount-5796402.svg'
+                            alt=''
+                            height={30}
+                            width={30}
+                            onClick={() => handlePromoClick(variant.id)}
+                            className='cursor-pointer'
+                          ></ImageNext>
+                        </div>):( <div className='w-[60px] flex justify-center'>
                             <ImageNext
-                              src='/images/noun-discount-5796402.svg'
+                              src='/images/noun-discount-57964023.svg'
                               alt=''
                               height={30}
                               width={30}
-                              onClick={() => setPromotionType(true)}
                               className='cursor-pointer'
                             ></ImageNext>
-                          </div>
+                          </div>)
+                         
                         )}
                         <button
                           type='button'
@@ -430,7 +461,15 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
           close={() => setPromotionType(false)}
         >
           <div className='flex mt-4'>
-            <PromotionType isModal={true} ></PromotionType>
+            <PromotionType
+              isModal={true}
+              variantId={selectVariantPromoActive}
+              setPromotionActiveId={setPromotionActiveId}
+              promotionActiveId={promotionActiveId}
+              quantity={quantityActive}
+              product={product}
+              setProducts={setProducts}
+            ></PromotionType>
           </div>
         </BottomPopup>
         <BottomPopup
-- 
cgit v1.2.3


From ead27f576ea73bb4625fea839ee78c4a8db0d4e9 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 6 Jul 2023 10:21:50 +0700
Subject: variant page

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

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 946529ce..e15ea252 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -84,7 +84,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
         programLineId: product.variants[variantIndex].programActive,
         selected: true
       })
-    }{
+    }else{
       updateItemCart({
         productId: variantId,
         quantity,
@@ -202,6 +202,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
                         setPromotionActiveId={setPromotionActiveId}
                         promotionActiveId={promotionActiveId}
                         quantity={quantityActive}
+                        product={product}
                       ></PromotionType>
                     </div>
                   </div>
-- 
cgit v1.2.3


From 3f890e6d482cefba37014e021cb4c2b8d5de2a9d Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 12 Jul 2023 14:31:07 +0700
Subject: cr

---
 src/lib/product/components/Product/ProductDesktop.jsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 6a87d022..cafab721 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -66,9 +66,9 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   }
 
   const handleBuy = (variant) => {
-    const quantity = variantQuantityRefs.current[variant.id].value
+    const quantity = variantQuantityRefs.current[variant].value
     if (!validQuantity(quantity)) return
-    router.push(`/shop/checkout?productId=${variant.id}&quantity=${quantity}`)
+    router.push(`/shop/checkout?productId=${variant}&quantity=${quantity}`)
   }
 
   const variantSectionRef = useRef(null)
-- 
cgit v1.2.3


From b886fcf2dbc9114bc2e2347e3d4bf5299ed43d3b Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 14 Jul 2023 09:26:08 +0700
Subject: toggle on off

---
 src/lib/product/components/Product/ProductDesktop.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index cafab721..037b8c66 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -256,7 +256,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 </button>
                 <button
                   type='button'
-                  onClick={() => handleBuy(product.variants[0])}
+                  onClick={() => handleBuy(product.variants[0].id)}
                   className='flex-1 py-2 btn-solid-red'
                 >
                   Beli
-- 
cgit v1.2.3


From c210cdc221db85f6711af92442808e15fc2eb10e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 20 Jul 2023 16:41:30 +0700
Subject: voucher get perhitungan dari api

---
 src/lib/product/components/Product/ProductDesktop.jsx | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

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

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 4e746877..4a1590ba 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -15,13 +15,8 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
 import ProductCard from '../ProductCard'
 import productSimilarApi from '../../api/productSimilarApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
-<<<<<<< HEAD
 import PromotionType from '@/lib/promotinProgram/components/PromotionType'
 import useAuth from '@/core/hooks/useAuth'
-import odooApi from '@/core/api/odooApi'
-=======
-import { gtagAddToCart } from '@/core/utils/googleTag'
->>>>>>> Feature/voucher
 
 const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
   const router = useRouter()
@@ -303,7 +298,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
                 />
                 <button
                   type='button'
-                  onClick={() => handleAddToCart(product.variants[0])}
+                  onClick={() => handleAddToCart(product.variants[0].id)}
                   className='flex-1 py-2 btn-yellow'
                 >
                   Keranjang
@@ -400,7 +395,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
                         />
                       </td>
                       <td className='flex gap-x-3'>
-                        {variant.programActive ? (
+                        {/* {variant.programActive ? (
                           <ImageNext
                             src='/images/noun-applied-check2.svg'
                             alt=''
@@ -429,7 +424,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
                             ></ImageNext>
                           </div>)
                          
-                        )}
+                        )} */}
                         <button
                           type='button'
                           onClick={() => handleAddToCart(variant)}
-- 
cgit v1.2.3

