From 2413603c4e17c5ab2f3d07ec26c40f1d2f61bc67 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Tue, 11 Apr 2023 16:32:49 +0700
Subject: validate if price 0

---
 src/lib/checkout/components/Checkout.jsx | 39 ++++++++++++++++++++++++++++----
 1 file changed, 34 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 cb96b995..eee679fd 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -61,6 +61,7 @@ const Checkout = () => {
   const [products, setProducts] = useState(null)
   const [totalAmount, setTotalAmount] = useState(0)
   const [totalDiscountAmount, setTotalDiscountAmount] = useState(0)
+  const [priceCheck, setPriceCheck] = useState(false)
 
   useEffect(() => {
     const loadProducts = async () => {
@@ -77,6 +78,7 @@ const Checkout = () => {
 
       const dataProducts = await CartApi({ variantIds })
       const productsWithQuantity = dataProducts?.map((product) => {
+        if (product.price.priceDiscount == 0) setPriceCheck(true)
         return {
           ...product,
           quantity: query.quantity
@@ -141,7 +143,6 @@ const Checkout = () => {
     setIsLoading(false)
     window.location.href = payment.data.redirectUrl
   }
-
   const taxTotal = (totalAmount - totalDiscountAmount) * 0.11
 
   return (
@@ -241,11 +242,21 @@ const Checkout = () => {
           <button
             className='flex-1 btn-yellow'
             onClick={checkout}
-            disabled={isLoading || !products || products?.length == 0}
+            disabled={isLoading || !products || products?.length == 0 || priceCheck}
           >
             {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
           </button>
         </div>
+        {priceCheck && (
+          <div className='px-4 mb-4'>
+            <span className='text-danger-500'>
+              *) Terdapat produk yang belum memiliki harga,{' '}
+              <a href='https://wa.me/628128080622' className='underline'>
+                Hubungi Kami untuk meminta harga.
+              </a>
+            </span>
+          </div>
+        )}
       </MobileView>
 
       <DesktopView>
@@ -309,12 +320,20 @@ const Checkout = () => {
                           </div>
                         )}
                         <div className='font-normal mt-1'>
-                          {currencyFormat(product?.price?.priceDiscount)}
+                          {product.price.priceDiscount > 0
+                            ? currencyFormat(product?.price?.priceDiscount)
+                            : 'Call For Price'}
                         </div>
                       </td>
                       <td>
                         <div className='text-danger-500 font-medium'>
-                          {currencyFormat(product?.price?.priceDiscount * product?.quantity)}
+                          {product.price.priceDiscount > 0 ? (
+                            currencyFormat(product?.price?.priceDiscount * product?.quantity)
+                          ) : (
+                            <a href='https://wa.me/628128080622' className='underline'>
+                              Call For Price{' '}
+                            </a>
+                          )}
                         </div>
                       </td>
                     </tr>
@@ -396,10 +415,20 @@ const Checkout = () => {
               <button
                 className='w-full btn-yellow mt-4'
                 onClick={checkout}
-                disabled={isLoading || !products || products?.length == 0}
+                disabled={isLoading || !products || products?.length == 0 || priceCheck}
               >
                 {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
               </button>
+              {priceCheck && (
+                <div className='mt-4'>
+                  <span className='text-danger-500'>
+                    *) Terdapat produk yang belum memiliki harga,{' '}
+                    <a href='https://wa.me/628128080622' className='underline'>
+                      Hubungi Kami untuk meminta harga.
+                    </a>
+                  </span>
+                </div>
+              )}
             </div>
           </div>
         </div>
-- 
cgit v1.2.3

