diff --git a/src/pages/call-history.tsx b/src/pages/call-history.tsx index 9405750..a9ae23f 100644 --- a/src/pages/call-history.tsx +++ b/src/pages/call-history.tsx @@ -1,14 +1,124 @@ +import { Badge } from '@/components/base/badges/badges'; import { TopBar } from '@/components/layout/top-bar'; +import { formatShortDate } from '@/lib/format'; +import { useData } from '@/providers/data-provider'; +import { useAuth } from '@/providers/auth-provider'; +import type { CallDisposition } from '@/types/entities'; + +const dispositionColor = (disposition: CallDisposition | null): 'success' | 'brand' | 'blue-light' | 'warning' | 'gray' | 'error' => { + switch (disposition) { + case 'APPOINTMENT_BOOKED': + return 'success'; + case 'FOLLOW_UP_SCHEDULED': + return 'brand'; + case 'INFO_PROVIDED': + return 'blue-light'; + case 'NO_ANSWER': + return 'warning'; + case 'WRONG_NUMBER': + return 'gray'; + case 'CALLBACK_REQUESTED': + return 'brand'; + default: + return 'gray'; + } +}; + +const formatDispositionLabel = (disposition: CallDisposition | null): string => { + if (!disposition) return '—'; + return disposition + .toLowerCase() + .replace(/_/g, ' ') + .replace(/\b\w/g, (c) => c.toUpperCase()); +}; + +const formatDuration = (seconds: number | null): string => { + if (seconds === null) return '—'; + const mins = Math.round(seconds / 60); + return mins === 0 ? '<1 min' : `${mins} min`; +}; + +const formatCallerNumber = (callerNumber: { number: string; callingCode: string }[] | null): string => { + if (!callerNumber || callerNumber.length === 0) return '—'; + const first = callerNumber[0]; + return `${first.callingCode} ${first.number}`; +}; export const CallHistoryPage = () => { + const { calls } = useData(); + const { user } = useAuth(); + + const agentCalls = calls + .filter((call) => call.agentName === user.name) + .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; + }); + return ( -
Coming soon — call logs, recordings, and outcome tracking.
-No call history available for your account yet.
+| + Date / Time + | ++ Caller + | ++ Lead Name + | ++ Duration + | ++ Disposition + | +
|---|---|---|---|---|
| + {call.startedAt ? formatShortDate(call.startedAt) : '—'} + | ++ {formatCallerNumber(call.callerNumber)} + | ++ {call.leadName ?? '—'} + | ++ {formatDuration(call.durationSeconds)} + | +
+ {call.disposition ? (
+ |
+
Coming soon — follow-up reminders, scheduling, and task management.
++ {followUp.scheduledAt ? formatShortDate(followUp.scheduledAt) : 'No date scheduled'} + {(isOverdue || followUp.followUpStatus === 'OVERDUE') && ' — Overdue'} +
++ {followUp.description ?? followUp.followUpType ?? 'Follow-up'} +
+ {(followUp.patientName || followUp.patientPhone) && ( ++ {followUp.patientName} + {followUp.patientPhone && ` · ${followUp.patientPhone}`} +
+ )} +All caught up — no scheduled callbacks or reminders.
+