diff --git a/app/dashboard/overview/page.tsx b/app/dashboard/overview/page.tsx index 9edf5cc..fd91203 100644 --- a/app/dashboard/overview/page.tsx +++ b/app/dashboard/overview/page.tsx @@ -52,34 +52,33 @@ function DashboardContent() { const isAuditor = session?.user?.role === "AUDITOR"; // Function to fetch metrics with optional date range - const fetchMetrics = useCallback(async ( - startDate?: string, - endDate?: string, - isInitial = false - ) => { - setLoading(true); - try { - let url = "/api/dashboard/metrics"; - if (startDate && endDate) { - url += `?startDate=${startDate}&endDate=${endDate}`; + const fetchMetrics = useCallback( + async (startDate?: string, endDate?: string, isInitial = false) => { + setLoading(true); + try { + let url = "/api/dashboard/metrics"; + if (startDate && endDate) { + url += `?startDate=${startDate}&endDate=${endDate}`; + } + + const res = await fetch(url); + const data = await res.json(); + + setMetrics(data.metrics); + setCompany(data.company); + + // Set initial load flag + if (isInitial) { + setIsInitialLoad(false); + } + } catch (error) { + console.error("Error fetching metrics:", error); + } finally { + setLoading(false); } - - const res = await fetch(url); - const data = await res.json(); - - setMetrics(data.metrics); - setCompany(data.company); - - // Set initial load flag - if (isInitial) { - setIsInitialLoad(false); - } - } catch (error) { - console.error("Error fetching metrics:", error); - } finally { - setLoading(false); - } - }, []); + }, + [] + ); useEffect(() => { // Redirect if not authenticated @@ -167,9 +166,26 @@ function DashboardContent() { {/* Metrics Grid Skeleton */}