From a49f5a3f968dcc8c84759a382a0762abf0bc758b Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 23 Mar 2023 17:01:03 +0700 Subject: cart, checkout, quotation --- src/lib/checkout/components/Checkout.jsx | 449 ++++++++++++++++++++----------- 1 file changed, 297 insertions(+), 152 deletions(-) (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index ef0b1d54..57d217a7 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -16,8 +16,9 @@ import checkoutApi from '../api/checkoutApi' import { useRouter } from 'next/router' import VariantGroupCard from '@/lib/variant/components/VariantGroupCard' import axios from 'axios' -import Script from 'next/script' import Image from '@/core/components/elements/Image/Image' +import MobileView from '@/core/components/views/MobileView' +import DesktopView from '@/core/components/views/DesktopView' const Checkout = () => { const router = useRouter() @@ -99,17 +100,12 @@ const Checkout = () => { } }, [products]) - const poNumber = useRef('') - const poFile = useRef('') + const poNumber = useRef(null) + const poFile = useRef(null) const [isLoading, setIsLoading] = useState(false) const checkout = async () => { - if (!paymentMethod) { - toast.error('Metode pembayaran harus dipilih', { position: 'bottom-center' }) - return - } - const file = poFile.current.files[0] if (typeof file !== 'undefined' && file.size > 5000000) { toast.error('Maksimal ukuran file adalah 5MB', { position: 'bottom-center' }) @@ -130,179 +126,331 @@ const Checkout = () => { if (typeof file !== 'undefined') data.po_file = await getFileBase64(file) const isCheckouted = await checkoutApi({ data }) - setIsLoading(false) if (!isCheckouted?.id) { toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') return } for (const product of products) deleteItemCart({ productId: product.id }) - if (paymentMethod == 'midtrans') { - const payment = await axios.post( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` - ) - window.location.href = payment.data.redirectUrl - } else { - router.push(`/shop/checkout/finish?order_id=${isCheckouted.name}`) - } + const payment = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` + ) + setIsLoading(false) + window.location.href = payment.data.redirectUrl } return ( <> -
- -
- -
- - Jika mengalami kesulitan dalam melakukan pembelian di website Indoteknik. Hubungi kami - disini - -
-
+ +
+ +
+ +
+ + Jika mengalami kesulitan dalam melakukan pembelian di website Indoteknik. Hubungi kami + disini + +
+
- + - + - + -
- {products && ( - - )} -
+
+ {products && } +
- + -
-
-
Ringkasan Pesanan
-
{products?.length} Barang
-
-
-
-
-
Total Belanja
-
{currencyFormat(totalAmount)}
-
-
-
Total Diskon
-
- {currencyFormat(totalDiscountAmount)}
+
+
+
Ringkasan Pesanan
+
{products?.length} Barang
-
-
Subtotal
-
{currencyFormat(totalAmount - totalDiscountAmount)}
+
+
+
+
Total Belanja
+
{currencyFormat(totalAmount)}
+
+
+
Total Diskon
+
- {currencyFormat(totalDiscountAmount)}
+
+
+
Subtotal
+
{currencyFormat(totalAmount - totalDiscountAmount)}
+
+
+
PPN 11% (Incl.)
+
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
-
-
PPN 11% (Incl.)
-
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
+
+
Grand Total
+
+ {currencyFormat(totalAmount - totalDiscountAmount)} +
+

*) Belum termasuk biaya pengiriman

+

+ Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui{' '} + + Syarat & Ketentuan + {' '} + yang berlaku +

-
-
-
Grand Total
-
- {currencyFormat(totalAmount - totalDiscountAmount)} + + + + + + + +
+
Metode Pembayaran
+
+
setPaymentMethod('manual')} + > + Bank BCA (PT. Indoteknik Dotcom) +
8870-4000-81
+
+
setPaymentMethod('midtrans')} + > + Midtrans Payment +
-

*) Belum termasuk biaya pengiriman

-

- Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui{' '} - - Syarat & Ketentuan - {' '} - yang berlaku -

-
- - - + + +
+
Purchase Order
+ +
+
+ + +
+
+ + +
+
+

Ukuran dokumen PO Maksimal 5MB

+
- + -
-
Metode Pembayaran
-
-
setPaymentMethod('manual')} - > - Bank BCA (PT. Indoteknik Dotcom) -
8870-4000-81
-
-
setPaymentMethod('midtrans')} +
+
+ {isLoading ? 'Loading...' : 'Bayar'} +
-
- - + + + +
+
+ -
-
Purchase Order
+ -
-
- - + + + +
+
Detail Pesanan
+ + + + + + + + + + + {products?.map((product) => ( + + + + + + + ))} + +
Nama ProdukJumlahHargaSubtotal
+
+ {product?.name} +
+
+
+ {product?.parent?.name} +
+
+ {product?.code}{' '} + {product?.attributes.length > 0 + ? `| ${product?.attributes.join(', ')}` + : ''} +
+
+
+ + + {product?.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(product?.price?.price)} +
+
+ {product?.price?.discountPercentage}% +
+
+ )} +
+ {currencyFormat(product?.price?.priceDiscount)} +
+
+
+ {currencyFormat(product?.price?.priceDiscount * product?.quantity)} +
+
+
-
- - + +
+
+
+
Ringkasan Pesanan
+
{products?.length} Barang
+
+ +
+ +
+
+
Total Belanja
+
{currencyFormat(totalAmount)}
+
+
+
Total Diskon
+
- {currencyFormat(totalDiscountAmount)}
+
+
+
Subtotal
+
{currencyFormat(totalAmount - totalDiscountAmount)}
+
+
+
PPN 11% (Incl.)
+
{currencyFormat((totalAmount - totalDiscountAmount) * 0.11)}
+
+
+ +
+ +
+
Grand Total
+
+ {currencyFormat(totalAmount - totalDiscountAmount)} +
+
+

+ *) Belum termasuk biaya pengiriman +

+

+ Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui{' '} + + Syarat & Ketentuan + {' '} + yang berlaku +

+ +
+ +
+ Purchase Order (Opsional) +
+ +
+
+ + +
+
+ + +
+
+

Ukuran dokumen PO Maksimal 5MB

+ +
+ + +
-

Ukuran dokumen PO Maksimal 5MB

-
- - - -
- -
+ ) } @@ -311,10 +459,7 @@ const SectionAddress = ({ address, label, url }) => (
{label}
- + Pilih Alamat Lain
-- cgit v1.2.3