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

