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 */}
- {Array.from({ length: 8 }).map((_, i) => ( - - ))} + {Array.from({ length: 8 }, (_, i) => { + const metricTypes = [ + "sessions", + "users", + "time", + "response", + "costs", + "peak", + "resolution", + "languages", + ]; + return ( + + ); + })}
{/* Charts Skeleton */} @@ -333,7 +349,11 @@ function DashboardContent() { {refreshing ? "Refreshing..." : "Refresh"} {refreshing && ( -
+
Dashboard data is being refreshed
)} diff --git a/app/dashboard/sessions/page.tsx b/app/dashboard/sessions/page.tsx index 0dfc67c..7cf7554 100644 --- a/app/dashboard/sessions/page.tsx +++ b/app/dashboard/sessions/page.tsx @@ -13,7 +13,7 @@ import { Search, } from "lucide-react"; import Link from "next/link"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useId, useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; @@ -38,6 +38,17 @@ export default function SessionsPage() { const [error, setError] = useState(null); const [searchTerm, setSearchTerm] = useState(""); + const searchHeadingId = useId(); + const filtersHeadingId = useId(); + const filterContentId = useId(); + const categoryFilterId = useId(); + const categoryHelpId = useId(); + const languageFilterId = useId(); + const languageHelpId = useId(); + const sortOrderId = useId(); + const sortOrderHelpId = useId(); + const resultsHeadingId = useId(); + // Filter states const [filterOptions, setFilterOptions] = useState({ categories: [], @@ -156,8 +167,8 @@ export default function SessionsPage() { {/* Search Input */} -
-

+
+

Search Sessions

@@ -180,13 +191,13 @@ export default function SessionsPage() {
{/* Filter and Sort Controls */} -
+
@@ -196,7 +207,7 @@ export default function SessionsPage() { onClick={() => setFiltersExpanded(!filtersExpanded)} className="gap-2" aria-expanded={filtersExpanded} - aria-controls="filter-content" + aria-controls={filterContentId} > {filtersExpanded ? ( <> @@ -213,7 +224,7 @@ export default function SessionsPage() {
{filtersExpanded && ( - +
Session Filters and Sorting Options @@ -221,13 +232,13 @@ export default function SessionsPage() {
{/* Category Filter */}
- + -
+
Filter sessions by category type
{/* Language Filter */}
- + -
+
Filter sessions by language
@@ -319,20 +330,20 @@ export default function SessionsPage() { {/* Sort Order */}
- + -
+
Choose ascending or descending order
@@ -344,13 +355,13 @@ export default function SessionsPage() {
{/* Results section */} -
-

+
+

Session Results

{/* Live region for screen reader announcements */} -
+ {loading && "Loading sessions..."} {error && `Error loading sessions: ${error}`} {!loading && @@ -358,7 +369,7 @@ export default function SessionsPage() { sessions.length > 0 && `Found ${sessions.length} sessions`} {!loading && !error && sessions.length === 0 && "No sessions found"} -
+ {/* Loading State */} {loading && ( diff --git a/app/layout.tsx b/app/layout.tsx index 54b4740..3392754 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -126,6 +126,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {