From ebc09c5062cc7996b0f2aaf879062fc950c2e1c2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 25 Jan 2023 11:17:37 +0700 Subject: Transaction detail and variant card component --- src/components/elements/DescriptionRow.js | 10 ++ src/components/elements/Disclosure.js | 14 +++ src/components/transactions/TransactionDetail.js | 21 ++++ src/components/variants/VariantCard.js | 48 +++++++++ src/pages/my/transactions/[id].js | 124 ++++++++++++++++++++++ src/pages/my/transactions/[slug].js | 126 ----------------------- src/pages/shop/checkout.js | 30 ++---- src/styles/globals.css | 4 + 8 files changed, 227 insertions(+), 150 deletions(-) create mode 100644 src/components/elements/DescriptionRow.js create mode 100644 src/components/elements/Disclosure.js create mode 100644 src/components/transactions/TransactionDetail.js create mode 100644 src/components/variants/VariantCard.js create mode 100644 src/pages/my/transactions/[id].js delete mode 100644 src/pages/my/transactions/[slug].js diff --git a/src/components/elements/DescriptionRow.js b/src/components/elements/DescriptionRow.js new file mode 100644 index 00000000..7fe9e3a1 --- /dev/null +++ b/src/components/elements/DescriptionRow.js @@ -0,0 +1,10 @@ +const DescriptionRow = ({ label, children }) => ( +
+

{ label }

+
+ { children } +
+
+); + +export default DescriptionRow; \ No newline at end of file diff --git a/src/components/elements/Disclosure.js b/src/components/elements/Disclosure.js new file mode 100644 index 00000000..0aaedf87 --- /dev/null +++ b/src/components/elements/Disclosure.js @@ -0,0 +1,14 @@ +const { ChevronUpIcon, ChevronDownIcon } = require("@heroicons/react/24/outline"); + +const Disclosure = ({ label, active, onClick }) => ( +
+

{ label }

+ { onClick && ( active ? ( + + ) : ( + + ) ) } +
+); + +export default Disclosure; \ No newline at end of file diff --git a/src/components/transactions/TransactionDetail.js b/src/components/transactions/TransactionDetail.js new file mode 100644 index 00000000..6d304d31 --- /dev/null +++ b/src/components/transactions/TransactionDetail.js @@ -0,0 +1,21 @@ +import DescriptionRow from "../elements/DescriptionRow"; + +const CustomerSection = ({ address }) => { + const 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); + return ( +
+ { address?.name } + { address?.email || '-' } + { address?.mobile || '-' } + { fullAddress.join(', ') } +
+ ); +}; + +export { + CustomerSection +}; \ No newline at end of file diff --git a/src/components/variants/VariantCard.js b/src/components/variants/VariantCard.js new file mode 100644 index 00000000..cb4d8272 --- /dev/null +++ b/src/components/variants/VariantCard.js @@ -0,0 +1,48 @@ +import { createSlug } from "@/core/utils/slug"; +import Image from "../elements/Image"; +import Link from "../elements/Link"; +import currencyFormat from "@/core/utils/currencyFormat"; + +export default function VariantCard({ + data, + openOnClick = true +}) { + let product = data; + + const Card = () => ( +
+
+ {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)} +

+
+
+ ); + + if (openOnClick) { + return ( + + + + ); + } + + return ; +} \ No newline at end of file diff --git a/src/pages/my/transactions/[id].js b/src/pages/my/transactions/[id].js new file mode 100644 index 00000000..79337a29 --- /dev/null +++ b/src/pages/my/transactions/[id].js @@ -0,0 +1,124 @@ +import AppBar from "@/components/layouts/AppBar"; +import Layout from "@/components/layouts/Layout"; +import LineDivider from "@/components/elements/LineDivider"; +import WithAuth from "@/components/auth/WithAuth"; +import { useEffect, useState } from "react"; +import apiOdoo from "@/core/utils/apiOdoo"; +import { useRouter } from "next/router"; +import { useAuth } from "@/core/utils/auth"; +import VariantCard from "@/components/variants/VariantCard"; +import currencyFormat from "@/core/utils/currencyFormat"; +import Disclosure from "@/components/elements/Disclosure"; +import DescriptionRow from "@/components/elements/DescriptionRow"; +import { CustomerSection } from "@/components/transactions/TransactionDetail"; + +export default function DetailTransactions() { + const router = useRouter(); + const { id } = router.query; + const [ auth ] = useAuth(); + const [ transaction, setTransaction ] = useState(null); + const [ activeSection, setActiveSection ] = useState({ + purchase: false, + shipping: false, + invoice: false, + }); + + const toggleSection = ( name ) => { + setActiveSection({ + ...activeSection, + [name]: !activeSection[name] + }); + }; + + useEffect(() => { + if (auth) { + const loadTransaction = async () => { + const dataTransaction = await apiOdoo('GET', `/api/v1/partner/${auth?.partner_id}/sale_order/${id}`); + setTransaction(dataTransaction); + } + loadTransaction(); + } + }, [ auth, id ]); + + return ( + + + + +
+ + Pending Quotation + + + { transaction?.name } + + + { transaction?.po_name || '-' } + + + { transaction?.payment_term } + + + { transaction?.sales } + + + { transaction?.date_order } + +
+ + + + + +
+ { transaction?.products?.map((product, index) => ( + + )) } +
+

Total Belanja

+

{ currencyFormat(transaction?.amount_total || 0) }

+
+
+ + + + + toggleSection('purchase')} + /> + { activeSection.purchase && ( + + ) } + + + + toggleSection('shipping')} + /> + { activeSection.shipping && ( + + ) } + + + + toggleSection('invoice')} + /> + { activeSection.invoice && ( + + ) } +
+
+ ); +} \ No newline at end of file diff --git a/src/pages/my/transactions/[slug].js b/src/pages/my/transactions/[slug].js deleted file mode 100644 index a76b0c4d..00000000 --- a/src/pages/my/transactions/[slug].js +++ /dev/null @@ -1,126 +0,0 @@ -import { ArrowDownOnSquareIcon, ArrowDownTrayIcon, ChevronDownIcon, ChevronRightIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; -import AppBar from "@/components/layouts/AppBar"; -import Layout from "@/components/layouts/Layout"; -import LineDivider from "@/components/elements/LineDivider"; -import WithAuth from "@/components/auth/WithAuth"; -import { useState } from "react"; - -const Row = ({ label, children }) => ( -
-

{ label }

-
- { children } -
-
-); - -const Section = ({ children }) => ( -
- { children } -
-); - -const TitleRow = ({ label, active, onClick }) => ( -
-

{ label }

- { onClick && ( active ? ( - - ) : ( - - ) ) } -
-); - -export default function DetailTransactions() { - const [ activeSection, setActiveSection ] = useState({ - purchase: false, - shipping: false, - invoice: false, - }); - - const toggleSection = ( name ) => { - setActiveSection({ - ...activeSection, - [name]: !activeSection[name] - }); - }; - - return ( - - - - -
-
- - Pending Quotation - - SO/2023/03212 - PO/2023/02123 - Download - BCA Transfer - Cash Before Delivery - Rafi Zadanly - 01 Januari 2023 -
- - - - - - - - toggleSection('purchase')} - /> - { activeSection.purchase && ( -
- John Doe - johndoe@gmail.com - 081223538754 - Jalan Bandengan Utara No 85A, Kel. Penjaringan, Kec. Penjaringan, Jakarta Utara -
- ) } - - - - toggleSection('shipping')} - /> - { activeSection.shipping && ( -
- John Doe - johndoe@gmail.com - 081223538754 - Jalan Bandengan Utara No 85A, Kel. Penjaringan, Kec. Penjaringan, Jakarta Utara -
- ) } - - - - toggleSection('invoice')} - /> - { activeSection.invoice && ( -
- John Doe - johndoe@gmail.com - 081223538754 - Jalan Bandengan Utara No 85A, Kel. Penjaringan, Kec. Penjaringan, Jakarta Utara -
- ) } - -
-
-
- ); -} \ No newline at end of file diff --git a/src/pages/shop/checkout.js b/src/pages/shop/checkout.js index 1849e0fe..49d1a848 100644 --- a/src/pages/shop/checkout.js +++ b/src/pages/shop/checkout.js @@ -17,6 +17,7 @@ import { useRouter } from "next/router"; import WithAuth from "@/components/auth/WithAuth"; import { toast } from "react-hot-toast"; import getFileBase64 from "@/core/utils/getFileBase64"; +import VariantCard from "@/components/variants/VariantCard"; export default function Checkout() { const router = useRouter(); @@ -201,30 +202,11 @@ export default function Checkout() {
{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)} -

-
-
+ ))}
diff --git a/src/styles/globals.css b/src/styles/globals.css index 6c0a7607..e43ad1a9 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -4,6 +4,10 @@ @tailwind components; @tailwind utilities; +* { + -webkit-tap-highlight-color: transparent; +} + html, body { @apply w-screen -- cgit v1.2.3