fix: pinned header/chat input, numpad dialler, caller matching, appointment FK

- AppShell: h-screen + overflow-hidden for pinned header
- AI chat: input pinned to bottom, messages scroll independently
- Dialler: numpad grid (1-9,*,0,#) replaces text input
- Inbound calls: don't fall back to previously selected lead
- Appointment: use lead.patientId instead of leadId for FK
- Added .env.production for consistent builds

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 14:41:31 +05:30
parent 727a0728ee
commit 5816cc0b5c
6 changed files with 229 additions and 41 deletions

5
.env.production Normal file
View File

@@ -0,0 +1,5 @@
VITE_API_URL=https://engage-api.srv1477139.hstgr.cloud
VITE_SIDECAR_URL=https://engage-api.srv1477139.hstgr.cloud
VITE_SIP_URI=sip:523590@blr-pub-rtc4.ozonetel.com
VITE_SIP_PASSWORD=523590
VITE_SIP_WS_SERVER=wss://blr-pub-rtc4.ozonetel.com:444

View File

@@ -226,6 +226,7 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete
callerNumber={callerPhone} callerNumber={callerPhone}
leadName={fullName || null} leadName={fullName || null}
leadId={lead?.id ?? null} leadId={lead?.id ?? null}
patientId={(lead as any)?.patientId ?? null}
onSaved={handleAppointmentSaved} onSaved={handleAppointmentSaved}
/> />
</> </>
@@ -340,6 +341,7 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete
callerNumber={callerPhone} callerNumber={callerPhone}
leadName={fullName || null} leadName={fullName || null}
leadId={lead?.id ?? null} leadId={lead?.id ?? null}
patientId={(lead as any)?.patientId ?? null}
onSaved={handleAppointmentSaved} onSaved={handleAppointmentSaved}
/> />

View File

@@ -20,7 +20,7 @@ type ExistingAppointment = {
doctorId?: string; doctorId?: string;
department: string; department: string;
reasonForVisit?: string; reasonForVisit?: string;
appointmentStatus: string; status: string;
}; };
type AppointmentFormProps = { type AppointmentFormProps = {
@@ -29,6 +29,7 @@ type AppointmentFormProps = {
callerNumber?: string | null; callerNumber?: string | null;
leadName?: string | null; leadName?: string | null;
leadId?: string | null; leadId?: string | null;
patientId?: string | null;
onSaved?: () => void; onSaved?: () => void;
existingAppointment?: ExistingAppointment | null; existingAppointment?: ExistingAppointment | null;
}; };
@@ -70,6 +71,7 @@ export const AppointmentForm = ({
callerNumber, callerNumber,
leadName, leadName,
leadId, leadId,
patientId,
onSaved, onSaved,
existingAppointment, existingAppointment,
}: AppointmentFormProps) => { }: AppointmentFormProps) => {
@@ -141,11 +143,11 @@ export const AppointmentForm = ({
`{ appointments(filter: { `{ appointments(filter: {
doctorId: { eq: "${doctor}" }, doctorId: { eq: "${doctor}" },
scheduledAt: { gte: "${date}T00:00:00", lte: "${date}T23:59:59" } scheduledAt: { gte: "${date}T00:00:00", lte: "${date}T23:59:59" }
}) { edges { node { id scheduledAt durationMin appointmentStatus } } } }`, }) { edges { node { id scheduledAt durationMin status } } } }`,
).then(data => { ).then(data => {
// Filter out cancelled/completed appointments client-side // Filter out cancelled/completed appointments client-side
const activeAppointments = data.appointments.edges.filter(e => { const activeAppointments = data.appointments.edges.filter(e => {
const status = e.node.appointmentStatus; const status = e.node.status;
return status !== 'CANCELLED' && status !== 'COMPLETED' && status !== 'NO_SHOW'; return status !== 'CANCELLED' && status !== 'COMPLETED' && status !== 'NO_SHOW';
}); });
const slots = activeAppointments.map(e => { const slots = activeAppointments.map(e => {
@@ -223,14 +225,14 @@ export const AppointmentForm = ({
notify.success('Appointment Updated'); notify.success('Appointment Updated');
} else { } else {
// Double-check slot availability before booking // Double-check slot availability before booking
const checkResult = await apiClient.graphql<{ appointments: { edges: Array<{ node: { appointmentStatus: string } }> } }>( const checkResult = await apiClient.graphql<{ appointments: { edges: Array<{ node: { status: string } }> } }>(
`{ appointments(filter: { `{ appointments(filter: {
doctorId: { eq: "${doctor}" }, doctorId: { eq: "${doctor}" },
scheduledAt: { gte: "${date}T${timeSlot}:00", lte: "${date}T${timeSlot}:00" } scheduledAt: { gte: "${date}T${timeSlot}:00", lte: "${date}T${timeSlot}:00" }
}) { edges { node { appointmentStatus } } } }`, }) { edges { node { status } } } }`,
); );
const activeBookings = checkResult.appointments.edges.filter(e => const activeBookings = checkResult.appointments.edges.filter(e =>
e.node.appointmentStatus !== 'CANCELLED' && e.node.appointmentStatus !== 'NO_SHOW', e.node.status !== 'CANCELLED' && e.node.status !== 'NO_SHOW',
); );
if (activeBookings.length > 0) { if (activeBookings.length > 0) {
setError('This slot was just booked by someone else. Please select a different time.'); setError('This slot was just booked by someone else. Please select a different time.');
@@ -248,12 +250,12 @@ export const AppointmentForm = ({
scheduledAt, scheduledAt,
durationMin: 30, durationMin: 30,
appointmentType: 'CONSULTATION', appointmentType: 'CONSULTATION',
appointmentStatus: 'SCHEDULED', status: 'SCHEDULED',
doctorName: selectedDoctor?.name ?? '', doctorName: selectedDoctor?.name ?? '',
department: selectedDoctor?.department ?? '', department: selectedDoctor?.department ?? '',
doctorId: doctor, doctorId: doctor,
reasonForVisit: chiefComplaint || null, reasonForVisit: chiefComplaint || null,
...(leadId ? { patientId: leadId } : {}), ...(patientId ? { patientId } : {}),
}, },
}, },
); );
@@ -294,7 +296,7 @@ export const AppointmentForm = ({
}`, }`,
{ {
id: existingAppointment.id, id: existingAppointment.id,
data: { appointmentStatus: 'CANCELLED' }, data: { status: 'CANCELLED' },
}, },
); );
notify.success('Appointment Cancelled'); notify.success('Appointment Cancelled');

View File

@@ -1,14 +1,16 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSparkles, faUser } from '@fortawesome/pro-duotone-svg-icons'; import { faSparkles, faUser, faCalendarCheck } from '@fortawesome/pro-duotone-svg-icons';
import { faIcon } from '@/lib/icon-wrapper';
import { AiChatPanel } from './ai-chat-panel'; import { AiChatPanel } from './ai-chat-panel';
import { LiveTranscript } from './live-transcript';
import { useCallAssist } from '@/hooks/use-call-assist';
import { Badge } from '@/components/base/badges/badges'; import { Badge } from '@/components/base/badges/badges';
import { apiClient } from '@/lib/api-client';
import { formatPhone, formatShortDate } from '@/lib/format'; import { formatPhone, formatShortDate } from '@/lib/format';
import { cx } from '@/utils/cx'; import { cx } from '@/utils/cx';
import type { Lead, LeadActivity } from '@/types/entities'; import type { Lead, LeadActivity } from '@/types/entities';
const CalendarCheck = faIcon(faCalendarCheck);
type ContextTab = 'ai' | 'lead360'; type ContextTab = 'ai' | 'lead360';
interface ContextPanelProps { interface ContextPanelProps {
@@ -19,7 +21,7 @@ interface ContextPanelProps {
callUcid?: string | null; callUcid?: string | null;
} }
export const ContextPanel = ({ selectedLead, activities, callerPhone, isInCall, callUcid }: ContextPanelProps) => { export const ContextPanel = ({ selectedLead, activities, callerPhone }: ContextPanelProps) => {
const [activeTab, setActiveTab] = useState<ContextTab>('ai'); const [activeTab, setActiveTab] = useState<ContextTab>('ai');
// Auto-switch to lead 360 when a lead is selected // Auto-switch to lead 360 when a lead is selected
@@ -29,13 +31,6 @@ export const ContextPanel = ({ selectedLead, activities, callerPhone, isInCall,
} }
}, [selectedLead?.id]); }, [selectedLead?.id]);
const { transcript, suggestions, connected: assistConnected } = useCallAssist(
isInCall ?? false,
callUcid ?? null,
selectedLead?.id ?? null,
callerPhone ?? null,
);
const callerContext = selectedLead ? { const callerContext = selectedLead ? {
callerPhone: selectedLead.contactPhone?.[0]?.number ?? callerPhone, callerPhone: selectedLead.contactPhone?.[0]?.number ?? callerPhone,
leadId: selectedLead.id, leadId: selectedLead.id,
@@ -68,30 +63,57 @@ export const ContextPanel = ({ selectedLead, activities, callerPhone, isInCall,
)} )}
> >
<FontAwesomeIcon icon={faUser} className="size-3.5" /> <FontAwesomeIcon icon={faUser} className="size-3.5" />
Lead 360 {(selectedLead as any)?.patientId ? 'Patient 360' : 'Lead 360'}
</button> </button>
</div> </div>
{/* Tab content */} {/* Tab content */}
<div className="flex-1 overflow-y-auto"> {activeTab === 'ai' && (
{activeTab === 'ai' && ( <div className="flex flex-1 flex-col overflow-hidden p-4">
isInCall ? ( <AiChatPanel callerContext={callerContext} />
<LiveTranscript transcript={transcript} suggestions={suggestions} connected={assistConnected} /> </div>
) : ( )}
<div className="flex h-full flex-col p-4"> {activeTab === 'lead360' && (
<AiChatPanel callerContext={callerContext} /> <div className="flex-1 overflow-y-auto">
</div>
)
)}
{activeTab === 'lead360' && (
<Lead360Tab lead={selectedLead} activities={activities} /> <Lead360Tab lead={selectedLead} activities={activities} />
)} </div>
</div> )}
</div> </div>
); );
}; };
const Lead360Tab = ({ lead, activities }: { lead: Lead | null; activities: LeadActivity[] }) => { const Lead360Tab = ({ lead, activities }: { lead: Lead | null; activities: LeadActivity[] }) => {
const [patientData, setPatientData] = useState<any>(null);
const [loadingPatient, setLoadingPatient] = useState(false);
// Fetch patient data when lead has a patientId (returning patient)
useEffect(() => {
const patientId = (lead as any)?.patientId;
if (!patientId) {
setPatientData(null);
return;
}
setLoadingPatient(true);
apiClient.graphql<{ patients: { edges: Array<{ node: any }> } }>(
`query GetPatient($id: UUID!) { patients(filter: { id: { eq: $id } }) { edges { node {
id fullName { firstName lastName } dateOfBirth gender patientType
phones { primaryPhoneNumber } emails { primaryEmail }
appointments(first: 5, orderBy: [{ scheduledAt: DescNullsLast }]) { edges { node {
id scheduledAt status doctorName department reasonForVisit appointmentType
} } }
calls(first: 5, orderBy: [{ startedAt: DescNullsLast }]) { edges { node {
id callStatus disposition direction startedAt durationSec agentName
} } }
} } } }`,
{ id: patientId },
{ silent: true },
).then(data => {
setPatientData(data.patients.edges[0]?.node ?? null);
}).catch(() => setPatientData(null))
.finally(() => setLoadingPatient(false));
}, [(lead as any)?.patientId]);
if (!lead) { if (!lead) {
return ( return (
<div className="flex flex-col items-center justify-center py-16 text-center px-4"> <div className="flex flex-col items-center justify-center py-16 text-center px-4">
@@ -112,6 +134,15 @@ const Lead360Tab = ({ lead, activities }: { lead: Lead | null; activities: LeadA
.sort((a, b) => new Date(b.occurredAt ?? b.createdAt ?? '').getTime() - new Date(a.occurredAt ?? a.createdAt ?? '').getTime()) .sort((a, b) => new Date(b.occurredAt ?? b.createdAt ?? '').getTime() - new Date(a.occurredAt ?? a.createdAt ?? '').getTime())
.slice(0, 10); .slice(0, 10);
const isReturning = !!patientData;
const appointments = patientData?.appointments?.edges?.map((e: any) => e.node) ?? [];
const patientCalls = patientData?.calls?.edges?.map((e: any) => e.node) ?? [];
const patientAge = patientData?.dateOfBirth
? Math.floor((Date.now() - new Date(patientData.dateOfBirth).getTime()) / (365.25 * 24 * 60 * 60 * 1000))
: null;
const patientGender = patientData?.gender === 'MALE' ? 'M' : patientData?.gender === 'FEMALE' ? 'F' : null;
return ( return (
<div className="p-4 space-y-4"> <div className="p-4 space-y-4">
{/* Profile */} {/* Profile */}
@@ -120,6 +151,12 @@ const Lead360Tab = ({ lead, activities }: { lead: Lead | null; activities: LeadA
{phone && <p className="text-sm text-secondary">{formatPhone(phone)}</p>} {phone && <p className="text-sm text-secondary">{formatPhone(phone)}</p>}
{email && <p className="text-xs text-tertiary">{email}</p>} {email && <p className="text-xs text-tertiary">{email}</p>}
<div className="mt-2 flex flex-wrap gap-1.5"> <div className="mt-2 flex flex-wrap gap-1.5">
{isReturning && (
<Badge size="sm" color="brand" type="pill-color">Returning Patient</Badge>
)}
{patientAge !== null && patientGender && (
<Badge size="sm" color="gray" type="pill-color">{patientAge}y · {patientGender}</Badge>
)}
{lead.leadStatus && <Badge size="sm" color="brand">{lead.leadStatus}</Badge>} {lead.leadStatus && <Badge size="sm" color="brand">{lead.leadStatus}</Badge>}
{lead.leadSource && <Badge size="sm" color="gray">{lead.leadSource}</Badge>} {lead.leadSource && <Badge size="sm" color="gray">{lead.leadSource}</Badge>}
{lead.priority && lead.priority !== 'NORMAL' && ( {lead.priority && lead.priority !== 'NORMAL' && (
@@ -129,11 +166,66 @@ const Lead360Tab = ({ lead, activities }: { lead: Lead | null; activities: LeadA
{lead.interestedService && ( {lead.interestedService && (
<p className="mt-2 text-sm text-secondary">Interested in: {lead.interestedService}</p> <p className="mt-2 text-sm text-secondary">Interested in: {lead.interestedService}</p>
)} )}
{lead.leadScore !== null && lead.leadScore !== undefined && (
<p className="text-xs text-tertiary">Lead score: {lead.leadScore}</p>
)}
</div> </div>
{/* Returning patient: Appointments */}
{loadingPatient && (
<p className="text-xs text-tertiary">Loading patient details...</p>
)}
{isReturning && appointments.length > 0 && (
<div>
<h4 className="mb-2 text-xs font-bold text-secondary uppercase">Appointments</h4>
<div className="space-y-2">
{appointments.map((appt: any) => {
const statusColors: Record<string, 'success' | 'brand' | 'warning' | 'error' | 'gray'> = {
COMPLETED: 'success', SCHEDULED: 'brand', CONFIRMED: 'brand',
CANCELLED: 'error', NO_SHOW: 'warning',
};
return (
<div key={appt.id} className="flex items-start gap-2 rounded-lg bg-secondary p-2">
<CalendarCheck className="mt-0.5 size-3.5 text-fg-brand-primary shrink-0" />
<div className="min-w-0 flex-1">
<div className="flex items-center gap-1.5">
<span className="text-xs font-semibold text-primary">
{appt.doctorName ?? 'Doctor'} · {appt.department ?? ''}
</span>
{appt.status && (
<Badge size="sm" color={statusColors[appt.status] ?? 'gray'}>
{appt.status.toLowerCase()}
</Badge>
)}
</div>
<p className="text-[10px] text-quaternary">
{appt.scheduledAt ? formatShortDate(appt.scheduledAt) : ''}
{appt.reasonForVisit ? `${appt.reasonForVisit}` : ''}
</p>
</div>
</div>
);
})}
</div>
</div>
)}
{/* Returning patient: Recent calls */}
{isReturning && patientCalls.length > 0 && (
<div>
<h4 className="mb-2 text-xs font-bold text-secondary uppercase">Recent Calls</h4>
<div className="space-y-1">
{patientCalls.map((call: any) => (
<div key={call.id} className="flex items-center gap-2 text-xs">
<div className="mt-0.5 size-1.5 shrink-0 rounded-full bg-fg-quaternary" />
<span className="text-primary">
{call.direction === 'INBOUND' ? 'Inbound' : 'Outbound'}
{call.disposition ? `${call.disposition.replace(/_/g, ' ').toLowerCase()}` : ''}
</span>
<span className="text-quaternary ml-auto">{call.startedAt ? formatShortDate(call.startedAt) : ''}</span>
</div>
))}
</div>
</div>
)}
{/* AI Insight */} {/* AI Insight */}
{(lead.aiSummary || lead.aiSuggestedAction) && ( {(lead.aiSummary || lead.aiSuggestedAction) && (
<div className="rounded-lg bg-brand-primary p-3"> <div className="rounded-lg bg-brand-primary p-3">

View File

@@ -15,9 +15,9 @@ export const AppShell = ({ children }: AppShellProps) => {
return ( return (
<SipProvider> <SipProvider>
<div className="flex min-h-screen bg-primary"> <div className="flex h-screen bg-primary">
<Sidebar activeUrl={pathname} /> <Sidebar activeUrl={pathname} />
<main className="flex flex-1 flex-col overflow-auto">{children}</main> <main className="flex flex-1 flex-col overflow-hidden">{children}</main>
{isCCAgent && pathname !== '/' && pathname !== '/call-desk' && <CallWidget />} {isCCAgent && pathname !== '/' && pathname !== '/call-desk' && <CallWidget />}
</div> </div>
</SipProvider> </SipProvider>

View File

@@ -1,6 +1,6 @@
import { useState } from 'react'; import { useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSidebarFlip, faSidebar } from '@fortawesome/pro-duotone-svg-icons'; import { faSidebarFlip, faSidebar, faPhone, faXmark, faDeleteLeft } from '@fortawesome/pro-duotone-svg-icons';
import { useAuth } from '@/providers/auth-provider'; import { useAuth } from '@/providers/auth-provider';
import { useData } from '@/providers/data-provider'; import { useData } from '@/providers/data-provider';
import { useWorklist } from '@/hooks/use-worklist'; import { useWorklist } from '@/hooks/use-worklist';
@@ -12,6 +12,8 @@ import { ActiveCallCard } from '@/components/call-desk/active-call-card';
import { Badge } from '@/components/base/badges/badges'; import { Badge } from '@/components/base/badges/badges';
import { AgentStatusToggle } from '@/components/call-desk/agent-status-toggle'; import { AgentStatusToggle } from '@/components/call-desk/agent-status-toggle';
import { apiClient } from '@/lib/api-client';
import { notify } from '@/lib/toast';
import { cx } from '@/utils/cx'; import { cx } from '@/utils/cx';
export const CallDeskPage = () => { export const CallDeskPage = () => {
@@ -23,6 +25,24 @@ export const CallDeskPage = () => {
const [contextOpen, setContextOpen] = useState(true); const [contextOpen, setContextOpen] = useState(true);
const [activeMissedCallId, setActiveMissedCallId] = useState<string | null>(null); const [activeMissedCallId, setActiveMissedCallId] = useState<string | null>(null);
const [callDismissed, setCallDismissed] = useState(false); const [callDismissed, setCallDismissed] = useState(false);
const [diallerOpen, setDiallerOpen] = useState(false);
const [dialNumber, setDialNumber] = useState('');
const [dialling, setDialling] = useState(false);
const handleDial = async () => {
const num = dialNumber.replace(/[^0-9]/g, '');
if (num.length < 10) { notify.error('Enter a valid phone number'); return; }
setDialling(true);
try {
await apiClient.post('/api/ozonetel/dial', { phoneNumber: num });
setDiallerOpen(false);
setDialNumber('');
} catch {
notify.error('Dial failed');
} finally {
setDialling(false);
}
};
// Reset callDismissed when a new call starts (ringing in or out) // Reset callDismissed when a new call starts (ringing in or out)
if (callDismissed && (callState === 'ringing-in' || callState === 'ringing-out')) { if (callDismissed && (callState === 'ringing-in' || callState === 'ringing-out')) {
@@ -35,7 +55,11 @@ export const CallDeskPage = () => {
? marketingLeads.find((l) => l.contactPhone?.[0]?.number?.endsWith(callerNumber) || callerNumber.endsWith(l.contactPhone?.[0]?.number ?? '---')) ? marketingLeads.find((l) => l.contactPhone?.[0]?.number?.endsWith(callerNumber) || callerNumber.endsWith(l.contactPhone?.[0]?.number ?? '---'))
: null; : null;
const activeLead = isInCall ? (callerLead ?? selectedLead) : selectedLead; // For inbound calls, only use matched lead (don't fall back to previously selected worklist lead)
// For outbound (agent initiated from worklist), selectedLead is the intended target
const activeLead = isInCall
? (callerLead ?? (callState === 'ringing-out' ? selectedLead : null))
: selectedLead;
const activeLeadFull = activeLead as any; const activeLeadFull = activeLead as any;
return ( return (
@@ -102,6 +126,69 @@ export const CallDeskPage = () => {
)} )}
</div> </div>
</div> </div>
{/* Dialler FAB */}
{!isInCall && (
<div className="fixed bottom-6 right-6 z-40 flex flex-col items-end gap-3">
{diallerOpen && (
<div className="w-72 rounded-xl bg-primary shadow-xl ring-1 ring-secondary p-4">
<div className="flex items-center justify-between mb-3">
<span className="text-sm font-semibold text-primary">Dial</span>
<button onClick={() => setDiallerOpen(false)} className="text-fg-quaternary hover:text-fg-secondary">
<FontAwesomeIcon icon={faXmark} className="size-4" />
</button>
</div>
{/* Number display */}
<div className="flex items-center gap-2 mb-3 px-3 py-2.5 rounded-lg bg-secondary min-h-[40px]">
<span className="flex-1 text-lg font-semibold text-primary tracking-wider text-center">
{dialNumber || <span className="text-placeholder font-normal text-sm">Enter number</span>}
</span>
{dialNumber && (
<button onClick={() => setDialNumber(dialNumber.slice(0, -1))} className="text-fg-quaternary hover:text-fg-secondary shrink-0">
<FontAwesomeIcon icon={faDeleteLeft} className="size-4" />
</button>
)}
</div>
{/* Numpad */}
<div className="grid grid-cols-3 gap-1.5 mb-3">
{['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'].map(key => (
<button
key={key}
onClick={() => setDialNumber(prev => prev + key)}
className="flex items-center justify-center h-11 rounded-lg text-sm font-semibold text-primary bg-primary hover:bg-secondary border border-secondary transition duration-100 ease-linear active:scale-95"
>
{key}
</button>
))}
</div>
{/* Call button */}
<button
onClick={handleDial}
disabled={dialling || dialNumber.replace(/[^0-9]/g, '').length < 10}
className="w-full flex items-center justify-center gap-2 rounded-lg bg-success-solid py-2.5 text-sm font-medium text-white hover:opacity-90 disabled:bg-disabled disabled:cursor-not-allowed transition duration-100 ease-linear"
>
<FontAwesomeIcon icon={faPhone} className="size-3.5" />
{dialling ? 'Dialling...' : 'Call'}
</button>
</div>
)}
<button
onClick={() => setDiallerOpen(!diallerOpen)}
className={cx(
'flex size-14 items-center justify-center rounded-full shadow-lg transition duration-100 ease-linear',
diallerOpen
? 'bg-secondary text-fg-secondary'
: 'bg-brand-solid text-white hover:bg-brand-solid_hover',
)}
title="Quick dial"
>
<FontAwesomeIcon icon={diallerOpen ? faXmark : faPhone} className="size-5" />
</button>
</div>
)}
</div> </div>
); );
}; };