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/helpers/getFileBase64.js | 11 +++++++ src/pages/my/menu.js | 70 +++++++++++++------------------------------- src/pages/shop/checkout.js | 70 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 88 insertions(+), 63 deletions(-) create mode 100644 src/helpers/getFileBase64.js (limited to 'src') diff --git a/src/helpers/getFileBase64.js b/src/helpers/getFileBase64.js new file mode 100644 index 00000000..78013e43 --- /dev/null +++ b/src/helpers/getFileBase64.js @@ -0,0 +1,11 @@ +const getFileBase64 = file => new Promise((resolve, reject) => { + let reader = new FileReader(); + reader.readAsBinaryString(file); + reader.onload = () => { + let result = reader.result; + resolve(btoa(result)); + }; + reader.onerror = error => reject(error); +}); + +export default getFileBase64; \ No newline at end of file diff --git a/src/pages/my/menu.js b/src/pages/my/menu.js index e21b0433..0db6b011 100644 --- a/src/pages/my/menu.js +++ b/src/pages/my/menu.js @@ -7,36 +7,26 @@ import { ArrowRightOnRectangleIcon, ChatBubbleLeftRightIcon, ChevronRightIcon, - ClipboardDocumentIcon, - ClipboardIcon, - ClockIcon, - DocumentArrowDownIcon, MapIcon, PaperClipIcon, PencilSquareIcon, QuestionMarkCircleIcon, ReceiptPercentIcon, - UserIcon + UserIcon, + HeartIcon } from "@heroicons/react/24/outline"; -const activityMenus = [ - { icon: (), name: 'Daftar Transaksi', url: '/my/profile' }, - { icon: (), name: 'Penawaran Harga', url: '/my/profile' }, - { icon: (), name: 'Purchase Order', url: '/my/profile' }, - { icon: (), name: 'Faktur Penjualan', url: '/my/profile' }, - { icon: (), name: 'Faktur Pajak', url: '/my/profile' }, - { icon: (), name: 'Surat Jalan', url: '/my/profile' } -]; - -const serviceMenus = [ - { icon: (), name: 'Customer Support', url: '/my/profile' }, - { icon: (), name: 'F.A.Q', url: '/my/profile' }, -]; - -const settingMenus = [ - { icon: (),name: 'Daftar Alamat', url: '/my/address' }, - { icon: (),name: 'Keluar Akun', url: '/logout' }, -]; +const Menu = ({ icon, name, url }) => { + return ( + + + { icon } + { name } + + + + ); +}; export default function MyMenu() { const [auth] = useAuth(); @@ -64,41 +54,21 @@ export default function MyMenu() {

Aktivitas Pembelian

- { activityMenus.map((menu, index) => ( - - - { menu.icon } - { menu.name } - - - - )) } + } name="Daftar Transaksi" url="/my/transactions" /> + } name="Invoice & Faktur Pajak" url="/my/transactions" /> + } name="Wishlist" url="/my/wishlist" />

Pusat Bantuan

- { serviceMenus.map((menu, index) => ( - - - { menu.icon } - { menu.name } - - - - )) } + } name="Layanan Pelanggan" url="/" /> + } name="F.A.Q" url="/" />

Pengaturan Akun

- { settingMenus.map((menu, index) => ( - - - { menu.icon } - { menu.name } - - - - )) } + } name="Daftar Alamat" url="/my/address" /> + } name="Keluar Akun" url="/logout" />
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) => (