// ui/components/Dashboard.tsx import { useEffect, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, } from "recharts"; import { ChartContainer, ChartConfig } from "@/components/ui/chart"; import { DashboardSkeleton } from "./DashboardSKeleton"; import { useRecentActivity } from "@/hooks/useRecentActivity"; import { useSonStats } from "@/hooks/useSonStats"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; const chartConfig = { executions: { label: "Executions", color: "#2563eb", }, success: { label: "Success", color: "#F97316", }, failure: { label: "Failure", color: "#d1d5db", }, } satisfies ChartConfig; const timeframeOptions = [ { value: "1h", label: "1 Hour" }, { value: "6h", label: "6 Hours" }, { value: "12h", label: "12 Hours" }, { value: "24h", label: "24 Hours" }, { value: "168h", label: "1 Week" }, ]; export default function Dashboard() { const [timeframe, setTimeframe] = useState("24h"); const { activities, loading: activitiesLoading, error: activitiesError, } = useRecentActivity(); const { stats, loading: statsLoading, error: statsError, } = useSonStats(timeframe); if (activitiesLoading || statsLoading) { return ; } if (activitiesError || statsError) { return
Error loading dashboard data
; } return (

Dashboard

Recent Activity {!activities &&
No recent activity
} {activities && activities.map((activity) => ( {activity.action_type} {activity.description}
{new Date(activity.timestamp).toLocaleString()}
))}
Son Performance
); }