From ed950b23d50f9b3993cfd2ac2386a5b3a68d5e57 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 20 Feb 2023 17:03:28 +0700 Subject: fix --- src/core/components/elements/Sidebar/Sidebar.jsx | 37 +++-- src/core/components/layouts/AnimationLayout.jsx | 2 +- src/core/components/layouts/AppLayout.jsx | 2 +- src/core/hooks/useAuth.js | 3 +- src/lib/transaction/api/cancelTransactionApi.js | 8 ++ src/lib/transaction/api/transactionsApi.js | 8 ++ .../components/TransactionStatusBadge.jsx | 45 +++++++ src/lib/transaction/components/Transactions.jsx | 149 +++++++++++++++++++++ src/lib/transaction/hooks/useTransactions.js | 15 +++ src/lib/transaction/utils/transactions.js | 14 ++ src/pages/my/menu.jsx | 94 +++++++++++++ src/pages/my/transactions.jsx | 12 ++ 12 files changed, 373 insertions(+), 16 deletions(-) create mode 100644 src/lib/transaction/api/cancelTransactionApi.js create mode 100644 src/lib/transaction/api/transactionsApi.js create mode 100644 src/lib/transaction/components/TransactionStatusBadge.jsx create mode 100644 src/lib/transaction/components/Transactions.jsx create mode 100644 src/lib/transaction/hooks/useTransactions.js create mode 100644 src/lib/transaction/utils/transactions.js create mode 100644 src/pages/my/menu.jsx create mode 100644 src/pages/my/transactions.jsx diff --git a/src/core/components/elements/Sidebar/Sidebar.jsx b/src/core/components/elements/Sidebar/Sidebar.jsx index 74984393..412ed915 100644 --- a/src/core/components/elements/Sidebar/Sidebar.jsx +++ b/src/core/components/elements/Sidebar/Sidebar.jsx @@ -1,13 +1,22 @@ -import { getAuth } from "@/core/utils/auth" import Link from "../Link/Link" import greeting from "@/core/utils/greeting" import { Cog6ToothIcon } from "@heroicons/react/24/solid" +import useAuth from "@/core/hooks/useAuth" const Sidebar = ({ active, close }) => { - const auth = getAuth() + const auth = useAuth() + + const SidebarLink = ({ children, ...props }) => ( + { children } + ) + + const itemClassName = 'px-4 py-3 block !text-gray_r-12/80 font-normal' return ( <> @@ -24,29 +33,31 @@ const Sidebar = ({ { auth && ( <>
- {/* { greeting() }, */} + { greeting() }, { auth?.name }
- + ) } - + Semua Brand - - + + Tentang Indoteknik - - + + Pusat Bantuan - - - Kategori - + + diff --git a/src/core/components/layouts/AnimationLayout.jsx b/src/core/components/layouts/AnimationLayout.jsx index adb6b081..cf2b06d5 100644 --- a/src/core/components/layouts/AnimationLayout.jsx +++ b/src/core/components/layouts/AnimationLayout.jsx @@ -2,7 +2,7 @@ import { motion } from 'framer-motion' const AnimationLayout = ({ children, ...props }) => { const transition = { - ease: 'easeOut', + ease: 'easeIn', duration: 0.3 } diff --git a/src/core/components/layouts/AppLayout.jsx b/src/core/components/layouts/AppLayout.jsx index 7aaa52ca..3e986477 100644 --- a/src/core/components/layouts/AppLayout.jsx +++ b/src/core/components/layouts/AppLayout.jsx @@ -4,8 +4,8 @@ import AnimationLayout from "./AnimationLayout" const AppLayout = ({ children, title }) => { return ( <> - + { children } diff --git a/src/core/hooks/useAuth.js b/src/core/hooks/useAuth.js index 488562f6..13f04454 100644 --- a/src/core/hooks/useAuth.js +++ b/src/core/hooks/useAuth.js @@ -1,3 +1,4 @@ +import { useEffect, useState } from "react" import { getAuth } from "../utils/auth" const useAuth = () => { @@ -8,7 +9,7 @@ const useAuth = () => { handleIsAuthenticated() }, []) - return [auth, setAuth] + return auth } export default useAuth \ No newline at end of file diff --git a/src/lib/transaction/api/cancelTransactionApi.js b/src/lib/transaction/api/cancelTransactionApi.js new file mode 100644 index 00000000..19891b5a --- /dev/null +++ b/src/lib/transaction/api/cancelTransactionApi.js @@ -0,0 +1,8 @@ +import odooApi from "@/core/api/odooApi" + +const cancelTransactionApi = async ({ partnerId, transaction }) => { + const dataCancelTransaction = await odooApi('POST', `/api/v1/partner/${partnerId}/sale_order/${transaction.id}/cancel`) + return dataCancelTransaction +} + +export default cancelTransactionApi \ No newline at end of file diff --git a/src/lib/transaction/api/transactionsApi.js b/src/lib/transaction/api/transactionsApi.js new file mode 100644 index 00000000..d36c3664 --- /dev/null +++ b/src/lib/transaction/api/transactionsApi.js @@ -0,0 +1,8 @@ +import odooApi from "@/core/api/odooApi" + +const transactionsApi = async ({partnerId, query}) => { + const dataTransactions = await odooApi('GET', `/api/v1/partner/${partnerId}/sale_order?${query}`) + return dataTransactions +} + +export default transactionsApi \ No newline at end of file diff --git a/src/lib/transaction/components/TransactionStatusBadge.jsx b/src/lib/transaction/components/TransactionStatusBadge.jsx new file mode 100644 index 00000000..28fe714a --- /dev/null +++ b/src/lib/transaction/components/TransactionStatusBadge.jsx @@ -0,0 +1,45 @@ +const TransactionStatusBadge = ({ status }) => { + let badgeProps = { + className: ['h-fit'], + text: '' + } + switch (status) { + case 'cancel': + badgeProps.className.push('badge-solid-red') + badgeProps.text = 'Pesanan batal' + break + case 'draft': + badgeProps.className.push('badge-red') + badgeProps.text = 'Pending quotation' + break + case 'waiting': + badgeProps.className.push('badge-yellow') + badgeProps.text = 'Pesanan diterima' + break + case 'sale': + badgeProps.className.push('badge-yellow') + badgeProps.text = 'Pesanan diproses' + break + case 'shipping': + badgeProps.className.push('badge-green') + badgeProps.text = 'Pesanan dikirim' + break + case 'partial_shipping': + badgeProps.className.push('badge-green') + badgeProps.text = 'Dikirim sebagian' + break + case 'done': + badgeProps.className.push('badge-solid-green') + badgeProps.text = 'Pesanan selesai' + break + } + badgeProps.className = badgeProps.className.join(' ') + + return ( +
+ { badgeProps.text } +
+ ) +} + +export default TransactionStatusBadge \ No newline at end of file diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx new file mode 100644 index 00000000..97eb5f91 --- /dev/null +++ b/src/lib/transaction/components/Transactions.jsx @@ -0,0 +1,149 @@ +import { useRouter } from "next/router" +import { getAuth } from "@/core/utils/auth" +import { useState } from "react" +import { toast } from "react-hot-toast" +import { EllipsisVerticalIcon } from "@heroicons/react/24/outline" + +import { downloadPurchaseOrder, downloadQuotation } from "../utils/transactions" +import useTransactions from "../hooks/useTransactions" +import currencyFormat from "@/core/utils/currencyFormat" +import cancelTransactionApi from "../api/cancelTransactionApi" +import TransactionStatusBadge from "./TransactionStatusBadge" +import Spinner from "@/core/components/elements/Spinner/Spinner" +import Link from "@/core/components/elements/Link/Link" +import BottomPopup from "@/core/components/elements/Popup/BottomPopup" + +const Transactions = () => { + const auth = getAuth() + const router = useRouter() + const { + q = '', + page = 1 + } = router.query + + const { transactions } = useTransactions({ + partnerId: auth?.partnerId, + query: { + name: q, + limit: 30, + offset: (page - 1) * 30 + } + }) + + const [ toOthers, setToOthers ] = useState(null) + const [ toDelete, setToDelete ] = useState(null) + + const submitCancelTransaction = async () => { + const isCancelled = await cancelTransactionApi({ + partnerId: auth.partnerId, + transaction: toDelete + }) + if (isCancelled) { + toast.success('Berhasil batalkan transaksi') + transactions.refetch() + } + setToDelete(null) + } + + return ( +
+
+ { transactions.isLoading && ( +
+ +
+ ) } + { transactions.data?.saleOrders?.map((saleOrder, index) => ( +
+
+ + No. Transaksi +

{ saleOrder.name }

+ +
+ + setToOthers(saleOrder)} /> +
+
+ +
+
+ No. Purchase Order +

{ saleOrder.purchaseOrderName || '-' }

+
+
+ Total Invoice +

{ saleOrder.invoiceCount } Invoice

+
+
+
+
+ Sales +

{ saleOrder.sales }

+
+
+ Total Harga +

{ currencyFormat(saleOrder.amountTotal) }

+
+
+ +
+ )) } +
+ + setToOthers(null)}> +
+ + + +
+
+ + setToDelete(null)} + title="Batalkan Transaksi" + > +
+ Apakah anda yakin membatalkan transaksi {toDelete?.name}? +
+
+ + +
+
+
+ ) +} + +export default Transactions \ No newline at end of file diff --git a/src/lib/transaction/hooks/useTransactions.js b/src/lib/transaction/hooks/useTransactions.js new file mode 100644 index 00000000..b5742cae --- /dev/null +++ b/src/lib/transaction/hooks/useTransactions.js @@ -0,0 +1,15 @@ +import { useQuery } from "react-query" +import transactionsApi from "../api/transactionsApi" +import _ from "lodash-contrib" + +const useTransactions = ({ partnerId, query }) => { + const queryString = _.toQuery(query) + const fetchTransactions = async () => await transactionsApi({ partnerId, query: queryString }) + const { data, isLoading, refetch } = useQuery(`transactions-${queryString}`, fetchTransactions) + + return { + transactions: { data, isLoading, refetch } + } +} + +export default useTransactions \ No newline at end of file diff --git a/src/lib/transaction/utils/transactions.js b/src/lib/transaction/utils/transactions.js new file mode 100644 index 00000000..166e8a7e --- /dev/null +++ b/src/lib/transaction/utils/transactions.js @@ -0,0 +1,14 @@ +const downloadPurchaseOrder = (partnerId, transaction) => { + const url = `${process.env.ODOO_HOST}/api/v1/partner/${partnerId}/sale_order/${transaction.id}/download_po/${transaction.token}` + window.open(url, 'download') +} + +const downloadQuotation = (partnerId, transaction) => { + const url = `${process.env.ODOO_HOST}/api/v1/partner/${partnerId}/sale_order/${transaction.id}/download/${transaction.token}` + window.open(url, 'download') +} + +export { + downloadPurchaseOrder, + downloadQuotation +} \ No newline at end of file diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx new file mode 100644 index 00000000..d3edaa3b --- /dev/null +++ b/src/pages/my/menu.jsx @@ -0,0 +1,94 @@ +import Divider from "@/core/components/elements/Divider/Divider" +import Link from "@/core/components/elements/Link/Link" +import AppLayout from "@/core/components/layouts/AppLayout" +import { ChevronRightIcon, UserIcon } from "@heroicons/react/24/solid" + +export default function Menu() { + return ( + + +
+ +
+
+
Rafi Zadanly
+
Akun Bisnis
+
+
+ +
+ + + + +
+
+ + Aktivitas Pembelian + + +
+ + Daftar Transaksi + + + Invoice & Faktur Pajak + + + Wishlist + +
+
+ +
+ + Pusat Bantuan + + +
+ + Customer Support + + + F.A.Q + +
+
+ +
+ + Pengaturan Akun + + +
+ + Daftar Alamat + + + Ubah Password + + + Keluar Akun + +
+
+
+
+ ) +} + +const MenuHeader = ({ children, ...props }) => ( +
+ { children } + +
+) + +const LinkItem = ({ children, ...props }) => ( + + { children } +
+ +
+ +) \ No newline at end of file diff --git a/src/pages/my/transactions.jsx b/src/pages/my/transactions.jsx new file mode 100644 index 00000000..a530afcc --- /dev/null +++ b/src/pages/my/transactions.jsx @@ -0,0 +1,12 @@ +import AppLayout from "@/core/components/layouts/AppLayout" +import dynamic from "next/dynamic" + +const TransactionsComponent = dynamic(() => import("@/lib/transaction/components/Transactions")) + +export default function Transactions() { + return ( + + + + ) +} \ No newline at end of file -- cgit v1.2.3