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/cart/components/Cart.jsx | 6 +- src/lib/transaction/api/checkoutPoApi.js | 10 ++ src/lib/transaction/components/Transaction.jsx | 191 +++++++++++++++++++++++- src/lib/transaction/components/Transactions.jsx | 3 +- src/pages/my/menu.jsx | 24 ++- 5 files changed, 224 insertions(+), 10 deletions(-) create mode 100644 src/lib/transaction/api/checkoutPoApi.js (limited to 'src') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index bb1f21f6..e7606582 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -141,7 +141,7 @@ const Cart = () => { {product?.name} @@ -182,7 +182,7 @@ const Cart = () => { - updateQuantity(e.target.value, product?.id)} @@ -213,7 +213,7 @@ const Cart = () => {
Total: - { selectedProduct().length > 0 ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) : ' - ' } +  { selectedProduct().length > 0 ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) : '-' }
diff --git a/src/lib/transaction/api/checkoutPoApi.js b/src/lib/transaction/api/checkoutPoApi.js new file mode 100644 index 00000000..aed43cff --- /dev/null +++ b/src/lib/transaction/api/checkoutPoApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const checkoutPoApi = async ({ id }) => { + const auth = getAuth() + const dataCheckout = await odooApi('POST', `/api/v1/partner/${auth?.partnerId}/sale_order/${id}/checkout`) + return dataCheckout +} + +export default checkoutPoApi \ No newline at end of file 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 } diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx index 246a4a2c..25a6076a 100644 --- a/src/lib/transaction/components/Transactions.jsx +++ b/src/lib/transaction/components/Transactions.jsx @@ -38,7 +38,6 @@ const Transactions = () => { const submitCancelTransaction = async () => { const isCancelled = await cancelTransactionApi({ - partnerId: auth.partnerId, transaction: toCancel }) if (isCancelled) { @@ -171,7 +170,7 @@ const Transactions = () => { diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx index d3edaa3b..69e4b8bb 100644 --- a/src/pages/my/menu.jsx +++ b/src/pages/my/menu.jsx @@ -1,9 +1,20 @@ import Divider from "@/core/components/elements/Divider/Divider" import Link from "@/core/components/elements/Link/Link" import AppLayout from "@/core/components/layouts/AppLayout" +import useAuth from "@/core/hooks/useAuth" +import { deleteAuth } from "@/core/utils/auth" import { ChevronRightIcon, UserIcon } from "@heroicons/react/24/solid" +import { useRouter } from "next/router" export default function Menu() { + const auth = useAuth() + const router = useRouter() + + const logout = () => { + deleteAuth() + router.push('/login') + } + return ( @@ -11,8 +22,13 @@ export default function Menu() {
-
Rafi Zadanly
-
Akun Bisnis
+
{ auth?.name }
+ { auth?.company && ( +
Akun Bisnis
+ ) } + { !auth?.company && ( +
Akun Individu
+ ) }
@@ -67,9 +83,9 @@ export default function Menu() { Ubah Password - +
Keluar Akun - +
-- cgit v1.2.3