From ebf4faee910b591254b27b99be68e2e0cb6d31ae Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 22 May 2024 10:34:58 +0700
Subject: list site & button download

---
 src/lib/transaction/components/Transactions.jsx | 60 ++++++++++++++-----------
 1 file changed, 35 insertions(+), 25 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 9485449d..1a57a976 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -26,6 +26,7 @@ import MobileView from '@/core/components/views/MobileView';
 import DesktopView from '@/core/components/views/DesktopView';
 import Menu from '@/lib/auth/components/Menu';
 import * as XLSX from 'xlsx';
+import getSite from '../api/listSiteApi';
 
 const Transactions = ({ context = '' }) => {
   const auth = useAuth();
@@ -37,6 +38,7 @@ const Transactions = ({ context = '' }) => {
   const [inputQuery, setInputQuery] = useState(q);
   const [toOthers, setToOthers] = useState(null);
   const [toCancel, setToCancel] = useState(null);
+  const [listSites, setListSites] = useState([]);
 
   const [siteFilter, setSiteFilter] = useState(site);
 
@@ -51,6 +53,11 @@ const Transactions = ({ context = '' }) => {
 
   const { transactions } = useTransactions({ query });
 
+  const fetchSite = async () => {
+    const site = await getSite();
+    setListSites(site.sites);
+  };
+
   const submitCancelTransaction = async () => {
     const isCancelled = await cancelTransactionApi({
       transaction: toCancel,
@@ -108,13 +115,13 @@ const Transactions = ({ context = '' }) => {
       const row = {
         'No. Transaksi': saleOrder.name,
         'No. PO': saleOrder.purchaseOrderName || '-',
-        'Tanggal': saleOrder.dateOrder || '-',
+        Tanggal: saleOrder.dateOrder || '-',
         'Created By': saleOrder.address.customer?.name || '-',
-        'Salesperson': saleOrder.sales,
-        'Total': currencyFormat(saleOrder.amountTotal),
-        'Status': saleOrder.status,
+        Salesperson: saleOrder.sales,
+        Total: currencyFormat(saleOrder.amountTotal),
+        Status: saleOrder.status,
       };
-      if(siteFilter){
+      if (siteFilter) {
         row['Site'] = siteFilter;
       }
       rowsToExport.push(row);
@@ -134,6 +141,10 @@ const Transactions = ({ context = '' }) => {
 
     exportToExcel(dataToExport, siteFilter);
   };
+
+  useEffect(() => {
+    fetchSite();
+  }, []);
   return (
     <>
       <MobileView>
@@ -304,7 +315,7 @@ const Transactions = ({ context = '' }) => {
             <Menu />
           </div>
           <div className='w-9/12 p-4 bg-white border border-gray_r-6 rounded'>
-            <div className='flex mb-2 items-center justify-between'>
+            <div className='flex mb-6 items-center justify-between'>
               <h1 className='text-title-sm font-semibold'>
                 Daftar Transaksi{' '}
                 {transactions?.data?.saleOrders
@@ -312,16 +323,21 @@ const Transactions = ({ context = '' }) => {
                   : ''}
               </h1>
               <div className='grid grid-cols-2 gap-2'>
-                <select
-                  value={siteFilter}
-                  onChange={handleSiteFilterChange}
-                  className='form-input'
-                >
-                  <option value=''>Semua</option>
-                  <option value='Depok'>Depok</option>
-                  <option value='Padang'>Padang</option>
-                  <option value='berau'>Berau</option>
-                </select>
+                {listSites.length > 0 && (
+                  <select
+                    value={siteFilter}
+                    onChange={handleSiteFilterChange}
+                    className='form-input'
+                  >
+                    <option value=''>Pilih Site</option>
+                    {listSites.map((site) => (
+                      <option value={site} key={site}>
+                        {site}
+                      </option>
+                    ))}
+                  </select>
+                )}
+
                 <form className='flex gap-x-1' onSubmit={handleSubmit}>
                   <input
                     type='text'
@@ -341,16 +357,10 @@ const Transactions = ({ context = '' }) => {
             </div>
             <button
               onClick={handleExportExcel}
-              className='hover:text-blue-400 rounded inline-flex items-center mb-2'
+              type='button'
+              className='btn-solid-red px-3 py-2 mr-auto mb-2'
             >
-              <svg
-                class='fill-current w-4 h-4 mr-2'
-                xmlns='http://www.w3.org/2000/svg'
-                viewBox='0 0 20 20'
-              >
-                <path d='M13 8V2H7v6H2l8 8 8-8h-5zM0 18h20v2H0v-2z' />
-              </svg>
-              <span>Export</span>
+              <span>Download</span>
             </button>
             <table className='table-data'>
               <thead>
-- 
cgit v1.2.3

