From e38dff05fd629ef054d571e7d3b066f1bdd5520b Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 10 Mar 2025 11:21:46 +0700
Subject: <iman> add sort filter

---
 src/lib/transaction/components/Transactions.jsx | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

(limited to 'src/lib/transaction/components/Transactions.jsx')

diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index 2ef50dcb..a6cfe177 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -44,6 +44,7 @@ const Transactions = ({ context = '' }) => {
     site = null,
     limit = 15,
     status = 'all',
+    sort = 'none',
   } = router.query;
   const {
     productCart,
@@ -63,6 +64,7 @@ const Transactions = ({ context = '' }) => {
   const [limitNew, setLimitNew] = useState(limit);
   // const [status, setStatus] = useState('idle');
   const [statusNew, setStatusNew] = useState(status);
+  const [sortNew, setSortNew] = useState(sort);
   const [contextNew, setcontextNew] = useState(router.query.context || context);
   const query = {
     name: q,
@@ -70,6 +72,7 @@ const Transactions = ({ context = '' }) => {
     context: contextNew,
     limit: limitNew,
     status: statusNew,
+    sort: sortNew,
     site:
       siteFilter || (auth?.webRole === null && auth?.site ? auth.site : null),
   };
@@ -84,6 +87,12 @@ const Transactions = ({ context = '' }) => {
     { id: 'cancel', label: 'Pesanan Dibatalkan' },
   ];
 
+  const sortes = [
+    { id: 'none', label: 'Urutkan' },
+    { id: 'asc', label: 'dari yang terkecil' },
+    { id: 'desc', label: 'dari yang terbesar' },
+  ];
+
   const { transactions } = useTransactions({ query });
   const fetchSite = async () => {
     const site = await getSite();
@@ -338,11 +347,11 @@ const Transactions = ({ context = '' }) => {
               ))}
             </select>
             <select
-              value={statusNew}
-              onChange={(e) => handleStatusChange(e.target.value)}
+              value={sortNew}
+              onChange={(e) => setSortNew(e.target.value)}
               className='border border-gray-300 rounded-lg px-3 py-1 text-sm bg-white shadow-sm focus:outline-none focus:ring-2 focus:ring-red-500'
             >
-              {statuses.map((status) => (
+              {sortes.map((status) => (
                 <option key={status.id} value={status.id}>
                   {status.label}
                 </option>
-- 
cgit v1.2.3

