mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-04-11 18:28:15 +00:00
feat: build all data pages — worklist table, call history, patients, dashboard, reports
Worklist (call-desk): - Upgrade to Untitled UI Table with columns: Priority, Patient, Phone, Type, SLA, Actions - Filter tabs: All Tasks / Missed Calls / Callbacks / Follow-ups with counts - Search by name or phone - SLA timer color-coded: green <15m, amber <30m, red >30m Call History: - Full table: Type (direction icon), Patient (matched from leads), Phone, Duration, Outcome, Agent, Recording (play/pause), Time - Search + All/Inbound/Outbound/Missed filter - Recording playback via native <audio> Patients: - New page with table: Patient (avatar+name+age), Contact, Type, Gender, Status, Actions - Search + status filter - Call + View Details actions - Added patients to DataProvider + transforms + queries - Route /patients added, sidebar nav updated for cc-agent + executive Supervisor Dashboard: - KPI cards: Total Calls, Inbound, Outbound, Missed - Performance metrics: Avg Response Time, Callback Time, Conversion % - Agent performance table with per-agent stats - Missed Call Queue - AI Assistant section - Day/Week/Month filter Reports: - ECharts bar chart: Call Volume Trend (7-day, Inbound vs Outbound) - ECharts donut chart: Call Outcomes (Booked, Follow-up, Info, Missed) - KPI cards with trend indicators (+/-%) - Route /reports, sidebar Analytics → /reports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,29 +1,456 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faPhone,
|
||||
faPhoneArrowDownLeft,
|
||||
faPhoneArrowUpRight,
|
||||
faPhoneMissed,
|
||||
faClock,
|
||||
faCalendarCheck,
|
||||
faUserHeadset,
|
||||
faChartMixed,
|
||||
} from '@fortawesome/pro-duotone-svg-icons';
|
||||
import type { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
||||
import { Avatar } from '@/components/base/avatar/avatar';
|
||||
import { Badge } from '@/components/base/badges/badges';
|
||||
import { Table, TableCard } from '@/components/application/table/table';
|
||||
import { TopBar } from '@/components/layout/top-bar';
|
||||
import { TeamScoreboard } from '@/components/admin/team-scoreboard';
|
||||
import { CampaignRoiCards } from '@/components/admin/campaign-roi-cards';
|
||||
import { LeadFunnel } from '@/components/admin/lead-funnel';
|
||||
import { SlaMetrics } from '@/components/admin/sla-metrics';
|
||||
import { IntegrationHealth } from '@/components/admin/integration-health';
|
||||
import { useLeads } from '@/hooks/use-leads';
|
||||
import { useCampaigns } from '@/hooks/use-campaigns';
|
||||
import { AiChatPanel } from '@/components/call-desk/ai-chat-panel';
|
||||
import { useData } from '@/providers/data-provider';
|
||||
import { getInitials, formatShortDate } from '@/lib/format';
|
||||
import type { Call } from '@/types/entities';
|
||||
|
||||
// KPI Card component
|
||||
type KpiCardProps = {
|
||||
label: string;
|
||||
value: number | string;
|
||||
icon: IconDefinition;
|
||||
iconColor: string;
|
||||
iconBg: string;
|
||||
subtitle?: string;
|
||||
};
|
||||
|
||||
const KpiCard = ({ label, value, icon, iconColor, iconBg, subtitle }: KpiCardProps) => (
|
||||
<div className="flex flex-1 items-center gap-4 rounded-xl border border-secondary bg-primary p-5 shadow-xs">
|
||||
<div className={`flex size-12 shrink-0 items-center justify-center rounded-full ${iconBg}`}>
|
||||
<FontAwesomeIcon icon={icon} className={`size-5 ${iconColor}`} />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-xs font-medium text-tertiary">{label}</span>
|
||||
<span className="text-display-xs font-bold text-primary">{value}</span>
|
||||
{subtitle && <span className="text-xs text-tertiary">{subtitle}</span>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// Metric card for performance row
|
||||
type MetricCardProps = {
|
||||
label: string;
|
||||
value: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
const MetricCard = ({ label, value, description }: MetricCardProps) => (
|
||||
<div className="flex flex-1 flex-col gap-1 rounded-xl border border-secondary bg-primary p-5 shadow-xs">
|
||||
<span className="text-xs font-medium text-tertiary">{label}</span>
|
||||
<span className="text-lg font-bold text-primary">{value}</span>
|
||||
<span className="text-xs text-tertiary">{description}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
type DateRange = 'today' | 'week' | 'month';
|
||||
|
||||
const getDateRangeStart = (range: DateRange): Date => {
|
||||
const now = new Date();
|
||||
switch (range) {
|
||||
case 'today': {
|
||||
const start = new Date(now);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
return start;
|
||||
}
|
||||
case 'week': {
|
||||
const start = new Date(now);
|
||||
start.setDate(start.getDate() - 7);
|
||||
return start;
|
||||
}
|
||||
case 'month': {
|
||||
const start = new Date(now);
|
||||
start.setDate(start.getDate() - 30);
|
||||
return start;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const formatDuration = (seconds: number): string => {
|
||||
if (seconds < 60) return `${seconds}s`;
|
||||
const mins = Math.floor(seconds / 60);
|
||||
const secs = seconds % 60;
|
||||
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
||||
};
|
||||
|
||||
const formatPercent = (value: number): string => {
|
||||
if (isNaN(value) || !isFinite(value)) return '0%';
|
||||
return `${Math.round(value)}%`;
|
||||
};
|
||||
|
||||
type AgentPerformance = {
|
||||
id: string;
|
||||
name: string;
|
||||
initials: string;
|
||||
inboundCalls: number;
|
||||
outboundCalls: number;
|
||||
missedCalls: number;
|
||||
totalCalls: number;
|
||||
avgHandleTime: number;
|
||||
appointmentsBooked: number;
|
||||
conversionRate: number;
|
||||
};
|
||||
|
||||
export const TeamDashboardPage = () => {
|
||||
const { leads } = useLeads();
|
||||
const { campaigns } = useCampaigns();
|
||||
const { calls, agents, ingestionSources } = useData();
|
||||
const { calls, leads, followUps, loading } = useData();
|
||||
const [dateRange, setDateRange] = useState<DateRange>('week');
|
||||
|
||||
// Filter calls by date range
|
||||
const filteredCalls = useMemo(() => {
|
||||
const rangeStart = getDateRangeStart(dateRange);
|
||||
return calls.filter((call) => {
|
||||
if (!call.startedAt) return false;
|
||||
return new Date(call.startedAt) >= rangeStart;
|
||||
});
|
||||
}, [calls, dateRange]);
|
||||
|
||||
// KPI computations
|
||||
const totalCalls = filteredCalls.length;
|
||||
const inboundCalls = filteredCalls.filter((c) => c.callDirection === 'INBOUND').length;
|
||||
const outboundCalls = filteredCalls.filter((c) => c.callDirection === 'OUTBOUND').length;
|
||||
const missedCalls = filteredCalls.filter((c) => c.callStatus === 'MISSED').length;
|
||||
|
||||
// Performance metrics
|
||||
const avgResponseTime = useMemo(() => {
|
||||
const leadsWithResponse = leads.filter((l) => l.createdAt && l.firstContactedAt);
|
||||
if (leadsWithResponse.length === 0) return null;
|
||||
const totalMinutes = leadsWithResponse.reduce((sum, l) => {
|
||||
const created = new Date(l.createdAt!).getTime();
|
||||
const contacted = new Date(l.firstContactedAt!).getTime();
|
||||
return sum + (contacted - created) / 60000;
|
||||
}, 0);
|
||||
return Math.round(totalMinutes / leadsWithResponse.length);
|
||||
}, [leads]);
|
||||
|
||||
const missedCallbackTime = useMemo(() => {
|
||||
const missedCallsList = filteredCalls.filter((c) => c.callStatus === 'MISSED' && c.startedAt);
|
||||
if (missedCallsList.length === 0) return null;
|
||||
const now = Date.now();
|
||||
const totalMinutes = missedCallsList.reduce((sum, c) => {
|
||||
return sum + (now - new Date(c.startedAt!).getTime()) / 60000;
|
||||
}, 0);
|
||||
return Math.round(totalMinutes / missedCallsList.length);
|
||||
}, [filteredCalls]);
|
||||
|
||||
const callToAppointmentRate = useMemo(() => {
|
||||
if (totalCalls === 0) return 0;
|
||||
const booked = filteredCalls.filter((c) => c.disposition === 'APPOINTMENT_BOOKED').length;
|
||||
return (booked / totalCalls) * 100;
|
||||
}, [filteredCalls, totalCalls]);
|
||||
|
||||
const leadToAppointmentRate = useMemo(() => {
|
||||
if (leads.length === 0) return 0;
|
||||
const converted = leads.filter(
|
||||
(l) => l.leadStatus === 'APPOINTMENT_SET' || l.leadStatus === 'CONVERTED',
|
||||
).length;
|
||||
return (converted / leads.length) * 100;
|
||||
}, [leads]);
|
||||
|
||||
// Agent performance table data
|
||||
const agentPerformance = useMemo((): AgentPerformance[] => {
|
||||
const agentMap = new Map<string, Call[]>();
|
||||
for (const call of filteredCalls) {
|
||||
const agent = call.agentName ?? 'Unknown';
|
||||
if (!agentMap.has(agent)) agentMap.set(agent, []);
|
||||
agentMap.get(agent)!.push(call);
|
||||
}
|
||||
|
||||
return Array.from(agentMap.entries()).map(([name, agentCalls]) => {
|
||||
const inbound = agentCalls.filter((c) => c.callDirection === 'INBOUND').length;
|
||||
const outbound = agentCalls.filter((c) => c.callDirection === 'OUTBOUND').length;
|
||||
const missed = agentCalls.filter((c) => c.callStatus === 'MISSED').length;
|
||||
const total = agentCalls.length;
|
||||
const totalDuration = agentCalls.reduce((sum, c) => sum + (c.durationSeconds ?? 0), 0);
|
||||
const completedCalls = agentCalls.filter((c) => (c.durationSeconds ?? 0) > 0);
|
||||
const avgHandle = completedCalls.length > 0 ? Math.round(totalDuration / completedCalls.length) : 0;
|
||||
const booked = agentCalls.filter((c) => c.disposition === 'APPOINTMENT_BOOKED').length;
|
||||
const conversion = total > 0 ? (booked / total) * 100 : 0;
|
||||
|
||||
const nameParts = name.split(' ');
|
||||
const initials = getInitials(nameParts[0] ?? '', nameParts[1] ?? '');
|
||||
|
||||
return {
|
||||
id: name,
|
||||
name,
|
||||
initials,
|
||||
inboundCalls: inbound,
|
||||
outboundCalls: outbound,
|
||||
missedCalls: missed,
|
||||
totalCalls: total,
|
||||
avgHandleTime: avgHandle,
|
||||
appointmentsBooked: booked,
|
||||
conversionRate: conversion,
|
||||
};
|
||||
}).sort((a, b) => b.totalCalls - a.totalCalls);
|
||||
}, [filteredCalls]);
|
||||
|
||||
// Missed call queue (recent missed calls)
|
||||
const missedCallQueue = useMemo(() => {
|
||||
return filteredCalls
|
||||
.filter((c) => c.callStatus === 'MISSED')
|
||||
.sort((a, b) => {
|
||||
const dateA = a.startedAt ? new Date(a.startedAt).getTime() : 0;
|
||||
const dateB = b.startedAt ? new Date(b.startedAt).getTime() : 0;
|
||||
return dateB - dateA;
|
||||
})
|
||||
.slice(0, 10);
|
||||
}, [filteredCalls]);
|
||||
|
||||
const formatCallerPhone = (call: Call): string => {
|
||||
if (!call.callerNumber || call.callerNumber.length === 0) return 'Unknown';
|
||||
const first = call.callerNumber[0];
|
||||
return `${first.callingCode} ${first.number}`;
|
||||
};
|
||||
|
||||
const getTimeSince = (dateStr: string | null): string => {
|
||||
if (!dateStr) return '—';
|
||||
const diffMs = Date.now() - new Date(dateStr).getTime();
|
||||
const mins = Math.floor(diffMs / 60000);
|
||||
if (mins < 1) return 'Just now';
|
||||
if (mins < 60) return `${mins}m ago`;
|
||||
const hours = Math.floor(mins / 60);
|
||||
if (hours < 24) return `${hours}h ago`;
|
||||
return `${Math.floor(hours / 24)}d ago`;
|
||||
};
|
||||
|
||||
// Supervisor AI quick prompts
|
||||
const supervisorQuickPrompts = [
|
||||
{ label: 'Top conversions', template: 'Which agents have the highest conversion rates this week?' },
|
||||
{ label: 'Pending leads', template: 'How many leads are still pending first contact?' },
|
||||
{ label: 'Missed callback risks', template: 'Which missed calls have been waiting the longest without a callback?' },
|
||||
{ label: 'Weekly summary', template: 'Give me a summary of this week\'s team performance.' },
|
||||
];
|
||||
|
||||
const dateRangeLabel = dateRange === 'today' ? 'Today' : dateRange === 'week' ? 'This Week' : 'This Month';
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col">
|
||||
<TopBar title="Team Dashboard" subtitle="Global Hospital \u00b7 This Week" />
|
||||
<div className="flex flex-1 flex-col overflow-hidden">
|
||||
<TopBar title="Team Dashboard" subtitle={`Global Hospital \u00b7 ${dateRangeLabel}`} />
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-7 space-y-6">
|
||||
<TeamScoreboard leads={leads} calls={calls} agents={agents} />
|
||||
<div className="grid grid-cols-1 gap-6 xl:grid-cols-2">
|
||||
<LeadFunnel leads={leads} />
|
||||
<SlaMetrics leads={leads} />
|
||||
{/* Date range filter */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-md font-semibold text-primary">Overview</h2>
|
||||
<div className="flex rounded-lg border border-secondary overflow-hidden">
|
||||
{(['today', 'week', 'month'] as const).map((range) => (
|
||||
<button
|
||||
key={range}
|
||||
onClick={() => setDateRange(range)}
|
||||
className={`px-3 py-1.5 text-xs font-medium transition duration-100 ease-linear capitalize ${
|
||||
dateRange === range
|
||||
? 'bg-active text-brand-secondary'
|
||||
: 'bg-primary text-tertiary hover:bg-primary_hover'
|
||||
}`}
|
||||
>
|
||||
{range === 'today' ? 'Today' : range === 'week' ? 'Week' : 'Month'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* KPI Cards Row */}
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<KpiCard
|
||||
label="Total Calls"
|
||||
value={totalCalls}
|
||||
icon={faPhone}
|
||||
iconColor="text-fg-brand-primary"
|
||||
iconBg="bg-brand-secondary"
|
||||
/>
|
||||
<KpiCard
|
||||
label="Inbound"
|
||||
value={inboundCalls}
|
||||
icon={faPhoneArrowDownLeft}
|
||||
iconColor="text-fg-success-primary"
|
||||
iconBg="bg-success-secondary"
|
||||
/>
|
||||
<KpiCard
|
||||
label="Outbound"
|
||||
value={outboundCalls}
|
||||
icon={faPhoneArrowUpRight}
|
||||
iconColor="text-fg-brand-primary"
|
||||
iconBg="bg-brand-secondary"
|
||||
/>
|
||||
<KpiCard
|
||||
label="Missed"
|
||||
value={missedCalls}
|
||||
icon={faPhoneMissed}
|
||||
iconColor="text-fg-error-primary"
|
||||
iconBg="bg-error-secondary"
|
||||
subtitle={totalCalls > 0 ? `${formatPercent((missedCalls / totalCalls) * 100)} of total` : undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Performance Metrics Row */}
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<MetricCard
|
||||
label="Avg Lead Response Time"
|
||||
value={avgResponseTime !== null ? `${avgResponseTime} min` : '—'}
|
||||
description="Time from lead creation to first contact"
|
||||
/>
|
||||
<MetricCard
|
||||
label="Avg Missed Callback Time"
|
||||
value={missedCallbackTime !== null ? `${missedCallbackTime} min` : '—'}
|
||||
description="Avg wait time for missed call callbacks"
|
||||
/>
|
||||
<MetricCard
|
||||
label="Call to Appointment %"
|
||||
value={formatPercent(callToAppointmentRate)}
|
||||
description="Calls resulting in appointments"
|
||||
/>
|
||||
<MetricCard
|
||||
label="Lead to Appointment %"
|
||||
value={formatPercent(leadToAppointmentRate)}
|
||||
description="Leads converted to appointments"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Agent Performance Table + Missed Call Queue */}
|
||||
<div className="grid grid-cols-1 gap-6 xl:grid-cols-3">
|
||||
{/* Agent Performance Table */}
|
||||
<div className="xl:col-span-2">
|
||||
<TableCard.Root size="sm">
|
||||
<TableCard.Header
|
||||
title="Agent Performance"
|
||||
badge={agentPerformance.length}
|
||||
description="Call metrics by agent"
|
||||
/>
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<p className="text-sm text-tertiary">Loading...</p>
|
||||
</div>
|
||||
) : agentPerformance.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-12 gap-2">
|
||||
<FontAwesomeIcon icon={faUserHeadset} className="size-8 text-fg-quaternary" />
|
||||
<p className="text-sm text-tertiary">No agent data available</p>
|
||||
</div>
|
||||
) : (
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Head label="AGENT" />
|
||||
<Table.Head label="INBOUND" />
|
||||
<Table.Head label="OUTBOUND" />
|
||||
<Table.Head label="MISSED" />
|
||||
<Table.Head label="AVG HANDLE TIME" />
|
||||
<Table.Head label="CONVERSION %" />
|
||||
</Table.Header>
|
||||
<Table.Body items={agentPerformance}>
|
||||
{(agent) => (
|
||||
<Table.Row id={agent.id}>
|
||||
<Table.Cell>
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar size="sm" initials={agent.initials} />
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-primary">
|
||||
{agent.name}
|
||||
</span>
|
||||
<span className="text-xs text-tertiary">
|
||||
{agent.totalCalls} total calls
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-sm font-medium text-success-primary">{agent.inboundCalls}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-sm font-medium text-brand-secondary">{agent.outboundCalls}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{agent.missedCalls > 0 ? (
|
||||
<Badge size="sm" color="error">{agent.missedCalls}</Badge>
|
||||
) : (
|
||||
<span className="text-sm text-tertiary">0</span>
|
||||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-sm text-secondary">
|
||||
{formatDuration(agent.avgHandleTime)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Badge
|
||||
size="sm"
|
||||
color={agent.conversionRate >= 30 ? 'success' : agent.conversionRate >= 15 ? 'warning' : 'gray'}
|
||||
>
|
||||
{formatPercent(agent.conversionRate)}
|
||||
</Badge>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
)}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
)}
|
||||
</TableCard.Root>
|
||||
</div>
|
||||
|
||||
{/* Missed Call Queue */}
|
||||
<div className="xl:col-span-1">
|
||||
<div className="rounded-xl border border-secondary bg-primary shadow-xs">
|
||||
<div className="flex items-center justify-between border-b border-secondary px-5 py-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faPhoneMissed} className="size-4 text-fg-error-primary" />
|
||||
<h3 className="text-md font-semibold text-primary">Missed Call Queue</h3>
|
||||
</div>
|
||||
{missedCalls > 0 && (
|
||||
<Badge size="sm" color="error">{missedCalls}</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="max-h-[400px] overflow-y-auto">
|
||||
{missedCallQueue.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-10 gap-2">
|
||||
<FontAwesomeIcon icon={faPhoneMissed} className="size-6 text-fg-quaternary" />
|
||||
<p className="text-sm text-tertiary">No missed calls</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="divide-y divide-secondary">
|
||||
{missedCallQueue.map((call) => (
|
||||
<li key={call.id} className="flex items-center justify-between px-5 py-3 hover:bg-primary_hover transition duration-100 ease-linear">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-primary">
|
||||
{formatCallerPhone(call)}
|
||||
</span>
|
||||
{call.leadName && (
|
||||
<span className="text-xs text-tertiary">{call.leadName}</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-xs text-tertiary whitespace-nowrap">
|
||||
{getTimeSince(call.startedAt)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* AI Assistant Section */}
|
||||
<div className="rounded-xl border border-secondary bg-primary p-5 shadow-xs">
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<FontAwesomeIcon icon={faChartMixed} className="size-4 text-fg-brand-primary" />
|
||||
<h3 className="text-md font-semibold text-primary">Supervisor AI Assistant</h3>
|
||||
</div>
|
||||
<div className="h-[350px]">
|
||||
<AiChatPanel />
|
||||
</div>
|
||||
</div>
|
||||
<CampaignRoiCards campaigns={campaigns} />
|
||||
<IntegrationHealth sources={ingestionSources} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user