Admin Dashboard

Added by Justin Sheehan Justin S. June 24, 2025 5:58pm
Column
Done September 9, 2025 2:07am
Notes
Build a real-time Admin Analytics Dashboard at /admin/analytics in Daryle AI that replaces all dummy metrics with live data from Supabase.
Context
  • Existing placeholder cards and charts on /admin/analytics need to show actual counts and trends from our chats, profiles, and related tables.
  • Only superadmins may access this page.
Task
Fetch and display these metrics via Supabase JS calls (or RPCs) and bind them into the existing summary cards and chart components:
  1. Total Chats – exact count of rows in chats.
  2. Unique Users – distinct count of user_id in chats.
  3. Average Chat Length – average number of messages per chat (can use an RPC or calculate client-side).
  4. Returning Users % – percentage of users with more than one chat.
  5. Chat Volume Over Time – line chart grouped by day/week from created_at.
  6. Mode Usage Breakdown – donut/bar chart showing counts per mode field in chats.
  7. Messages Per Session Distribution – histogram of jsonb_array_length(messages) per chat.
Functional Requirements
  • Use Supabase .select() with { count: "exact" }, .rpc(), or .from().group() queries.
  • Show a loading spinner while data fetches, and an error message on failure.
  • Bind results into existing <SummaryCards> and <ChartSection> components.
Constraints
  • Respect RLS: ensure only superadmins can query these aggregates.
  • Do not hard-code any numbers.
  • Retain current layout, Tailwind styling, and chart libraries.
Output Files
  • pages/admin/analytics.tsx – add live data fetching and pass props to cards/charts
  • utils/analyticsQueries.ts (optional) – encapsulate Supabase calls or RPC wrappers
  • Supabase migration or RPC definitions if needed for averages or complex grouping
Make it copy-and-paste ready for Lovable’s prompt input.