From d0efa8d5c8a570669fb1f5880adfeebc5207b13e Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 4 Jun 2024 11:30:46 -0400 Subject: [PATCH] CHE-144 Some temporary state handling for loading/errors until migrated to Redux --- .../ApplicationDashBoard/ApplicationDashBoard.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/components/ApplicationDashBoard/ApplicationDashBoard.tsx b/client/src/components/ApplicationDashBoard/ApplicationDashBoard.tsx index 520b3a2..ba28994 100644 --- a/client/src/components/ApplicationDashBoard/ApplicationDashBoard.tsx +++ b/client/src/components/ApplicationDashBoard/ApplicationDashBoard.tsx @@ -12,10 +12,13 @@ const ApplicationDashboard = (): JSX.Element => { const [applicationsByStatus, setApplicationsByStatus] = useState< IStatusCount[] >([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); const user = useAppSelector((state) => state.user.userData); useEffect(() => { async function fetchAggregatedData() { + setLoading(true); try { const response = await axios.get( `/api/applications/aggregated-user-stats/${user?._id}` @@ -24,8 +27,12 @@ const ApplicationDashboard = (): JSX.Element => { response.data || {}; setTotalApplications(totalApplications); setApplicationsByStatus(applicationsByStatus); - } catch (error) { + setLoading(false); + } catch (err) { + const error = err as Error; console.error("Error fetching aggregated data:", error); + setError(error.message); + setLoading(false); } }