From 7c9f68d3a3febc9349eb2dd3a147601e3e3687b6 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Wed, 17 Dec 2025 14:44:36 +0700 Subject: [PATCH] feat(FE-363): Add Excel export loading and combine export state --- .../logistic-stock/tab/PurchasesPerSupplierTab.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/pages/report/logistic-stock/tab/PurchasesPerSupplierTab.tsx b/src/components/pages/report/logistic-stock/tab/PurchasesPerSupplierTab.tsx index 349de06b..c0672cab 100644 --- a/src/components/pages/report/logistic-stock/tab/PurchasesPerSupplierTab.tsx +++ b/src/components/pages/report/logistic-stock/tab/PurchasesPerSupplierTab.tsx @@ -46,6 +46,8 @@ interface GroupedSupplierData { const PurchasesPerSupplierTab = () => { // ===== STATE MANAGEMENT ===== const [isPdfExportLoading, setIsPdfExportLoading] = useState(false); + const [isExcelExportLoading, setIsExcelExportLoading] = useState(false); + const isAnyExportLoading = isPdfExportLoading || isExcelExportLoading; // ===== PAGINATION STATE ===== const [currentPage, setCurrentPage] = useState(1); @@ -256,9 +258,9 @@ const PurchasesPerSupplierTab = () => { ); const meta = - isResponseSuccess(purchasePerSupplier) && 'meta' in purchasePerSupplier + isResponseSuccess(purchasePerSupplier) && purchasePerSupplier?.meta ? purchasePerSupplier.meta - : undefined; + : null; const { data: allDataForExport } = useSWR( isSubmitted @@ -327,6 +329,7 @@ const PurchasesPerSupplierTab = () => { toast.error('Tidak ada data untuk diekspor.'); return; } + setIsExcelExportLoading(true); try { const groupedBySupplier: { [key: string]: typeof allExportData } = {}; @@ -453,6 +456,8 @@ const PurchasesPerSupplierTab = () => { toast.success('Excel berhasil dibuat dan diunduh.'); } catch { toast.error('Gagal membuat Excel. Silakan coba lagi.'); + } finally { + setIsExcelExportLoading(false); } }, [allExportData, tableFilterState, areaOptions, supplierOptions]); @@ -727,7 +732,7 @@ const PurchasesPerSupplierTab = () => { + }