feat(FE-357): Add loading state for export

This commit is contained in:
rstubryan
2025-12-17 13:45:00 +07:00
parent e515438312
commit 9365320b03
@@ -33,6 +33,11 @@ interface Totals {
}
const HppPerKandangTab = () => {
// ===== STATE MANAGEMENT =====
const [isPdfExportLoading, setIsPdfExportLoading] = useState(false);
const [isExcelExportLoading, setIsExcelExportLoading] = useState(false);
const isAnyExportLoading = isPdfExportLoading || isExcelExportLoading;
// ===== SUBMISSION STATE =====
const [isSubmitted, setIsSubmitted] = useState(false);
@@ -273,6 +278,7 @@ const HppPerKandangTab = () => {
return;
}
setIsExcelExportLoading(true);
try {
const totals = allExportData.reduce(
(acc, item) => ({
@@ -400,6 +406,8 @@ const HppPerKandangTab = () => {
toast.success('Excel berhasil dibuat dan diunduh.');
} catch {
toast.error('Gagal membuat Excel. Silakan coba lagi.');
} finally {
setIsExcelExportLoading(false);
}
}, [
allExportData,
@@ -415,6 +423,7 @@ const HppPerKandangTab = () => {
return;
}
setIsPdfExportLoading(true);
try {
const areaName = tableFilterState.area_id
? areaOptions.find(
@@ -448,6 +457,8 @@ const HppPerKandangTab = () => {
toast.success('PDF berhasil dibuat dan diunduh.');
} catch {
toast.error('Gagal membuat PDF. Silakan coba lagi.');
} finally {
setIsPdfExportLoading(false);
}
}, [
hppPerKandang,
@@ -652,7 +663,11 @@ const HppPerKandangTab = () => {
Reset
</Button>
<Dropdown
trigger={<Button color='success'>Export</Button>}
trigger={
<Button color='success' isLoading={isAnyExportLoading}>
Export
</Button>
}
align='end'
>
<Menu className='w-32'>