From f15a7f8a4387d215abd1051ee520adca8944fa05 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 28 Mar 2023 16:32:45 +0700
Subject: checkout, quotation

---
 src/lib/checkout/components/Checkout.jsx | 53 ++++++++++----------------------
 1 file changed, 17 insertions(+), 36 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 048bb24e..ffb33eb7 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -78,7 +78,7 @@ const Checkout = () => {
       }
 
       const dataProducts = await CartApi({ variantIds })
-      const productsWithQuantity = dataProducts.map(async (product) => {
+      const productsWithQuantity = dataProducts?.map(async (product) => {
         const productPrice = await variantPriceApi({ id: product.id })
         return {
           ...product,
@@ -87,12 +87,16 @@ const Checkout = () => {
             discountPercentage: productPrice.discount,
             priceDiscount: productPrice.priceExcludeAfterDiscount
           },
-          quantity: query.quantity ? query.quantity : getItemCart({ productId: product.id }).quantity
+          quantity: query.quantity
+            ? query.quantity
+            : getItemCart({ productId: product.id }).quantity
         }
       })
-      Promise.all(productsWithQuantity).then((resolvedProducts) => {
-        setProducts(resolvedProducts)
-      })
+      if (productsWithQuantity) {
+        Promise.all(productsWithQuantity).then((resolvedProducts) => {
+          setProducts(resolvedProducts)
+        })
+      }
     }
     loadProducts()
   }, [router])
@@ -150,6 +154,8 @@ const Checkout = () => {
     window.location.href = payment.data.redirectUrl
   }
 
+  const taxTotal = (totalAmount - totalDiscountAmount) * 0.11
+
   return (
     <>
       <MobileView>
@@ -202,14 +208,14 @@ const Checkout = () => {
             </div>
             <div className='flex gap-x-2 justify-between'>
               <div className='text-gray_r-11'>PPN 11% (Incl.)</div>
-              <div>{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}</div>
+              <div>{currencyFormat(taxTotal)}</div>
             </div>
           </div>
           <hr className='my-4 border-gray_r-6' />
           <div className='flex gap-x-2 justify-between mb-4'>
             <div>Grand Total</div>
             <div className='font-semibold text-gray_r-12'>
-              {currencyFormat(totalAmount - totalDiscountAmount)}
+              {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}
             </div>
           </div>
           <p className='text-caption-2 text-gray_r-10 mb-2'>*) Belum termasuk biaya pengiriman</p>
@@ -232,31 +238,6 @@ const Checkout = () => {
 
         <Divider />
 
-        <div className='p-4'>
-          <div className='font-medium mb-4'>Metode Pembayaran</div>
-          <div className='flex flex-col gap-y-3'>
-            <div
-              className={`p-2 idt-transition border rounded text-gray_r-12/80 ${
-                paymentMethod == 'manual' ? 'border-yellow_r-8 bg-yellow_r-2' : 'border-gray_r-6'
-              }`}
-              onClick={() => setPaymentMethod('manual')}
-            >
-              Bank BCA (PT. Indoteknik Dotcom)
-              <div className='mt-1'>8870-4000-81</div>
-            </div>
-            <div
-              className={`p-2 idt-transition border rounded ${
-                paymentMethod == 'midtrans' ? 'border-yellow_r-8 bg-yellow_r-2' : 'border-gray_r-6'
-              }`}
-              onClick={() => setPaymentMethod('midtrans')}
-            >
-              <Image src='/images/payments/midtrans.jpg' alt='Midtrans Payment' />
-            </div>
-          </div>
-        </div>
-
-        <Divider />
-
         <div className='p-4'>
           <div className='font-medium'>Purchase Order</div>
 
@@ -286,7 +267,7 @@ const Checkout = () => {
             onClick={checkout}
             disabled={isLoading || !products || products?.length == 0}
           >
-            {isLoading ? 'Loading...' : 'Bayar'}
+            {isLoading ? 'Loading...' : 'Lanjut Pembayaran'}
           </button>
         </div>
       </MobileView>
@@ -402,8 +383,8 @@ const Checkout = () => {
                   <div>{currencyFormat(totalAmount - totalDiscountAmount)}</div>
                 </div>
                 <div className='flex gap-x-2 justify-between'>
-                  <div className='text-gray_r-11'>PPN 11% (Incl.)</div>
-                  <div>{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}</div>
+                  <div className='text-gray_r-11'>PPN 11%</div>
+                  <div>{currencyFormat(taxTotal)}</div>
                 </div>
               </div>
 
@@ -412,7 +393,7 @@ const Checkout = () => {
               <div className='flex gap-x-2 justify-between mb-4'>
                 <div>Grand Total</div>
                 <div className='font-semibold text-gray_r-12'>
-                  {currencyFormat(totalAmount - totalDiscountAmount)}
+                  {currencyFormat(totalAmount - totalDiscountAmount + taxTotal)}
                 </div>
               </div>
               <p className='text-caption-2 text-gray_r-11 mb-2'>
-- 
cgit v1.2.3

