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

---
 src/lib/cart/components/Cart.jsx | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 907d1267..718541af 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -17,10 +17,16 @@ import DesktopView from '@/core/components/views/DesktopView'
 import ProductCard from '@/lib/product/components/ProductCard'
 import productSearchApi from '@/lib/product/api/productSearchApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
+import useAuth from '@/core/hooks/useAuth'
 
 const Cart = () => {
   const router = useRouter()
   const [products, setProducts] = useState(null)
+  const auth = useAuth()
+
+  useEffect(() => {
+    if (!auth) return
+  }, [auth])
   const { cart } = useCart({ enabled: !products })
 
   const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0)
-- 
cgit v1.2.3


From e4b4f2c09ebd819acc204c2e58288fe9fc6294ea Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Thu, 15 Jun 2023 15:45:43 +0700
Subject: get dan delete cart

---
 src/lib/cart/components/Cart.jsx | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 718541af..561a0064 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -4,7 +4,7 @@ import Image from '@/core/components/elements/Image/Image'
 import NextImage from 'next/image'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { useEffect, useState } from 'react'
-import { deleteItemCart, getItemCart, updateItemCart } from '@/core/utils/cart'
+import { deleteItemCart, getCart, getCartnew, getItemCart, updateItemCart } from '@/core/utils/cart'
 import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline'
 import { createSlug } from '@/core/utils/slug'
 import { useRouter } from 'next/router'
@@ -19,14 +19,27 @@ import productSearchApi from '@/lib/product/api/productSearchApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import useAuth from '@/core/hooks/useAuth'
 
+
+const { useQuery } = require('react-query')
+const { getCartApi } = require('../api/CartApi')
+
 const Cart = () => {
   const router = useRouter()
   const [products, setProducts] = useState(null)
   const auth = useAuth()
+  const { data: listCart } = useQuery('listCart', getCartApi)
 
   useEffect(() => {
     if (!auth) return
   }, [auth])
+
+  useEffect(() => {
+    if(listCart){
+      setProducts(listCart.products)
+    }
+  }, [listCart])
+
+  console.log('product', products)
   const { cart } = useCart({ enabled: !products })
 
   const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0)
-- 
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

---
 src/lib/cart/components/Cart.jsx | 66 ++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 36 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 561a0064..31aa034d 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -4,7 +4,7 @@ import Image from '@/core/components/elements/Image/Image'
 import NextImage from 'next/image'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { useEffect, useState } from 'react'
-import { deleteItemCart, getCart, getCartnew, getItemCart, updateItemCart } from '@/core/utils/cart'
+import { addCart, deleteItemCart, getCart, getCartApi, getCartnew, getItemCart, updateItemCart } from '@/core/utils/cart'
 import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline'
 import { createSlug } from '@/core/utils/slug'
 import { useRouter } from 'next/router'
@@ -19,28 +19,34 @@ import productSearchApi from '@/lib/product/api/productSearchApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import useAuth from '@/core/hooks/useAuth'
 
-
-const { useQuery } = require('react-query')
-const { getCartApi } = require('../api/CartApi')
-
 const Cart = () => {
   const router = useRouter()
   const [products, setProducts] = useState(null)
+  const [isLoading, setIsLoading] = useState(true)
   const auth = useAuth()
-  const { data: listCart } = useQuery('listCart', getCartApi)
+
+
+  const [cart, setCart]  = useState(null)
 
   useEffect(() => {
     if (!auth) return
   }, [auth])
 
   useEffect(() => {
-    if(listCart){
-      setProducts(listCart.products)
+    const cart = async () => {
+      const listCart = await getCartApi()
+      setCart(listCart)
     }
-  }, [listCart])
+    cart()
+  })
+
+  useEffect(() => {
+    if(cart){
+      setProducts(cart.products)
+      setIsLoading(false)
+    }
+  }, [cart])
 
-  console.log('product', products)
-  const { cart } = useCart({ enabled: !products })
 
   const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0)
   const [totalTaxAmount, setTotalTaxAmount] = useState(0)
@@ -50,20 +56,6 @@ const Cart = () => {
 
   const [productRecomendation, setProductRecomendation] = useState(null)
 
-  useEffect(() => {
-    if (cart.data && !products) {
-      const productsWithQuantity = cart.data.map((product) => {
-        const productInCart = getItemCart({ productId: product.id })
-        if (!productInCart) return
-        return {
-          ...product,
-          quantity: productInCart.quantity,
-          selected: productInCart.selected
-        }
-      })
-      setProducts(productsWithQuantity)
-    }
-  }, [cart, products])
 
   useEffect(() => {
     if (!products) return
@@ -73,11 +65,6 @@ const Cart = () => {
     let calculateTotalDiscountAmount = 0
     for (const product of products) {
       if (product.quantity == '') continue
-      updateItemCart({
-        productId: product.id,
-        quantity: product.quantity,
-        selected: product.selected
-      })
 
       if (!product.selected) continue
       let priceBeforeTax = product.price.price / 1.11
@@ -127,8 +114,11 @@ const Cart = () => {
         quantity = value != '' && value < 1 ? 1 : value
         break
     }
-    productsToUpdate[productIndex].quantity = quantity
+    let qty = quantity
+    productsToUpdate[productIndex].quantity = qty
+    
     setProducts([...productsToUpdate])
+    addCart(productId, qty, productsToUpdate[productIndex].selected)
   }
 
   const toggleSelected = (productId) => {
@@ -136,8 +126,12 @@ const Cart = () => {
     if (productIndex < 0) return
 
     let productsToUpdate = products
-    productsToUpdate[productIndex].selected = !productsToUpdate[productIndex].selected
+    let isSelected = !productsToUpdate[productIndex].selected
+    productsToUpdate[productIndex].selected = isSelected
+    
+    
     setProducts([...productsToUpdate])
+    addCart(productId, productsToUpdate[productIndex].quantity, isSelected)
   }
 
   const selectedProduct = () => {
@@ -190,13 +184,13 @@ const Cart = () => {
           </div>
 
           <div className='flex flex-col gap-y-4 h-screen'>
-            {cart.isLoading && (
+            {isLoading && (
               <div className='flex justify-center my-4'>
                 <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' />
               </div>
             )}
 
-            {!cart.isLoading && (!products || products?.length == 0) && (
+            {!isLoading && (!products || products?.length == 0) && (
               <div className='px-4'>
                 <Alert className='text-center my-2' type='info'>
                   Keranjang belanja anda masih kosong
@@ -335,7 +329,7 @@ const Cart = () => {
                 </tr>
               </thead>
               <tbody>
-                {cart.isLoading && (
+                {isLoading && (
                   <tr>
                     <td colSpan={6}>
                       <div className='flex justify-center my-2'>
@@ -344,7 +338,7 @@ const Cart = () => {
                     </td>
                   </tr>
                 )}
-                {!cart.isLoading && (!products || products?.length == 0) && (
+                {!isLoading && (!products || products?.length == 0) && (
                   <tr>
                     <td colSpan={6}>Keranjang belanja anda masih kosong</td>
                   </tr>
-- 
cgit v1.2.3


From d2ac3371d30464801924539350ddb50eb42eb007 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 21 Jun 2023 13:19:30 +0700
Subject: handling cart

---
 src/lib/cart/components/Cart.jsx | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 31aa034d..a9113e75 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -4,7 +4,15 @@ import Image from '@/core/components/elements/Image/Image'
 import NextImage from 'next/image'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { useEffect, useState } from 'react'
-import { addCart, deleteItemCart, getCart, getCartApi, getCartnew, getItemCart, updateItemCart } from '@/core/utils/cart'
+import {
+  addCart,
+  deleteItemCart,
+  getCart,
+  getCartApi,
+  getCartnew,
+  getItemCart,
+  updateItemCart
+} from '@/core/utils/cart'
 import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline'
 import { createSlug } from '@/core/utils/slug'
 import { useRouter } from 'next/router'
@@ -18,6 +26,7 @@ import ProductCard from '@/lib/product/components/ProductCard'
 import productSearchApi from '@/lib/product/api/productSearchApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import useAuth from '@/core/hooks/useAuth'
+import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'
 
 const Cart = () => {
   const router = useRouter()
@@ -25,8 +34,7 @@ const Cart = () => {
   const [isLoading, setIsLoading] = useState(true)
   const auth = useAuth()
 
-
-  const [cart, setCart]  = useState(null)
+  const [cart, setCart] = useState(null)
 
   useEffect(() => {
     if (!auth) return
@@ -38,16 +46,15 @@ const Cart = () => {
       setCart(listCart)
     }
     cart()
-  })
+  },[])
 
   useEffect(() => {
-    if(cart){
+    if (cart) {
       setProducts(cart.products)
       setIsLoading(false)
     }
   }, [cart])
 
-
   const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0)
   const [totalTaxAmount, setTotalTaxAmount] = useState(0)
   const [totalDiscountAmount, setTotalDiscountAmount] = useState(0)
@@ -56,7 +63,6 @@ const Cart = () => {
 
   const [productRecomendation, setProductRecomendation] = useState(null)
 
-
   useEffect(() => {
     if (!products) return
 
@@ -116,7 +122,7 @@ const Cart = () => {
     }
     let qty = quantity
     productsToUpdate[productIndex].quantity = qty
-    
+
     setProducts([...productsToUpdate])
     addCart(productId, qty, productsToUpdate[productIndex].selected)
   }
@@ -128,8 +134,7 @@ const Cart = () => {
     let productsToUpdate = products
     let isSelected = !productsToUpdate[productIndex].selected
     productsToUpdate[productIndex].selected = isSelected
-    
-    
+
     setProducts([...productsToUpdate])
     addCart(productId, productsToUpdate[productIndex].quantity, isSelected)
   }
@@ -332,8 +337,8 @@ const Cart = () => {
                 {isLoading && (
                   <tr>
                     <td colSpan={6}>
-                      <div className='flex justify-center my-2'>
-                        <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' />
+                      <div className='container flex justify-center my-4'>
+                        <LogoSpinner width={48} height={48} />
                       </div>
                     </td>
                   </tr>
-- 
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

---
 src/lib/cart/components/Cart.jsx | 155 +++++++++++++++++++++------------------
 1 file changed, 83 insertions(+), 72 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index a9113e75..cfbc3989 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -46,7 +46,7 @@ const Cart = () => {
       setCart(listCart)
     }
     cart()
-  },[])
+  }, [])
 
   useEffect(() => {
     if (cart) {
@@ -350,89 +350,100 @@ const Cart = () => {
                 )}
                 {products &&
                   products?.map((product) => (
-                    <tr key={product.id}>
-                      <td>
-                        <input
-                          type='checkbox'
-                          onClick={() => toggleSelected(product.id)}
-                          checked={product?.selected}
-                          className='accent-danger-500 w-4'
-                        />
-                      </td>
-                      <td className='flex'>
-                        <Link
-                          href={createSlug(
-                            '/shop/product/',
-                            product?.parent.name,
-                            product?.parent.id
-                          )}
-                          className='w-[20%] flex-shrink-0'
-                        >
-                          <Image
-                            src={product?.parent?.image}
-                            alt={product?.name}
-                            className='object-contain object-center border border-gray_r-6 h-28 w-full rounded-md'
+                    <>
+                      <tr className='!border-b-0 pb-0'>
+                        <td colSpan={6}>
+                          <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
+                            <div className='flex border border-solid border-red-600 rounded-md p-1'><span className='text-red-600'>Promo</span></div>
+                            <div className='flex font-semibold'>Pilih Promo Yang Tersedia Bisa lebih Hemat</div>
+                            <div className='justify-end'>Cek Promo </div>
+                          </div>
+                        </td>
+                      </tr>
+                      <tr key={product.id} className='!border-t-0'>
+                        <td>
+                          <input
+                            type='checkbox'
+                            onClick={() => toggleSelected(product.id)}
+                            checked={product?.selected}
+                            className='accent-danger-500 w-4'
                           />
-                        </Link>
-                        <div className='px-2 text-left'>
+                        </td>
+                        <td className='flex'>
                           <Link
                             href={createSlug(
                               '/shop/product/',
                               product?.parent.name,
                               product?.parent.id
                             )}
-                            className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'
+                            className='w-[20%] flex-shrink-0'
                           >
-                            {product?.parent?.name}
+                            <Image
+                              src={product?.parent?.image}
+                              alt={product?.name}
+                              className='object-contain object-center border border-gray_r-6 h-28 w-full rounded-md'
+                            />
                           </Link>
-                          <div className='text-gray_r-11 mt-2'>
-                            {product?.code}{' '}
-                            {product?.attributes.length > 0
-                              ? `| ${product?.attributes.join(', ')}`
-                              : ''}
-                          </div>
-                        </div>
-                      </td>
-                      <td>
-                        <input
-                          className='form-input w-16 py-2 text-center bg-gray_r-1'
-                          type='number'
-                          value={product?.quantity}
-                          onChange={(e) => updateQuantity(e.target.value, product?.id)}
-                          onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')}
-                        />
-                      </td>
-                      <td>
-                        {product?.price?.discountPercentage > 0 && (
-                          <div className='flex gap-x-1 items-center justify-center mt-3'>
-                            <div className='text-gray_r-11 line-through text-caption-1'>
-                              {currencyFormat(product?.price?.price)}
+                          <div className='px-2 text-left'>
+                            <Link
+                              href={createSlug(
+                                '/shop/product/',
+                                product?.parent.name,
+                                product?.parent.id
+                              )}
+                              className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'
+                            >
+                              {product?.parent?.name}
+                            </Link>
+                            <div className='text-gray_r-11 mt-2'>
+                              {product?.code}{' '}
+                              {product?.attributes.length > 0
+                                ? `| ${product?.attributes.join(', ')}`
+                                : ''}
                             </div>
-                            <div className='badge-solid-red'>
-                              {product?.price?.discountPercentage}%
+                          </div>
+                        </td>
+                        <td>
+                          <input
+                            className='form-input w-16 py-2 text-center bg-gray_r-1'
+                            type='number'
+                            value={product?.quantity}
+                            onChange={(e) => updateQuantity(e.target.value, product?.id)}
+                            onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')}
+                          />
+                        </td>
+                        <td>
+                          {product?.price?.discountPercentage > 0 && (
+                            <div className='flex gap-x-1 items-center justify-center mt-3'>
+                              <div className='text-gray_r-11 line-through text-caption-1'>
+                                {currencyFormat(product?.price?.price)}
+                              </div>
+                              <div className='badge-solid-red'>
+                                {product?.price?.discountPercentage}%
+                              </div>
                             </div>
+                          )}
+                          <div className='font-normal mt-1'>
+                            {currencyFormat(product?.price?.priceDiscount)}
                           </div>
-                        )}
-                        <div className='font-normal mt-1'>
-                          {currencyFormat(product?.price?.priceDiscount)}
-                        </div>
-                      </td>
-                      <td>
-                        <div className='text-danger-500 font-medium'>
-                          {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
-                        </div>
-                      </td>
-                      <td>
-                        <div className='flex justify-center items-center h-full'>
-                          <button
-                            className='btn-red p-1 ml-1'
-                            onClick={() => setDeleteConfirmation(product)}
-                          >
-                            <TrashIcon className='w-4' />
-                          </button>
-                        </div>
-                      </td>
-                    </tr>
+                        </td>
+                        <td>
+                          <div className='text-danger-500 font-medium'>
+                            {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
+                          </div>
+                        </td>
+                        <td>
+                          <div className='flex justify-center items-center h-full'>
+                            <button
+                              className='btn-red p-1 ml-1'
+                              onClick={() => setDeleteConfirmation(product)}
+                            >
+                              <TrashIcon className='w-4' />
+                            </button>
+                          </div>
+                        </td>
+                      </tr>
+                    </>
                   ))}
               </tbody>
             </table>
-- 
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/cart/components/Cart.jsx | 173 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 160 insertions(+), 13 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index cfbc3989..29bbf080 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -7,10 +7,7 @@ import { useEffect, useState } from 'react'
 import {
   addCart,
   deleteItemCart,
-  getCart,
   getCartApi,
-  getCartnew,
-  getItemCart,
   updateItemCart
 } from '@/core/utils/cart'
 import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline'
@@ -27,6 +24,8 @@ import productSearchApi from '@/lib/product/api/productSearchApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
 import useAuth from '@/core/hooks/useAuth'
 import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'
+import { getPromotionProgram } from '@/lib/promotinProgram/api/homepageApi'
+import PromotionType from '@/lib/promotinProgram/components/PromotionType'
 
 const Cart = () => {
   const router = useRouter()
@@ -50,7 +49,21 @@ const Cart = () => {
 
   useEffect(() => {
     if (cart) {
-      setProducts(cart.products)
+      const processProducts = async () => {
+        const updatedProducts = await Promise.all(
+          cart.products.map(async (product) => {
+            const id = product.id
+            const program = await getPromotionProgram({ id })
+            const isPromo = program.length > 0 ? 1 : 0
+            return {
+              ...product,
+              isPromo
+            }
+          })
+        )
+        setProducts(updatedProducts)
+      }
+      processProducts()
       setIsLoading(false)
     }
   }, [cart])
@@ -62,6 +75,10 @@ const Cart = () => {
   const [deleteConfirmation, setDeleteConfirmation] = useState(null)
 
   const [productRecomendation, setProductRecomendation] = useState(null)
+  const [promotionType, setPromotionType] = useState(null)
+  const [variantId, setVariantId] = useState(null)
+  const [quantity, setQuantity] = useState(null)
+  const [promotionActiveId, setPromotionActiveId] = useState(null)
 
   useEffect(() => {
     if (!products) return
@@ -84,6 +101,18 @@ const Cart = () => {
     setTotalDiscountAmount(calculateTotalDiscountAmount)
   }, [products])
 
+  useEffect(() => {
+    if(!promotionActiveId) return
+
+    console.log('bajingan')
+    updateItemCart({
+      productId: variantId,
+      quantity,
+      programLineId:promotionActiveId,
+      selected: true
+    })
+  }, [promotionActiveId, variantId, quantity])
+
   useEffect(() => {
     const LoadProductSimilar = async () => {
       const randProductIndex = Math.floor(Math.random() * products.length)
@@ -152,6 +181,13 @@ const Cart = () => {
     toast.success('Berhasil menghapus barang dari keranjang')
   }
 
+  const handlePopUpPromo = (variantId, quantity, promoId = null) => {
+    setPromotionType(true)
+    setVariantId(variantId)
+    setQuantity(quantity)
+    setPromotionActiveId(promoId)
+  }
+
   return (
     <>
       <BottomPopup
@@ -181,6 +217,23 @@ const Cart = () => {
         </div>
       </BottomPopup>
 
+      <BottomPopup
+        className=' !h-[75%]'
+        title='Pakai Promo'
+        active={promotionType}
+        close={() => setPromotionType(false)}
+      >
+        <div className='flex mt-4'>
+          <PromotionType
+            isModal={true}
+            variantId={variantId}
+            setPromotionActiveId={setPromotionActiveId}
+            promotionActiveId={promotionActiveId}
+            quantity={quantity}
+          ></PromotionType>
+        </div>
+      </BottomPopup>
+
       <MobileView>
         <div className='pt-4'>
           <div className='flex justify-between mb-4 px-4'>
@@ -351,15 +404,61 @@ const Cart = () => {
                 {products &&
                   products?.map((product) => (
                     <>
-                      <tr className='!border-b-0 pb-0'>
-                        <td colSpan={6}>
-                          <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
-                            <div className='flex border border-solid border-red-600 rounded-md p-1'><span className='text-red-600'>Promo</span></div>
-                            <div className='flex font-semibold'>Pilih Promo Yang Tersedia Bisa lebih Hemat</div>
-                            <div className='justify-end'>Cek Promo </div>
-                          </div>
-                        </td>
-                      </tr>
+                      {product.isPromo > 0 && (
+                        <tr className='!border-b-0 pb-0'>
+                          <td colSpan={6}>
+                            <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
+                              {product.program ? (
+                                <>
+                                  <div className='flex border border-solid border-red-600 rounded-md p-1'>
+                                    <span className='text-red-600'>
+                                      {product.program.type.label}
+                                    </span>
+                                  </div>
+                                  <div className='flex'>
+                                    Anda Lebih hamat{' '}
+                                    <span className='text-red-600 font-semibold ml-2'>
+                                      {' '}
+                                      {currencyFormat(product.program.price.priceDiscount)}
+                                    </span>
+                                  </div>
+                                </>
+                              ) : (
+                                <>
+                                  <div className='flex border border-solid border-red-600 rounded-md p-1'>
+                                    <span className='text-red-600'>Promo</span>
+                                  </div>
+                                  <div className='flex'>
+                                    Pilih Promo Yang Tersedia Bisa lebih Hemat
+                                  </div>
+                                </>
+                              )}
+                              <div
+                                onClick={() => handlePopUpPromo(product.id, product.quantity, product.program?.id)}
+                                className='ml-auto text-red-500 flex gap-x-1 cursor-pointer'
+                              >
+                                <div className='font-semibold'> Cek Promo</div>
+                                <div>
+                                  <svg
+                                    aria-hidden='true'
+                                    fill='none'
+                                    stroke='currentColor'
+                                    stroke-width='1.5'
+                                    viewBox='0 0 20 24'
+                                    className='h-5 w-5 font-semibold'
+                                  >
+                                    <path
+                                      d='M8.25 4.5l7.5 7.5-7.5 7.5'
+                                      stroke-linecap='round'
+                                      stroke-linejoin='round'
+                                    ></path>
+                                  </svg>
+                                </div>
+                              </div>
+                            </div>
+                          </td>
+                        </tr>
+                      )}
                       <tr key={product.id} className='!border-t-0'>
                         <td>
                           <input
@@ -443,6 +542,54 @@ const Cart = () => {
                           </div>
                         </td>
                       </tr>
+                      {product.program && (
+                        <tr key={product?.program?.id} className='!border-t-0'>
+                          <td></td>
+                          <td className='flex'>
+                            <div className='w-[20%] flex-shrink-0'>
+                              <Image
+                                src={product.program.image}
+                                alt={product.program.name}
+                                className='object-contain object-center border border-gray_r-6 h-28 w-full rounded-md'
+                              />
+                            </div>
+                            <div className='px-2 text-left'>
+                              <div className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'>
+                                <div className='flex border border-solid border-red-600 rounded-md p-1'>
+                                  <span className='text-red-600'>{product.program.type.label}</span>
+                                </div>
+                                <div className='mt-2'>{product.program.name}</div>
+                              </div>
+                            </div>
+                          </td>
+                          <td>
+                            <input
+                              className='form-input w-16 py-2 text-center bg-gray_r-1'
+                              type='number'
+                              value={1}
+                              disabled
+                            />
+                          </td>
+                          <td>
+                            {product?.price?.discountPercentage > 0 && (
+                              <div className='flex gap-x-1 items-center justify-center mt-3'>
+                                <div className='text-gray_r-11 line-through text-caption-1'>
+                                  {currencyFormat(product?.price?.price)}
+                                </div>
+                              </div>
+                            )}
+                            <div className='font-normal mt-1'>
+                              {product?.program?.price.priceDiscount > 0 ? 'Gratis' : ''}
+                            </div>
+                          </td>
+                          <td>
+                            <div className='text-danger-500 font-medium'>
+                              {product.program.price.priceDiscount > 0 ? 'Gratis' : ''}
+                            </div>
+                          </td>
+                          <td></td>
+                        </tr>
+                      )}
                     </>
                   ))}
               </tbody>
-- 
cgit v1.2.3


From c4ff871551cfbf3ed759b3d7be735d7039edb6f5 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Fri, 30 Jun 2023 14:58:05 +0700
Subject: cart

---
 src/lib/cart/components/Cart.jsx | 83 ++++++++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 33 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 29bbf080..0cbcacd8 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -4,12 +4,7 @@ import Image from '@/core/components/elements/Image/Image'
 import NextImage from 'next/image'
 import currencyFormat from '@/core/utils/currencyFormat'
 import { useEffect, useState } from 'react'
-import {
-  addCart,
-  deleteItemCart,
-  getCartApi,
-  updateItemCart
-} from '@/core/utils/cart'
+import { addCart, deleteItemCart, getCartApi, updateItemCart } from '@/core/utils/cart'
 import { CheckIcon, TrashIcon } from '@heroicons/react/24/outline'
 import { createSlug } from '@/core/utils/slug'
 import { useRouter } from 'next/router'
@@ -39,12 +34,13 @@ const Cart = () => {
     if (!auth) return
   }, [auth])
 
+  const getCart = async () => {
+    const listCart = await getCartApi()
+    setCart(listCart)
+  }
+
   useEffect(() => {
-    const cart = async () => {
-      const listCart = await getCartApi()
-      setCart(listCart)
-    }
-    cart()
+    getCart()
   }, [])
 
   useEffect(() => {
@@ -102,16 +98,20 @@ const Cart = () => {
   }, [products])
 
   useEffect(() => {
-    if(!promotionActiveId) return
-
-    console.log('bajingan')
-    updateItemCart({
-      productId: variantId,
-      quantity,
-      programLineId:promotionActiveId,
-      selected: true
-    })
-  }, [promotionActiveId, variantId, quantity])
+    const updateData = () => {
+      updateItemCart({
+        productId: variantId,
+        quantity,
+        programLineId: promotionActiveId,
+        selected: true
+      }).then(() => {
+        getCart().then(() => {
+          setPromotionType(false)
+        })
+      })
+    }
+    updateData()
+  }, [promotionActiveId])
 
   useEffect(() => {
     const LoadProductSimilar = async () => {
@@ -416,11 +416,17 @@ const Cart = () => {
                                     </span>
                                   </div>
                                   <div className='flex'>
-                                    Anda Lebih hamat{' '}
-                                    <span className='text-red-600 font-semibold ml-2'>
-                                      {' '}
-                                      {currencyFormat(product.program.price.priceDiscount)}
-                                    </span>
+                                    {product.program.type.value == 'merchandise' ? (
+                                      <>Selamat anda mendapatkan merchandise indoteknik.com</>
+                                    ) : (
+                                      <>
+                                        Selamat! Pembelian anda lebih hemat
+                                        <span className='text-red-600 font-semibold ml-2'>
+                                          {' '}
+                                          {currencyFormat(product.program.price.priceDiscount)}
+                                        </span>
+                                      </>
+                                    )}
                                   </div>
                                 </>
                               ) : (
@@ -434,7 +440,13 @@ const Cart = () => {
                                 </>
                               )}
                               <div
-                                onClick={() => handlePopUpPromo(product.id, product.quantity, product.program?.id)}
+                                onClick={() =>
+                                  handlePopUpPromo(
+                                    product.id,
+                                    product.quantity,
+                                    product.program?.id
+                                  )
+                                }
                                 className='ml-auto text-red-500 flex gap-x-1 cursor-pointer'
                               >
                                 <div className='font-semibold'> Cek Promo</div>
@@ -459,7 +471,10 @@ const Cart = () => {
                           </td>
                         </tr>
                       )}
-                      <tr key={product.id} className='!border-t-0'>
+                      <tr
+                        key={product.id}
+                        className={`${product.isPromo ? '!border-t-0 !border-b-0' : ''}`}
+                      >
                         <td>
                           <input
                             type='checkbox'
@@ -554,11 +569,13 @@ const Cart = () => {
                               />
                             </div>
                             <div className='px-2 text-left'>
-                              <div className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'>
-                                <div className='flex border border-solid border-red-600 rounded-md p-1'>
-                                  <span className='text-red-600'>{product.program.type.label}</span>
-                                </div>
-                                <div className='mt-2'>{product.program.name}</div>
+                              <div className=''>
+                                <span className='border border-solid border-red-600 rounded-md p-1 text-red-600'>
+                                  {product.program.type.label}
+                                </span>
+                              </div>
+                              <div className='mt-2 line-clamp-2 leading-6'>
+                                {product.program.name}
                               </div>
                             </div>
                           </td>
-- 
cgit v1.2.3


From 2777e0d64152dace9c5307cd07bd8e13c6f6631e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 3 Jul 2023 10:05:40 +0700
Subject: cart mobile

---
 src/lib/cart/components/Cart.jsx | 210 +++++++++++++++++++++++++--------------
 1 file changed, 138 insertions(+), 72 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 0cbcacd8..45f2f770 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -256,85 +256,151 @@ const Cart = () => {
               </div>
             )}
 
-            {products?.map((product) => (
-              <div key={product?.id} className='flex mx-4'>
-                <input
-                  type='checkbox'
-                  onClick={() => toggleSelected(product.id)}
-                  checked={product?.selected}
-                  className='mr-2 accent-danger-500 w-4'
-                />
-
-                <Link
-                  href={createSlug('/shop/product/', product?.parent.name, product?.parent.id)}
-                  className='w-[30%] flex-shrink-0'
-                >
-                  <Image
-                    src={product?.parent?.image}
-                    alt={product?.name}
-                    className='object-contain object-center border border-gray_r-6 h-40 w-full rounded-md'
-                  />
-                </Link>
-                <div className='flex-1 px-2 text-caption-2'>
-                  <Link
-                    href={createSlug('/shop/product/', product?.parent.name, product?.parent.id)}
-                    className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'
-                  >
-                    {product?.parent?.name}
-                  </Link>
-                  <div className='text-gray_r-11 mt-1'>
-                    {product?.code}{' '}
-                    {product?.attributes.length > 0 ? `| ${product?.attributes.join(', ')}` : ''}
-                  </div>
-                  {product?.price?.discountPercentage > 0 && (
-                    <div className='flex gap-x-1 items-center mt-3'>
-                      <div className='text-gray_r-11 line-through text-caption-2'>
-                        {currencyFormat(product?.price?.price)}
+            {products &&
+              products?.map((product) => (
+                <>
+                  {product.isPromo > 0 && (
+                    <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
+                      {product.program ? (
+                        <>
+                          <div className='flex border border-solid border-red-600 rounded-md p-1 text-caption-2'>
+                            <span className='text-red-600'>{product.program.type.label}</span>
+                          </div>
+                          <div className='flex text-caption-2'>
+                            {product.program.type.value == 'merchandise' ? (
+                              <>Selamat anda mendapatkan merchandise indoteknik.com</>
+                            ) : (
+                              <>
+                                Selamat! Pembelian anda lebih hemat
+                                <span className='text-red-600 font-semibold ml-2 text-caption-2'>
+                                  {' '}
+                                  {currencyFormat(product.program.price.priceDiscount)}
+                                </span>
+                              </>
+                            )}
+                          </div>
+                        </>
+                      ) : (
+                        <>
+                          <div className='flex border border-solid border-red-600 rounded-md p-1'>
+                            <span className='text-red-600'>Promo</span>
+                          </div>
+                          <div className='flex'>Pilih Promo Yang Tersedia Bisa lebih Hemat</div>
+                        </>
+                      )}
+                      <div
+                        onClick={() =>
+                          handlePopUpPromo(product.id, product.quantity, product.program?.id)
+                        }
+                        className='ml-auto text-red-500 flex gap-x-1 cursor-pointer'
+                      >
+                        <div className='font-semibold text-caption-2'> Cek Promo</div>
+                        <div>
+                          <svg
+                            aria-hidden='true'
+                            fill='none'
+                            stroke='currentColor'
+                            stroke-width='1.5'
+                            viewBox='0 0 20 24'
+                            className='h-5 w-5 font-semibold'
+                          >
+                            <path
+                              d='M8.25 4.5l7.5 7.5-7.5 7.5'
+                              stroke-linecap='round'
+                              stroke-linejoin='round'
+                            ></path>
+                          </svg>
+                        </div>
                       </div>
-                      <div className='badge-solid-red'>{product?.price?.discountPercentage}%</div>
                     </div>
                   )}
-                  <div className='font-normal mt-1'>
-                    {currencyFormat(product?.price?.priceDiscount)}
-                  </div>
-                  <div className='flex justify-between items-center mt-1'>
-                    <div className='text-danger-500 font-medium'>
-                      {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
-                    </div>
-                    <div className='flex gap-x-1'>
-                      <button
-                        type='button'
-                        className='btn-light px-2 py-1'
-                        onClick={() => updateQuantity(1, product?.id, 'MINUS')}
-                        disabled={product?.quantity == 1}
-                      >
-                        -
-                      </button>
-                      <input
-                        className='form-input w-6 border-0 border-b rounded-none py-1 px-0 text-center'
-                        type='number'
-                        value={product?.quantity}
-                        onChange={(e) => updateQuantity(e.target.value, product?.id)}
-                        onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')}
+                  <div key={product?.id} className='flex mx-4'>
+                    <input
+                      type='checkbox'
+                      onClick={() => toggleSelected(product.id)}
+                      checked={product?.selected}
+                      className='mr-2 accent-danger-500 w-4'
+                    />
+
+                    <Link
+                      href={createSlug('/shop/product/', product?.parent.name, product?.parent.id)}
+                      className='w-[30%] flex-shrink-0'
+                    >
+                      <Image
+                        src={product?.parent?.image}
+                        alt={product?.name}
+                        className='object-contain object-center border border-gray_r-6 h-40 w-full rounded-md'
                       />
-                      <button
-                        type='button'
-                        className='btn-light px-2 py-1'
-                        onClick={() => updateQuantity(1, product?.id, 'PLUS')}
-                      >
-                        +
-                      </button>
-                      <button
-                        className='btn-red p-1 ml-1'
-                        onClick={() => setDeleteConfirmation(product)}
+                    </Link>
+                    <div className='flex-1 px-2 text-caption-2'>
+                      <Link
+                        href={createSlug(
+                          '/shop/product/',
+                          product?.parent.name,
+                          product?.parent.id
+                        )}
+                        className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'
                       >
-                        <TrashIcon className='w-4' />
-                      </button>
+                        {product?.parent?.name}
+                      </Link>
+                      <div className='text-gray_r-11 mt-1'>
+                        {product?.code}{' '}
+                        {product?.attributes.length > 0
+                          ? `| ${product?.attributes.join(', ')}`
+                          : ''}
+                      </div>
+                      {product?.price?.discountPercentage > 0 && (
+                        <div className='flex gap-x-1 items-center mt-3'>
+                          <div className='text-gray_r-11 line-through text-caption-2'>
+                            {currencyFormat(product?.price?.price)}
+                          </div>
+                          <div className='badge-solid-red'>
+                            {product?.price?.discountPercentage}%
+                          </div>
+                        </div>
+                      )}
+                      <div className='font-normal mt-1'>
+                        {currencyFormat(product?.price?.priceDiscount)}
+                      </div>
+                      <div className='flex justify-between items-center mt-1'>
+                        <div className='text-danger-500 font-medium'>
+                          {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
+                        </div>
+                        <div className='flex gap-x-1'>
+                          <button
+                            type='button'
+                            className='btn-light px-2 py-1'
+                            onClick={() => updateQuantity(1, product?.id, 'MINUS')}
+                            disabled={product?.quantity == 1}
+                          >
+                            -
+                          </button>
+                          <input
+                            className='form-input w-6 border-0 border-b rounded-none py-1 px-0 text-center'
+                            type='number'
+                            value={product?.quantity}
+                            onChange={(e) => updateQuantity(e.target.value, product?.id)}
+                            onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')}
+                          />
+                          <button
+                            type='button'
+                            className='btn-light px-2 py-1'
+                            onClick={() => updateQuantity(1, product?.id, 'PLUS')}
+                          >
+                            +
+                          </button>
+                          <button
+                            className='btn-red p-1 ml-1'
+                            onClick={() => setDeleteConfirmation(product)}
+                          >
+                            <TrashIcon className='w-4' />
+                          </button>
+                        </div>
+                      </div>
                     </div>
                   </div>
-                </div>
-              </div>
-            ))}
+                </>
+              ))}
 
             <div className='sticky bottom-0 left-0 w-full p-4 mt-auto border-t border-gray_r-6 bg-white'>
               <div className='flex justify-between mb-4'>
-- 
cgit v1.2.3


From 8b173abd19630b7cab5f0f562925c46e3f71d096 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 4 Jul 2023 13:38:33 +0700
Subject: promotion program

---
 src/lib/cart/components/Cart.jsx | 149 +++++++++++++++++++++++----------------
 1 file changed, 90 insertions(+), 59 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 45f2f770..f1584f98 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -59,7 +59,8 @@ const Cart = () => {
         )
         setProducts(updatedProducts)
       }
-      processProducts()
+      // processProducts()
+      setProducts(cart.products)
       setIsLoading(false)
     }
   }, [cart])
@@ -86,6 +87,10 @@ const Cart = () => {
       if (product.quantity == '') continue
 
       if (!product.selected) continue
+
+      if (product.canBuy == false) {
+        toggleSelected(product.id)
+      }
       let priceBeforeTax = product.price.price / 1.11
       calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity
       calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity
@@ -153,7 +158,12 @@ const Cart = () => {
     productsToUpdate[productIndex].quantity = qty
 
     setProducts([...productsToUpdate])
-    addCart(productId, qty, productsToUpdate[productIndex].selected)
+    addCart(
+      productId,
+      qty,
+      productsToUpdate[productIndex].selected,
+      productsToUpdate[productIndex].program?.id
+    )
   }
 
   const toggleSelected = (productId) => {
@@ -165,7 +175,12 @@ const Cart = () => {
     productsToUpdate[productIndex].selected = isSelected
 
     setProducts([...productsToUpdate])
-    addCart(productId, productsToUpdate[productIndex].quantity, isSelected)
+    addCart(
+      productId,
+      productsToUpdate[productIndex].quantity,
+      isSelected,
+      productsToUpdate[productIndex].program?.id
+    )
   }
 
   const selectedProduct = () => {
@@ -259,7 +274,7 @@ const Cart = () => {
             {products &&
               products?.map((product) => (
                 <>
-                  {product.isPromo > 0 && (
+                  {product.hasProgram > 0 && (
                     <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
                       {product.program ? (
                         <>
@@ -470,7 +485,7 @@ const Cart = () => {
                 {products &&
                   products?.map((product) => (
                     <>
-                      {product.isPromo > 0 && (
+                      {product.hasProgram && (
                         <tr className='!border-b-0 pb-0'>
                           <td colSpan={6}>
                             <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
@@ -489,7 +504,7 @@ const Cart = () => {
                                         Selamat! Pembelian anda lebih hemat
                                         <span className='text-red-600 font-semibold ml-2'>
                                           {' '}
-                                          {currencyFormat(product.program.price.priceDiscount)}
+                                          {currencyFormat(product.program?.totalSavings)}
                                         </span>
                                       </>
                                     )}
@@ -539,9 +554,10 @@ const Cart = () => {
                       )}
                       <tr
                         key={product.id}
-                        className={`${product.isPromo ? '!border-t-0 !border-b-0' : ''}`}
+                        className={`${product.hasProgram ? '!border-t-0 !border-b-0' : ''}`}
                       >
-                        <td>
+                        <td className='relative'>
+                          <ComponentCanBuy canBuy={product.canBuy} />
                           <input
                             type='checkbox'
                             onClick={() => toggleSelected(product.id)}
@@ -549,7 +565,8 @@ const Cart = () => {
                             className='accent-danger-500 w-4'
                           />
                         </td>
-                        <td className='flex'>
+                        <td className='flex relative'>
+                          <ComponentCanBuy canBuy={product.canBuy} />
                           <Link
                             href={createSlug(
                               '/shop/product/',
@@ -583,7 +600,8 @@ const Cart = () => {
                             </div>
                           </div>
                         </td>
-                        <td>
+                        <td className='relative'>
+                          <ComponentCanBuy canBuy={product.canBuy} />
                           <input
                             className='form-input w-16 py-2 text-center bg-gray_r-1'
                             type='number'
@@ -592,7 +610,8 @@ const Cart = () => {
                             onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')}
                           />
                         </td>
-                        <td>
+                        <td className='relative'>
+                          <ComponentCanBuy canBuy={product.canBuy} />
                           {product?.price?.discountPercentage > 0 && (
                             <div className='flex gap-x-1 items-center justify-center mt-3'>
                               <div className='text-gray_r-11 line-through text-caption-1'>
@@ -607,7 +626,8 @@ const Cart = () => {
                             {currencyFormat(product?.price?.priceDiscount)}
                           </div>
                         </td>
-                        <td>
+                        <td className='relative'>
+                          <ComponentCanBuy canBuy={product.canBuy} />
                           <div className='text-danger-500 font-medium'>
                             {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
                           </div>
@@ -623,54 +643,62 @@ const Cart = () => {
                           </div>
                         </td>
                       </tr>
-                      {product.program && (
-                        <tr key={product?.program?.id} className='!border-t-0'>
-                          <td></td>
-                          <td className='flex'>
-                            <div className='w-[20%] flex-shrink-0'>
-                              <Image
-                                src={product.program.image}
-                                alt={product.program.name}
-                                className='object-contain object-center border border-gray_r-6 h-28 w-full rounded-md'
-                              />
-                            </div>
-                            <div className='px-2 text-left'>
-                              <div className=''>
-                                <span className='border border-solid border-red-600 rounded-md p-1 text-red-600'>
-                                  {product.program.type.label}
-                                </span>
-                              </div>
-                              <div className='mt-2 line-clamp-2 leading-6'>
-                                {product.program.name}
-                              </div>
-                            </div>
-                          </td>
-                          <td>
-                            <input
-                              className='form-input w-16 py-2 text-center bg-gray_r-1'
-                              type='number'
-                              value={1}
-                              disabled
-                            />
-                          </td>
-                          <td>
-                            {product?.price?.discountPercentage > 0 && (
-                              <div className='flex gap-x-1 items-center justify-center mt-3'>
-                                <div className='text-gray_r-11 line-through text-caption-1'>
-                                  {currencyFormat(product?.price?.price)}
+                      {product?.program?.items && (
+                        <tr key={product.program.id} className='!border-t-0'>
+                          {product.program.items.map((item) => (
+                            <>
+                              <td className='relative'>
+                                <ComponentCanBuy canBuy={product.canBuy} />
+                              </td>
+                              <td className='flex relative'>
+                                <ComponentCanBuy canBuy={product.canBuy} />
+                                <div className='w-[20%] flex-shrink-0'>
+                                  <Image
+                                    src={item.parent.image}
+                                    alt={item.name}
+                                    className='object-contain object-center border border-gray_r-6 h-28 w-full rounded-md'
+                                  />
                                 </div>
-                              </div>
-                            )}
-                            <div className='font-normal mt-1'>
-                              {product?.program?.price.priceDiscount > 0 ? 'Gratis' : ''}
-                            </div>
-                          </td>
-                          <td>
-                            <div className='text-danger-500 font-medium'>
-                              {product.program.price.priceDiscount > 0 ? 'Gratis' : ''}
-                            </div>
-                          </td>
-                          <td></td>
+                                <div className='px-2 text-left'>
+                                  <div className=''>
+                                    <span className='border border-solid border-red-600 rounded-md p-1 text-red-600'>
+                                      {product.program.type.label}
+                                    </span>
+                                  </div>
+                                  <div className='mt-2 line-clamp-2 leading-6'>{item.name}</div>
+                                </div>
+                              </td>
+                              <td className='relative'>
+                                <ComponentCanBuy canBuy={product.canBuy} />
+                                <input
+                                  className='form-input w-16 py-2 text-center bg-gray_r-1'
+                                  type='number'
+                                  value={1}
+                                  disabled
+                                />
+                              </td>
+                              <td className='relative'>
+                                <ComponentCanBuy canBuy={product.canBuy} />
+                                {item?.price?.discountPercentage > 0 && (
+                                  <div className='flex gap-x-1 items-center justify-center mt-3'>
+                                    <div className='text-gray_r-11 line-through text-caption-1'>
+                                      {currencyFormat(product?.price?.price)}
+                                    </div>
+                                  </div>
+                                )}
+                                <div className='font-normal mt-1'>
+                                  {item?.price.priceDiscount > 0 ? 'Gratis' : ''}
+                                </div>
+                              </td>
+                              <td className='relative'>
+                                <ComponentCanBuy canBuy={product.canBuy} />
+                                <div className='text-danger-500 font-medium'>
+                                  {item.price.priceDiscount > 0 ? 'Gratis' : ''}
+                                </div>
+                              </td>
+                              <td></td>
+                            </>
+                          ))}
                         </tr>
                       )}
                     </>
@@ -747,4 +775,7 @@ const Cart = () => {
   )
 }
 
+const ComponentCanBuy = ({ canBuy }) =>
+  !canBuy && <div className='absolute w-full h-full bg-gray_r-3/40 top-0 left-0' />
+
 export default Cart
-- 
cgit v1.2.3


From 9272a07644a75d201753501cfff173b1260963ea Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 5 Jul 2023 09:29:46 +0700
Subject: cart, checkout dan nav bar mobile

---
 src/lib/cart/components/Cart.jsx | 69 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 61 insertions(+), 8 deletions(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index f1584f98..224d02d1 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -278,18 +278,18 @@ const Cart = () => {
                     <div className='flex gap-x-2 bg-yellow-100 p-2 items-center'>
                       {product.program ? (
                         <>
-                          <div className='flex border border-solid border-red-600 rounded-md p-1 text-caption-2'>
+                          <div className='border border-solid border-red-600 rounded-md p-1 text-caption-2 whitespace-nowrap'>
                             <span className='text-red-600'>{product.program.type.label}</span>
                           </div>
-                          <div className='flex text-caption-2'>
+                          <div className='text-caption-2'>
                             {product.program.type.value == 'merchandise' ? (
                               <>Selamat anda mendapatkan merchandise indoteknik.com</>
                             ) : (
                               <>
-                                Selamat! Pembelian anda lebih hemat
-                                <span className='text-red-600 font-semibold ml-2 text-caption-2'>
+                                Selamat! Pembelian anda hemat
+                                <span className='text-red-600 font-semibold text-caption-2'>
                                   {' '}
-                                  {currencyFormat(product.program.price.priceDiscount)}
+                                  {currencyFormat(product.program?.totalSavings)}
                                 </span>
                               </>
                             )}
@@ -307,9 +307,12 @@ const Cart = () => {
                         onClick={() =>
                           handlePopUpPromo(product.id, product.quantity, product.program?.id)
                         }
-                        className='ml-auto text-red-500 flex gap-x-1 cursor-pointer'
+                        className='ml-auto text-red-500 flex gap-x-0 cursor-pointer'
                       >
-                        <div className='font-semibold text-caption-2'> Cek Promo</div>
+                        <div className='font-semibold text-caption-2 whitespace-nowrap'>
+                          {' '}
+                          Cek Promo
+                        </div>
                         <div>
                           <svg
                             aria-hidden='true'
@@ -329,7 +332,8 @@ const Cart = () => {
                       </div>
                     </div>
                   )}
-                  <div key={product?.id} className='flex mx-4'>
+                  <div key={product?.id} className='flex mx-4 relative'>
+                    <ComponentCanBuy canBuy={product.canBuy} />
                     <input
                       type='checkbox'
                       onClick={() => toggleSelected(product.id)}
@@ -414,6 +418,55 @@ const Cart = () => {
                       </div>
                     </div>
                   </div>
+                  {product.program &&
+                    product.program.items &&
+                    product.program.items.map((item) => (
+                      <div key={item.id} className='flex mx-4 relative'>
+                         <ComponentCanBuy canBuy={product.canBuy} />
+                        <input className='mr-2 accent-danger-500 w-4' />
+                        <Link
+                          href={createSlug(
+                            '/shop/product/',
+                            product?.parent.name,
+                            product?.parent.id
+                          )}
+                          className='w-[30%] flex-shrink-0'
+                        >
+                          <Image
+                            src={item?.parent?.image}
+                            alt={item?.name}
+                            className='object-contain object-center border border-gray_r-6 h-40 w-full rounded-md'
+                          />
+                        </Link>
+                        <div className='flex-1 px-2 text-caption-2'>
+                          <Link
+                            href={createSlug(
+                              '/shop/product/',
+                              product?.parent.name,
+                              product?.parent.id
+                            )}
+                            className='line-clamp-2 leading-6 !text-gray_r-12 font-normal'
+                          >
+                            <div className='px-2 text-left mt-2'>
+                              <div className='mb-2'>
+                                <span className='border border-solid border-red-600 rounded-md p-1 text-red-600'>
+                                  {product.program.type.label}
+                                </span>
+                              </div>
+                              <div>{item.name}</div>
+                            </div>
+                          </Link>
+                          {item.price?.discountPercentage > 0 && (
+                            <div className='flex gap-x-1 items-center mt-3 ml-3'>
+                              <div className='text-gray_r-11 line-through text-caption-2'>
+                                {currencyFormat(item?.price?.price)}
+                              </div>
+                            </div>
+                          )}
+                          <div className='text-danger-500 font-medium mt-1 ml-3'>Gratis</div>
+                        </div>
+                      </div>
+                    ))}
                 </>
               ))}
 
-- 
cgit v1.2.3


From 581334e8d077916c3a9ab87fd5b6e6b5126aba12 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Mon, 10 Jul 2023 10:00:33 +0700
Subject: add auth id

---
 src/lib/cart/components/Cart.jsx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src/lib/cart/components/Cart.jsx')

diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 224d02d1..41efffe9 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -111,7 +111,9 @@ const Cart = () => {
         selected: true
       }).then(() => {
         getCart().then(() => {
-          setPromotionType(false)
+          if(promotionActiveId){
+            setPromotionType(false)
+          }
         })
       })
     }
-- 
cgit v1.2.3

