From 7265295454801c1d921385a4b67fb3780b46771e Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 14:00:00 +0700 Subject: fix --- src/lib/checkout/components/Checkout.jsx | 36 +++++++++++++++++++++++--- src/lib/checkout/components/FinishCheckout.jsx | 30 +++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/lib/checkout/components/FinishCheckout.jsx (limited to 'src/lib/checkout/components') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 0a3949c3..8416cd9e 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -9,11 +9,15 @@ import VariantCard from '@/lib/variant/components/VariantCard' import { ExclamationCircleIcon } from '@heroicons/react/24/outline' import { useEffect, useRef, useState } from 'react' import _ from 'lodash' -import { getCart, getItemCart } from '@/core/utils/cart' +import { deleteItemCart, getCart, getItemCart } from '@/core/utils/cart' import currencyFormat from '@/core/utils/currencyFormat' import { toast } from 'react-hot-toast' +import getFileBase64 from '@/core/utils/getFileBase64' +import checkoutApi from '../api/checkoutApi' +import { useRouter } from 'next/router' const Checkout = () => { + const router = useRouter() const auth = useAuth() const [selectedAddress, setSelectedAddress] = useState({ shipping: null, @@ -96,6 +100,33 @@ const Checkout = () => { toast.error('Pilih metode pembayaran', { 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' }) + return + } + setIsLoading(true) + const productOrder = products.map((product) => ({ + product_id: product.id, + quantity: product.quantity + })) + let data = { + partner_shipping_id: selectedAddress.shipping.id, + partner_invoice_id: selectedAddress.invoicing.id, + order_line: JSON.stringify(productOrder), + type: 'sale_order' + } + if (poNumber.current.value) data.po_number = poNumber.current.value + if (typeof file !== 'undefined') data.po_file = await getFileBase64(file) + + const isCheckouted = await checkoutApi({ data }) + setIsLoading(false) + if (isCheckouted?.id) { + for (const product of products) deleteItemCart({ productId: product.id }) + router.push(`/shop/checkout/finish?id=${isCheckouted.id}`) + return + } + toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') } return ( @@ -232,8 +263,7 @@ const Checkout = () => {
diff --git a/src/lib/checkout/components/FinishCheckout.jsx b/src/lib/checkout/components/FinishCheckout.jsx new file mode 100644 index 00000000..f0aaba4e --- /dev/null +++ b/src/lib/checkout/components/FinishCheckout.jsx @@ -0,0 +1,30 @@ +import Link from "@/core/components/elements/Link/Link" +import useTransaction from "@/lib/transaction/hooks/useTransaction" + +const FinishCheckout = ({ id }) => { + const { transaction } = useTransaction({ id }) + + return ( +
+
+
+

Terima Kasih atas Pembelian Anda

+

+ Rincian belanja sudah kami kirimkan ke email anda. Mohon dicek kembali. jika tidak + menerima email, anda dapat menghubungi kami disini. +

+

{transaction.data?.name}

+

No. Transaksi

+
+ + Lihat detail pembelian Anda disini + +
+
+ ) +} + +export default FinishCheckout \ No newline at end of file -- cgit v1.2.3