From 0d28dc8ff5fb8c5399e356ed6ecae4fce2019ca6 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 May 2025 08:55:43 +0700 Subject: fix repeat-order --- src/lib/transaction/components/Transactions.jsx | 124 +++++++++++++++++++++--- 1 file changed, 110 insertions(+), 14 deletions(-) (limited to 'src/lib/transaction') diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx index 45821901..c4651119 100644 --- a/src/lib/transaction/components/Transactions.jsx +++ b/src/lib/transaction/components/Transactions.jsx @@ -78,6 +78,8 @@ const Transactions = ({ context = '' }) => { const [dateRange, setDateRange] = useState([null, null]); // const [startDate, endDate] = dateRange; const [isOpenCalender, setIsOpenCalender] = useState(false); + const [cachedAllData, setCachedAllData] = useState(null); // Simpan data "All" + const [currentData, setCurrentData] = useState([]); // Data yang ditampilkan const parseDate = (date) => { if (null || 'null') return null; @@ -263,7 +265,16 @@ const Transactions = ({ context = '' }) => { const getAllData = async () => { const query = { name: q, - context, + offset: (pageNew - 1) * limitNew, + limit: limitNew, + context: contextMap[statusNew], // gunakan contextMap + sort: sortNew, + startDate: state[0]?.startDate + ? state[0].startDate.toLocaleDateString('id-ID') + : null, + endDate: state[0]?.endDate + ? state[0].endDate.toLocaleDateString('id-ID') + : null, site: siteFilter || (auth?.webRole === null && auth?.site ? auth.site : null), }; @@ -345,22 +356,29 @@ const Transactions = ({ context = '' }) => { } }; - const handleStatusChange = (status) => { + + const handleStatusChange = async (status) => { setStatusNew(status); + setPageNew(1); - if (['quotation', 'cancel', 'diterima', ''].includes(status)) { - setcontextNew('quotation'); - } else { - setcontextNew(''); + if (status === 'all' && cachedAllData) { + setCurrentData(cachedAllData); + return; } - + const data = await fetchSite(status, 1); + if (status === 'all') { - router.push(`${router.pathname}`); - } else { - setPageNew(1); + setCachedAllData(data); } + + setCurrentData(data); }; + useEffect(() => { + setCachedAllData([]); + }, []); + + const handleReset = () => { setState([ { @@ -857,9 +875,7 @@ const Transactions = ({ context = '' }) => {

Info Transaksi

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed - do eiusmod tempor incididunt ut labore et dolore magna - aliqua. + Gunakan filter status untuk mempermudah pencarian transaksi anda di Daftar Transaksi
@@ -928,6 +944,86 @@ const Transactions = ({ context = '' }) => { +
+ + {isOpenCalender && ( +
+ {/* Tombol silang di sudut kanan atas */} + + setState([item.selection])} + showSelectionPreview={true} + maxDate={new Date()} + moveRangeOnFirstSelection={false} + months={1} + ranges={state} + className='w-full' + /> + +
+ + +
+
+ )} +

Menampilkan {startItem}- @@ -980,7 +1076,7 @@ const Transactions = ({ context = '' }) => { {transactions.data.saleOrders.map((saleOrder, index) => (