From 036aa2bc11dc9e467df5b3c883404b44b6e961d9 Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Fri, 26 Jul 2024 14:24:21 +0800 Subject: [PATCH] add loading when downloading --- .../GenerateProjectPandLReport.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx index e2e0876..f57c222 100644 --- a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx +++ b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx @@ -12,15 +12,22 @@ import { FormHelperText } from "@mui/material"; import { errorDialog, errorDialogWithContent } from "../Swal/CustomAlerts"; import { TeamResult } from "@/app/api/team"; import { SessionStaff } from "@/config/authConfig"; +import GenerateProjectPandLReportLoading from "./GenerateProjectPandLReportLoading"; interface Props { projects: ProjectResult[]; } +interface SubComponents { + Loading: typeof GenerateProjectPandLReportLoading; +} + + + type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; -const GenerateProjectPandLReport: React.FC = ({ projects }) => { +const GenerateProjectPandLReport: React.FC & SubComponents = ({ projects }) => { const { t } = useTranslation("report"); const projectCombo = projects.map(project => ({ label: `${project.code} - ${project.name}`, @@ -36,15 +43,17 @@ const GenerateProjectPandLReport: React.FC = ({ projects }) => { [t], ); + const [loading, setLoading] = React.useState(false); + return ( <> - } + {!loading && + { - + setLoading(true); if (Boolean(query.project) && query.project !== "All") { - // const projectIndex = projectCombo.findIndex(project => project === query.project) - // console.log(projects[projectIndex].id, query.startMonth, query.startMonthTo) if(query.project != null && query.startMonth != "" && query.startMonthTo != undefined){ const response = await fetchProjectPandLReport({ projectId: parseFloat(query.project), startMonth: query.startMonth, endMonth: query.startMonthTo }) if (response) { @@ -58,11 +67,14 @@ const GenerateProjectPandLReport: React.FC = ({ projects }) => { }) } } + setLoading(false); }} formType={"download"} - /> + />} ); }; +GenerateProjectPandLReport.Loading = GenerateProjectPandLReportLoading; + export default GenerateProjectPandLReport; \ No newline at end of file