/admin is the entry point for store operators. It provides sales metrics, order activity, top-product analytics, an AI pulse narrative, and a proactive inventory oracle — all organized into animated, lazily-loaded lego components.
Dashboard Components
DashboardHeader
Date range picker with presets (Today, Last 7 days, Last 30 days, This month). Includes a CSV export button for the current range.
DashboardPulse
AI-powered business health narrative. Calls the
dashboard-intelligence edge function to generate a narrative, list of anomalies, and a health_score.AdminOracleDashboard
Shows products with stock below 10 units. Fetches via
getOracleLowStockProducts(). Links directly to the relevant product edit page.AIInsights
Proactive AI insights panel (Wave 59 feature). Calls
getProactiveInsights() from admin-crm.service.ts.DashboardStats
Six KPI cards: Today’s Sales, Pending Orders, Low Stock Products, Total Customers, Active Products, Total Orders.
SalesChart + TopProducts
Sales volume chart for the selected date range and a ranked list of top 5 products by revenue within that range.
RecentOrders
Feed of the 8 most recent orders with customer name, status badge, total, and payment method.
getDashboardStats()
The primary data function. Called byuseAdminDashboardStats(startDate, endDate) in the dashboard page.
endDate is today and startDate is 6 days prior (7-day window).
Return type:
Date Range Filtering
The dashboard maintains adateRange state with start and end as ISO date strings (YYYY-MM-DD). Changing the range triggers a React Query refetch:
getDashboardStats sets the end date to 23:59:59.999 and start to 00:00:00.000 to capture the full day on both ends.
getRecentOrders()
customer_profiles (for logged-in customers) or the shipping address record (for guest/anonymous orders). The dashboard calls it with limit = 8.
System Pulse (getPulseMetrics)
The sidebar pulse indicator andDashboardPulse component both use:
alert→ anyinventoryAlerts > 0busy→activeOrders > 10optimal→ everything else
AI Dashboard Intelligence
TheDashboardPulse component calls the dashboard-intelligence Supabase Edge Function:
POSTs { stats, action: 'get_pulse' } to the edge function endpoint and returns:
narrative— A natural language description of business healthanomalies— Array of detected anomalies (e.g. unusual sales drop)health_score— A 0–100 score; defaults to100on error
The
dashboard-intelligence edge function requires the GEMINI_API_KEY secret set in your Supabase project. See the AI Edge Functions section for deployment instructions.CSV Export
The dashboard header includes an export button that generates a CSV from current stats:Command Palette Search
The admin panel includes a keyboard-accessible command palette powered bysearchCommandPalette(query):
