From 93f99f867afde7c61530da85ef2e26280a1d18df Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadmiqdad27@gmail.com>
Date: Mon, 1 Sep 2025 15:25:16 +0700
Subject: <Miqdad> No reload

---
 src/lib/transaction/components/Transactions.jsx | 27 +++++++++++++++----------
 1 file changed, 16 insertions(+), 11 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 287451ef..4572a7b5 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -42,6 +42,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();
@@ -58,6 +59,8 @@ const Transactions = ({ context = '' }) => {
   const { setRefreshCart } = useProductCartContext();
 
   const [inputQuery, setInputQuery] = useState(q);
+  const [cachedAllData, setCachedAllData] = useState(null); // Simpan data "All"
+  const [currentData, setCurrentData] = useState([]); // Data yang ditampilkan
   const [toOthers, setToOthers] = useState(null);
   const [toCancel, setToCancel] = useState(null);
   const [listSites, setListSites] = useState([]);
@@ -339,20 +342,22 @@ 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 },
-    });
-  };
 
-  useEffect(() => {
-    // bersihkan cache lama jika perlu (saat first mount)
-    // (sengaja kosong; tidak pakai cached data di versi ini)
-  }, []);
+    if (status === 'all' && cachedAllData) {
+      setCurrentData(cachedAllData);
+      return;
+    }
+    const data = await fetchSite(status, 1);
+
+    if (status === 'all') {
+      setCachedAllData(data);
+    }
+
+    setCurrentData(data);
+  };
 
   const handleReset = () => {
     setState([{ startDate: null, endDate: new Date(), key: 'selection' }]);
-- 
cgit v1.2.3

