import { useMemo, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSidebarFlip, faSidebar } from '@fortawesome/pro-duotone-svg-icons'; import { AiChatPanel } from '@/components/call-desk/ai-chat-panel'; import { DashboardKpi } from '@/components/dashboard/kpi-cards'; import { MissedQueue } from '@/components/dashboard/missed-queue'; import { RichAgentTable, TimeBreakdown, NpsConversion, PerformanceAlerts, useSupervisorRollup, } from '@/components/dashboard/supervisor-rollup'; import { useData } from '@/providers/data-provider'; import { cx } from '@/utils/cx'; type DateRange = 'today' | 'week' | 'month'; const getDateRangeStart = (range: DateRange): Date => { const now = new Date(); switch (range) { case 'today': { const s = new Date(now); s.setHours(0, 0, 0, 0); return s; } case 'week': { const s = new Date(now); s.setDate(s.getDate() - 7); return s; } case 'month': { const s = new Date(now); s.setDate(s.getDate() - 30); return s; } } }; export const TeamDashboardPage = () => { const { calls, leads, campaigns, loading } = useData(); const [dateRange, setDateRange] = useState('week'); const [aiOpen, setAiOpen] = useState(true); // Pull the richer supervisor rollup (NPS, idle, time breakdown, alerts) // from the sidecar. Only `today`/`week`/`month` overlap with the rollup's // date-range semantics — map them through directly. const { agents: rollupAgents } = useSupervisorRollup(dateRange); const filteredCalls = useMemo(() => { const rangeStart = getDateRangeStart(dateRange); return calls.filter((call) => { if (!call.startedAt) return false; return new Date(call.startedAt) >= rangeStart; }); }, [calls, dateRange]); const dateRangeLabel = dateRange === 'today' ? 'Today' : dateRange === 'week' ? 'This Week' : 'This Month'; const convRate = useMemo(() => { if (filteredCalls.length === 0) return 0; const completed = filteredCalls.filter((c) => c.callStatus === 'COMPLETED').length; return Math.round((completed / filteredCalls.length) * 100); }, [filteredCalls]); const missedQueueCount = filteredCalls.filter((c) => c.callStatus === 'MISSED').length; return (
{/* Header */}

Team Dashboard

{dateRangeLabel}
{(['today', 'week', 'month'] as const).map((range) => ( ))}
{/* Main content — scrollable column with KPIs pinned at the top, then stacked supervisor sections (Agent table, Time breakdown, NPS/Conv, Alerts, Missed Queue, Campaigns). No tabs: everything is scroll-visible so a supervisor doesn't have to hunt across surfaces for their metrics. */}
{loading && rollupAgents.length === 0 ? (

Loading...

) : ( <>

Missed Queue ({missedQueueCount})

Campaigns ({campaigns.length})

{campaigns.length === 0 ? (

No campaigns

) : (
{campaigns.map((c) => (
{c.campaignName}
{c.campaignStatus} {c.platform} {c.leadCount} leads {c.convertedCount} converted
{c.budget && ( ₹{Math.round(c.budget.amountMicros / 1_000_000).toLocaleString()} )}
))}
)}
)}
{/* AI panel — collapsible */}
{aiOpen && (
)}
); };