From fb80b92d502437160e45b237b380071ab102c838 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 22 Jan 2024 10:41:53 +0700
Subject: Update disable checkout when has product price 0 and fix filter brand

---
 src/lib/checkout/components/Checkout.jsx | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

(limited to 'src/lib/checkout/components/Checkout.jsx')

diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index eb31b9dc..85eda80b 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -10,7 +10,7 @@ import {
   ClockIcon,
   ExclamationCircleIcon,
 } from '@heroicons/react/24/outline';
-import React, { useEffect, useRef, useState } from 'react';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
 import _ from 'lodash';
 import { deleteItemCart } from '@/core/utils/cart';
 import currencyFormat from '@/core/utils/currencyFormat';
@@ -411,6 +411,14 @@ const Checkout = () => {
   };
   // const taxTotal = (totalAmount - totalDiscountAmount - discountVoucher) * 0.11
 
+  const hasNoPrice = useMemo(() => {
+    if (!products) return false;
+    for (const item of products) {
+      if (item.price.priceDiscount == 0) return true;
+    }
+    return false;
+  }, [products]);
+
   return (
     <>
       <BottomPopup
@@ -995,7 +1003,11 @@ const Checkout = () => {
             className='flex-1 btn-yellow'
             onClick={checkout}
             disabled={
-              isLoading || !products || products?.length == 0 || priceCheck
+              isLoading ||
+              !products ||
+              products?.length == 0 ||
+              priceCheck ||
+              hasNoPrice
             }
           >
             {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
@@ -1090,8 +1102,7 @@ const Checkout = () => {
                 <div className='flex justify-between items-center'>
                   <div className='font-medium'>Ringkasan Pesanan</div>
                   <div className='text-gray_r-11 text-caption-1'>
-                    {cartCheckout?.totalWeight.kg}{' '}
-                    Kg
+                    {cartCheckout?.totalWeight.kg} Kg
                   </div>
                 </div>
 
@@ -1283,7 +1294,8 @@ const Checkout = () => {
                     isLoading ||
                     !products ||
                     products?.length == 0 ||
-                    priceCheck
+                    priceCheck ||
+                    hasNoPrice
                   }
                 >
                   {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
-- 
cgit v1.2.3

