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 = () => {
// ===== 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 = () => {
</Button>
<Dropdown
trigger={
<Button color='success' isLoading={isPdfExportLoading}>
<Button color='success' isLoading={isAnyExportLoading}>
Export
</Button>
}