import { DocumentDuplicateIcon, ExclamationCircleIcon } from "@heroicons/react/24/solid"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import Alert from "../../components/Alert"; import AppBar from "../../components/AppBar"; import Image from "../../components/Image"; import Layout from "../../components/Layout"; import LineDivider from "../../components/LineDivider"; import Link from "../../components/Link"; import ProgressBar from "../../components/ProgressBar"; import apiOdoo from "../../helpers/apiOdoo"; import { useAuth } from "../../helpers/auth"; import { getCart } from "../../helpers/cart"; import currencyFormat from "../../helpers/currencyFormat"; import { createSlug } from "../../helpers/slug"; export default function Checkout() { const [auth, setAuth] = useAuth(); const [address, setAddress] = useState(null); const [selectedAddress, setSelectedAddress] = 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 payments = [ { name: 'BCA', number: '8870-4000-81' }, { name: 'MANDIRI', number: '155-0067-6869-75' }, ]; const copyToClipboard = (text) => { navigator.clipboard.writeText(text); }; const changePayment = (index) => { let payment = payments[index]; if (selectedPayment == payment.name) { copyToClipboard(payment.number); toast.success('Nomor bank berhasil disalin', { position: 'bottom-center', duration: 1500 }); } else { toast.success('Metode pembayaran berhasil diubah, tekan sekali lagi untuk salin nomor bank', { position: 'bottom-center', duration: 3000 }); } setSelectedPayment(payment.name); } useEffect(() => { const getAddress = async () => { if (auth?.id) { const dataAddress = await apiOdoo('GET', `/api/v1/user/${auth.id}/address`); setAddress(dataAddress); } }; getAddress(); }, [auth]); useEffect(() => { const getProducts = async () => { let cart = getCart(); let productIds = Object .values(cart) .filter((itemCart) => itemCart.to_process == true) .map((itemCart) => itemCart.product_id); if (productIds.length > 0) { productIds = productIds.join(','); let dataProducts = await apiOdoo('GET', `/api/v1/product_variant/${productIds}`); dataProducts = dataProducts.map((product) => ({ ...product, quantity: cart[product.id].quantity, to_process: cart[product.id].to_process, })); setProducts(dataProducts); } }; getProducts(); }, []); useEffect(() => { if (address) setSelectedAddress(address[0]); }, [address]); useEffect(() => { if (products) { const productsToProcess = products.filter((product) => product.to_process == true); let calculateTotalPriceBeforeTax = 0; let calculateTotalTaxAmount = 0; let calculateTotalDiscountAmount = 0; productsToProcess.forEach(product => { let priceBeforeTax = product.price.price / 1.11; calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity; calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity; calculateTotalDiscountAmount += (product.price.price - product.price.price_discount) * product.quantity; }); setTotalPriceBeforeTax(calculateTotalPriceBeforeTax); setTotalTaxAmount(calculateTotalTaxAmount); setTotalDiscountAmount(calculateTotalDiscountAmount); } }, [products]); return (
Jika mengalami kesulitan dalam melakukan pembelian di website Indoteknik. Hubungi kami disini

Alamat Pengiriman

Ubah Alamat
{ selectedAddress && (

{ selectedAddress.name }

{ selectedAddress.mobile }

{ selectedAddress.street } { selectedAddress.street2 }

) }
{products && products.map((product, index) => (
{product.parent.name}
{product.parent.name}

{product.code || '-'} {product.attributes.length > 0 ? ` | ${product.attributes.join(', ')}` : ''}

{currencyFormat(product.price.price_discount)} × {product.quantity} Barang

{currencyFormat(product.quantity * product.price.price_discount)}

))}
{products && (

Ringkasan Pesanan

{products.length} Barang


Subtotal

{currencyFormat(totalPriceBeforeTax)}

PPN 11%

{currencyFormat(totalTaxAmount)}

Total Diskon

- {currencyFormat(totalDiscountAmount)}


Grand Total

{currencyFormat(totalPriceBeforeTax + totalTaxAmount - totalDiscountAmount)}

*) Belum termasuk biaya pengiriman

Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui Syarat & Ketentuan yang berlaku

)}

Pilih Metode Pembayaran

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