From c3386e06741165427b50fb7f33682bc0fdcabfce Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 19 Jan 2023 17:14:39 +0700 Subject: Checkout with upload PO --- src/pages/shop/checkout.js | 70 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'src/pages/shop') diff --git a/src/pages/shop/checkout.js b/src/pages/shop/checkout.js index a8645db5..7b37eaad 100644 --- a/src/pages/shop/checkout.js +++ b/src/pages/shop/checkout.js @@ -16,21 +16,24 @@ import { getItemAddress } from "../../helpers/address"; import { useRouter } from "next/router"; import WithAuth from "../../components/WithAuth"; import { toast } from "react-hot-toast"; +import getFileBase64 from "../../helpers/getFileBase64"; export default function Checkout() { const router = useRouter(); - const [auth] = useAuth(); - const [addresses, setAddresses] = useState(null); - const [selectedAddress, setSelectedAddress] = useState({ + const [ auth ] = useAuth(); + const [ addresses, setAddresses ] = useState(null); + const [ poNumber, setPoNumber ] = useState(''); + const [ poFile, setPoFile ] = useState(''); + const [ selectedAddress, setSelectedAddress ] = useState({ shipping: null, invoicing: null }); - const [selectedPayment, setSelectedPayment] = useState(null); - const [products, setProducts] = useState(null); - const [totalPriceBeforeTax, setTotalPriceBeforeTax] = useState(0); - const [totalTaxAmount, setTotalTaxAmount] = useState(0); - const [totalDiscountAmount, setTotalDiscountAmount] = useState(0); - const [finishCheckout, setFinishCheckout] = useState(null); + const [ selectedPayment, setSelectedPayment ] = useState(null); + const [ products, setProducts ] = useState(null); + const [ totalPriceBeforeTax, setTotalPriceBeforeTax ] = useState(0); + const [ totalTaxAmount, setTotalTaxAmount ] = useState(0); + const [ totalDiscountAmount, setTotalDiscountAmount ] = useState(0); + const [ finishCheckout, setFinishCheckout ] = useState(null); const payments = [ { name: 'BCA', number: '8870-4000-81' }, @@ -107,7 +110,7 @@ export default function Checkout() { const submit = async () => { if (!selectedPayment) { - toast.error('Mohon pilih metode pembayaran terlebih dahulu', { + toast.error('Mohon pilih metode pembayaran', { position: 'bottom-center' }); return; @@ -118,7 +121,16 @@ export default function Checkout() { 'partner_shipping_id': selectedAddress.shipping.id, 'partner_invoice_id': selectedAddress.invoicing.id, 'order_line': JSON.stringify(productOrder) - } + }; + if (auth?.company && (!poNumber || !poFile)) { + toast.error('Mohon isi nomor dan file PO', { + position: 'bottom-center' + }); + return; + }; + if (poNumber) data.po_number = poNumber; + if (poFile) data.po_file = await getFileBase64(poFile); + const checkoutToOdoo = await apiOdoo('POST', '/api/v1/sale_order/checkout', data); for (const product of products) { deleteItemCart(product.id); @@ -181,7 +193,7 @@ export default function Checkout() {

{ selectedAddress.shipping.name }

{ selectedAddress.shipping.mobile }

-

{ selectedAddress.shipping.street } { selectedAddress.shipping.street2 }

+

{ selectedAddress.shipping.street }, { selectedAddress.shipping.city.name }

) } @@ -270,7 +282,7 @@ export default function Checkout() {
-

Pilih Metode Pembayaran

+

Metode Pembayaran (Wajib dipilih)

{ payments.map((payment, index) => (