feat(FE-363): Add Excel export loading and combine export state

This commit is contained in:
rstubryan
2025-12-17 14:44:36 +07:00
parent 9ea86fe5c3
commit 7c9f68d3a3
@@ -46,6 +46,8 @@ interface GroupedSupplierData {
const PurchasesPerSupplierTab = () => { const PurchasesPerSupplierTab = () => {
// ===== STATE MANAGEMENT ===== // ===== STATE MANAGEMENT =====
const [isPdfExportLoading, setIsPdfExportLoading] = useState(false); const [isPdfExportLoading, setIsPdfExportLoading] = useState(false);
const [isExcelExportLoading, setIsExcelExportLoading] = useState(false);
const isAnyExportLoading = isPdfExportLoading || isExcelExportLoading;
// ===== PAGINATION STATE ===== // ===== PAGINATION STATE =====
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
@@ -256,9 +258,9 @@ const PurchasesPerSupplierTab = () => {
); );
const meta = const meta =
isResponseSuccess(purchasePerSupplier) && 'meta' in purchasePerSupplier isResponseSuccess(purchasePerSupplier) && purchasePerSupplier?.meta
? purchasePerSupplier.meta ? purchasePerSupplier.meta
: undefined; : null;
const { data: allDataForExport } = useSWR( const { data: allDataForExport } = useSWR(
isSubmitted isSubmitted
@@ -327,6 +329,7 @@ const PurchasesPerSupplierTab = () => {
toast.error('Tidak ada data untuk diekspor.'); toast.error('Tidak ada data untuk diekspor.');
return; return;
} }
setIsExcelExportLoading(true);
try { try {
const groupedBySupplier: { [key: string]: typeof allExportData } = {}; const groupedBySupplier: { [key: string]: typeof allExportData } = {};
@@ -453,6 +456,8 @@ const PurchasesPerSupplierTab = () => {
toast.success('Excel berhasil dibuat dan diunduh.'); toast.success('Excel berhasil dibuat dan diunduh.');
} catch { } catch {
toast.error('Gagal membuat Excel. Silakan coba lagi.'); toast.error('Gagal membuat Excel. Silakan coba lagi.');
} finally {
setIsExcelExportLoading(false);
} }
}, [allExportData, tableFilterState, areaOptions, supplierOptions]); }, [allExportData, tableFilterState, areaOptions, supplierOptions]);
@@ -727,7 +732,7 @@ const PurchasesPerSupplierTab = () => {
</Button> </Button>
<Dropdown <Dropdown
trigger={ trigger={
<Button color='success' isLoading={isPdfExportLoading}> <Button color='success' isLoading={isAnyExportLoading}>
Export Export
</Button> </Button>
} }