summaryrefslogtreecommitdiff
path: root/src/lib/checkout
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-28 16:32:45 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-28 16:32:45 +0700
commitf15a7f8a4387d215abd1051ee520adca8944fa05 (patch)
treea51a50ba27a53ff03da38c388e36a17149ad60fa /src/lib/checkout
parent8ca9069251873e87338f1c7f581b418bebb11e9a (diff)
checkout, quotation
Diffstat (limited to 'src/lib/checkout')
-rw-r--r--src/lib/checkout/components/Checkout.jsx53
1 files changed, 17 insertions, 36 deletions
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>
@@ -233,31 +239,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>
<div className='mt-4 flex gap-x-3'>
@@ -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'>