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

