link,[object Object]
Skip to content

Reports & Analytics Playbook ​

Purpose: How to validate Admin Analytics and Admin Reports data and flows. Audience: Admin, Developer Prerequisites: Admin role; Supabase project data with listings, transactions, reports.

Admin Analytics (KPIs)

  • Page: /admin/analytics
  • Code: src/pages/admin/AdminAnalytics.tsx
  • Query source (lines 14-21): parallel counts via Supabase
    • profiles → total users (count exact)
    • listings → total listings (count exact)
    • transactions → total transactions (count exact)
  • Known placeholder: totalRevenue mock (line 27) — replace with real aggregation when ready.
  • SQL checks
    sql
    select count(*) from profiles;
    select count(*) from listings;
    select count(*) from transactions;
    -- Replace mock revenue with real: sum(amount) from transactions where status in ('funded','payout_released','completed')

Admin Reports (user reports)

  • Page: /admin/reports
  • Code: src/pages/admin/AdminReports.tsx
  • Key metrics (cards): total, pending, under_review, resolved
  • Filter/search by status and term
  • Mutation (lines ~93-115): update report status; sets resolved_at/resolved_by on terminal states; invalidates ['admin-reports']
  • Tables: reports (see Data Model)
  • SQL checks
    sql
    -- Counts by status
    select status, count(*) from reports group by status;
    -- Recent reports
    select id, type, reason, status, created_at from reports order by created_at desc limit 20;
    -- Verify update effects
    select id, status, resolved_at, resolved_by from reports where id = 'REPORT_UUID';

Replace mock with real (suggestion)

  • Revenue: select coalesce(sum(amount),0) from transactions where status in ('funded','payout_released','completed');
  • Growth charts: build from monthly buckets on transactions and profiles (date_trunc by month)
    sql
    select date_trunc('month', created_at) m, count(*) c from transactions group by m order by m;
    select date_trunc('month', created_at) m, count(*) c from profiles group by m order by m;

Troubleshooting

  • Counts mismatch: ensure RLS allows admin views; check filters/status values
  • Slow dashboards: add indexes (transactions.created_at, profiles.created_at)
  • Status updates not reflected: query invalidation key ['admin-reports'] should be hit; refetch if necessary

Related

  • Data model: docs/data-model/schema.md
  • Admin tables: docs/architecture/admin-tables.md
  • Search & Indexing: docs/architecture/search-indexing.md