From d1f70e37fdea0d677cedccec9effdbeeb91656aa Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 22 May 2024 15:18:49 +0700
Subject: feedback testing renca

---
 src/lib/transaction/components/Transactions.jsx | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 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 1a57a976..5a6dfb01 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -27,6 +27,7 @@ import DesktopView from '@/core/components/views/DesktopView';
 import Menu from '@/lib/auth/components/Menu';
 import * as XLSX from 'xlsx';
 import getSite from '../api/listSiteApi';
+import transactionsApi from '../api/transactionsApi';
 
 const Transactions = ({ context = '' }) => {
   const auth = useAuth();
@@ -136,10 +137,22 @@ const Transactions = ({ context = '' }) => {
     XLSX.writeFile(workbook, 'transactions.xlsx');
   };
 
-  const handleExportExcel = () => {
-    const dataToExport = transactions.data.saleOrders;
+  const getAllData = async () => {
+    const query = {
+      name: q,
+      context,
+      site:
+        siteFilter || (auth?.webRole === null && auth?.site ? auth.site : null),
+    };
+    const queryString = toQuery(query)
+    const data = await transactionsApi({ query : queryString });
+    return data;
+  };
+
+  const handleExportExcel = async () => {
+    const dataToExport = await getAllData();
 
-    exportToExcel(dataToExport, siteFilter);
+    exportToExcel(dataToExport?.saleOrders, siteFilter);
   };
 
   useEffect(() => {
@@ -323,7 +336,7 @@ const Transactions = ({ context = '' }) => {
                   : ''}
               </h1>
               <div className='grid grid-cols-2 gap-2'>
-                {listSites.length > 0 && (
+                {listSites?.length > 0 ? (
                   <select
                     value={siteFilter}
                     onChange={handleSiteFilterChange}
@@ -336,7 +349,7 @@ const Transactions = ({ context = '' }) => {
                       </option>
                     ))}
                   </select>
-                )}
+                ):( <div></div>) }
 
                 <form className='flex gap-x-1' onSubmit={handleSubmit}>
                   <input
-- 
cgit v1.2.3

