mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-363): Add Excel export loading and combine export state
This commit is contained in:
@@ -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>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user