summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-01-25 13:38:59 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-01-25 13:38:59 +0700
commitfbf2043c00f560d6614f282aeb4512364c6c387c (patch)
treef7ab00f845f0cfd4bcfd25c873d69f9bb8aa829f /src/components
parent8081cceafa40ecb84779df0d9eb4555547d99b98 (diff)
optimize render cost
Diffstat (limited to 'src/components')
-rw-r--r--src/components/elements/Disclosure.js2
-rw-r--r--src/components/elements/Skeleton.js2
-rw-r--r--src/components/transactions/TransactionDetail.js56
3 files changed, 53 insertions, 7 deletions
diff --git a/src/components/elements/Disclosure.js b/src/components/elements/Disclosure.js
index 0aaedf87..584fa144 100644
--- a/src/components/elements/Disclosure.js
+++ b/src/components/elements/Disclosure.js
@@ -1,7 +1,7 @@
const { ChevronUpIcon, ChevronDownIcon } = require("@heroicons/react/24/outline");
const Disclosure = ({ label, active, onClick }) => (
- <div className="flex justify-between p-4" onClick={onClick}>
+ <div className={`flex justify-between p-4 ` + (active && 'bg-yellow_r-2')} onClick={onClick}>
<p className="font-medium leading-normal">{ label }</p>
{ onClick && ( active ? (
<ChevronUpIcon className="w-5 h-5" />
diff --git a/src/components/elements/Skeleton.js b/src/components/elements/Skeleton.js
index 843b200f..0a0bbc78 100644
--- a/src/components/elements/Skeleton.js
+++ b/src/components/elements/Skeleton.js
@@ -1,5 +1,5 @@
const SkeletonList = ({ number }) => (
- <div role="status" className="space-y-5 animate-pulse">
+ <div role="status" className="space-y-6 animate-pulse">
{ Array.from(Array(number), (e, i) => (
<div className="flex items-center justify-between" key={i}>
<div>
diff --git a/src/components/transactions/TransactionDetail.js b/src/components/transactions/TransactionDetail.js
index 6d304d31..7659a321 100644
--- a/src/components/transactions/TransactionDetail.js
+++ b/src/components/transactions/TransactionDetail.js
@@ -1,13 +1,15 @@
+import { useState } from "react";
import DescriptionRow from "../elements/DescriptionRow";
+import Disclosure from "../elements/Disclosure";
-const CustomerSection = ({ address }) => {
+const DetailAddress = ({ 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 (
- <div className="px-4 pb-4 flex flex-col gap-y-4">
+ <div className="p-4 flex flex-col gap-y-4">
<DescriptionRow label="Nama">{ address?.name }</DescriptionRow>
<DescriptionRow label="Email">{ address?.email || '-' }</DescriptionRow>
<DescriptionRow label="No Telepon">{ address?.mobile || '-' }</DescriptionRow>
@@ -16,6 +18,50 @@ const CustomerSection = ({ address }) => {
);
};
-export {
- CustomerSection
-}; \ No newline at end of file
+const TransactionDetailAddress = ({ transaction }) => {
+ const [ activeSection, setActiveSection ] = useState({
+ purchase: false,
+ shipping: false,
+ invoice: false,
+ });
+
+ const toggleSection = ( name ) => {
+ setActiveSection({
+ ...activeSection,
+ [name]: !activeSection[name]
+ });
+ };
+
+ return (
+ <div className="m-4 rounded border border-gray_r-6 divide-y divide-gray_r-6">
+ <Disclosure
+ label="Detail Pelanggan"
+ active={activeSection.purchase}
+ onClick={() => toggleSection('purchase')}
+ />
+ { activeSection.purchase && (
+ <DetailAddress address={transaction?.address?.customer} />
+ ) }
+
+ <Disclosure
+ label="Detail Pengiriman"
+ active={activeSection.shipping}
+ onClick={() => toggleSection('shipping')}
+ />
+ { activeSection.shipping && (
+ <DetailAddress address={transaction?.address?.shipping} />
+ ) }
+
+ <Disclosure
+ label="Detail Penagihan"
+ active={activeSection.invoice}
+ onClick={() => toggleSection('invoice')}
+ />
+ { activeSection.invoice && (
+ <DetailAddress address={transaction?.address?.invoice} />
+ ) }
+ </div>
+ );
+};
+
+export { TransactionDetailAddress }; \ No newline at end of file