From 2710d13d4d417bfa17d6eeaa7493f06d8ae06aa8 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Fri, 29 Aug 2025 17:05:44 +0700
Subject: <Miqdad> No reload on status change

---
 src/lib/transaction/components/Transactions.jsx | 26 +++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 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 e22cd490..5466466c 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -41,6 +41,7 @@ import { DateRangePicker } from 'react-date-range';
 import 'react-date-range/dist/styles.css';
 import 'react-date-range/dist/theme/default.css';
 
+
 const Transactions = ({ context = '' }) => {
   const auth = useAuth();
   const router = useRouter();
@@ -56,6 +57,8 @@ const Transactions = ({ context = '' }) => {
   } = router.query;
   const { setRefreshCart } = useProductCartContext();
 
+  const [cachedAllData, setCachedAllData] = useState(null); // Simpan data "All"
+  const [currentData, setCurrentData] = useState([]); 
   const [inputQuery, setInputQuery] = useState(q);
   const [toOthers, setToOthers] = useState(null);
   const [toCancel, setToCancel] = useState(null);
@@ -338,16 +341,27 @@ const Transactions = ({ context = '' }) => {
     }
   };
 
-  const handleStatusChange = (status) => {
+  const handleStatusChange = async (status) => {
     setStatusNew(status);
     setPageNew(1);
-    // opsional: sinkronkan ke URL
-    router.push({
-      pathname: router.pathname,
-      query: { ...router.query, status },
-    });
+
+    if (status === 'all' && cachedAllData) {
+      setCurrentData(cachedAllData);
+      return;
+    }
+    const data = await fetchSite(status, 1);
+
+    if (status === 'all') {
+      setCachedAllData(data);
+    }
+
+    setCurrentData(data);
   };
 
+  useEffect(() => {
+    setCachedAllData([]);
+  }, []);
+
   useEffect(() => {
     // bersihkan cache lama jika perlu (saat first mount)
     // (sengaja kosong; tidak pakai cached data di versi ini)
-- 
cgit v1.2.3

