From 3f2ff1475676ba47a841796e39e7d17d627e5356 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 21 Feb 2023 14:46:24 +0700 Subject: fix --- src/lib/transaction/components/Transaction.jsx | 191 ++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 1 deletion(-) (limited to 'src/lib/transaction/components/Transaction.jsx') diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index c9bdf715..143b24bb 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -3,13 +3,18 @@ import useTransaction from "../hooks/useTransaction" import TransactionStatusBadge from "./TransactionStatusBadge" import Divider from "@/core/components/elements/Divider/Divider" import { useRef, useState } from "react" -import { downloadPurchaseOrder } from "../utils/transactions" +import { downloadPurchaseOrder, downloadQuotation } from "../utils/transactions" import BottomPopup from "@/core/components/elements/Popup/BottomPopup" import uploadPoApi from "../api/uploadPoApi" import { toast } from "react-hot-toast" import getFileBase64 from "@/core/utils/getFileBase64" import currencyFormat from "@/core/utils/currencyFormat" import VariantGroupCard from "@/lib/variant/components/VariantGroupCard" +import { ChevronDownIcon, ChevronRightIcon, ChevronUpIcon } from "@heroicons/react/24/outline" +import Link from "@/core/components/elements/Link/Link" +import Alert from "@/core/components/elements/Alert/Alert" +import checkoutPoApi from "../api/checkoutPoApi" +import cancelTransactionApi from "../api/cancelTransactionApi" const Transaction = ({ id }) => { const { transaction } = useTransaction({ id }) @@ -41,6 +46,37 @@ const Transaction = ({ id }) => { toast.error('Terjadi kesalahan internal, coba lagi nanti atau hubungi kami') } + const [ section, setSection ] = useState({ + customer: false, + invoice: false, + shipping: false + }) + const toggleSection = (name) => { + setSection({ ...section, [name]: !section[name] }) + } + + const [ cancelTransaction, setCancelTransaction ] = useState(false) + const openCancelTransaction = () => setCancelTransaction(true) + const closeCancelTransaction = () => setCancelTransaction(false) + const submitCancelTransaction = async () => { + const isCancelled = await cancelTransactionApi({ transaction: transaction.data }) + if (isCancelled) { + toast.success('Berhasil batalkan transaksi') + transaction.refetch() + } + closeCancelTransaction() + } + + const checkout = async () => { + if (!transaction.data?.purchaseOrderFile) { + toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan') + return + } + await checkoutPoApi({ id }) + toast.success('Berhasil melanjutkan pesanan') + transaction.refetch() + } + return ( <> { transaction.isLoading && ( @@ -105,6 +141,122 @@ const Transaction = ({ id }) => { + + toggleSection('customer')} + /> + + { section.customer && } + + + + toggleSection('shipping')} + /> + + { section.shipping && } + + + + toggleSection('invoice')} + /> + + { section.invoice && } + + + +
+

Invoice

+
+ { transaction.data?.invoices?.map((invoice, index) => ( + +
+
+

{ invoice?.name }

+
+ { invoice.amountResidual > 0 ? ( +
Belum Lunas
+ ) : ( +
Lunas
+ ) } +

+ { currencyFormat(invoice.amountTotal) } +

+
+
+ +
+ + )) } + { transaction.data?.invoices?.length === 0 && ( + + Belum ada Invoice + + ) } +
+
+ + + +
+ { transaction.data?.status == 'draft' && ( + + ) } + + { transaction.data?.status != 'draft' && ( + + ) } +
+ + +
+ Apakah anda yakin membatalkan transaksi {transaction.data?.name}? +
+
+ + +
+
{ ) } +const SectionButton = ({ label, active, toggle }) => ( + +) + +const SectionContent = ({ address }) => { + let fullAddress = [] + if (address?.street) fullAddress.push(address.street) + if (address?.sub_district?.name) fullAddress.push(address.sub_district.name) + if (address?.district?.name) fullAddress.push(address.district.name) + if (address?.city?.name) fullAddress.push(address.city.name) + fullAddress = fullAddress.join(', ') + + return ( +
+ + { address.name } + + + { address.email || '-' } + + + { address.mobile || '-' } + + + { fullAddress } + +
+ ) +} + const DescriptionRow = ({ children, label }) => (
{ label } -- cgit v1.2.3