diff --git a/src/components/call-desk/active-call-card.tsx b/src/components/call-desk/active-call-card.tsx index b92a9bf..c0529a9 100644 --- a/src/components/call-desk/active-call-card.tsx +++ b/src/components/call-desk/active-call-card.tsx @@ -14,6 +14,7 @@ import { setOutboundPending } from '@/state/sip-manager'; import { useSip } from '@/providers/sip-provider'; import { DispositionModal } from './disposition-modal'; import type { CallAction } from './disposition-modal'; +import { Dialog, Modal, ModalOverlay } from '@/components/application/modals/modal'; import { AppointmentForm } from './appointment-form'; import { TransferDialog } from './transfer-dialog'; import { EnquiryForm } from './enquiry-form'; @@ -74,12 +75,17 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete const leadAppointments = useMemo(() => { const patientId = (lead as any)?.patientId; if (!patientId) return []; + const now = Date.now(); return appointments .filter((a) => a.patientId === patientId && a.appointmentStatus !== 'CANCELLED' && a.appointmentStatus !== 'NO_SHOW' - && a.appointmentStatus !== 'COMPLETED', + && a.appointmentStatus !== 'COMPLETED' + // Only future appointments make sense as reschedule targets. + // Past ones can't be edited — they already happened. + && a.scheduledAt + && new Date(a.scheduledAt).getTime() >= now, ) .sort((a, b) => new Date(a.scheduledAt ?? '').getTime() - new Date(b.scheduledAt ?? '').getTime()); }, [appointments, lead]); @@ -89,6 +95,12 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete [leadAppointments, editingApptId], ); + // Pending pill click awaiting the reschedule-confirm modal. When the + // agent clicks a pill, we store the appointment id here + open the modal. + // Yes → promote to editingApptId in edit mode. No → promote in view mode. + const [pendingApptId, setPendingApptId] = useState(null); + const [apptMode, setApptMode] = useState<'edit' | 'view'>('edit'); + const agentConfig = localStorage.getItem('helix_agent_config'); const agentIdForState = agentConfig ? (() => { try { return JSON.parse(agentConfig).ozonetelAgentId; } catch { return null; } })() : null; const { supervisorPresence } = useAgentState(agentIdForState); @@ -397,7 +409,7 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete + + + + )} + + + + {/* Disposition Modal — the ONLY path to end a call */} void; existingAppointment?: ExistingAppointment | null; + // When true, the form shows the existing appointment's data in a + // disabled state — no input editing, no Save/Cancel. Only a Close + // button. Used by the reschedule-confirm flow when the agent picks + // "No, just view" on an upcoming-appointment pill. + readOnly?: boolean; }; type DoctorRecord = { id: string; name: string; department: string; clinic: string }; @@ -60,6 +65,7 @@ export const AppointmentForm = ({ patientId, onSaved, existingAppointment, + readOnly = false, }: AppointmentFormProps) => { const isEditMode = !!existingAppointment; @@ -471,7 +477,7 @@ export const AppointmentForm = ({ placeholder="Full name" value={patientName} onChange={setPatientName} - isDisabled={!isNameEditable} + isDisabled={readOnly || !isNameEditable} /> {!isNameEditable && initialLeadName.length > 0 && ( @@ -544,7 +550,7 @@ export const AppointmentForm = ({ items={departmentItems} selectedKey={department} onSelectionChange={(key) => setDepartment(key as string)} - isDisabled={doctors.length === 0} + isDisabled={readOnly || doctors.length === 0} > {(item) => } @@ -555,7 +561,7 @@ export const AppointmentForm = ({ items={doctorSelectItems} selectedKey={doctor} onSelectionChange={(key) => setDoctor(key as string)} - isDisabled={!department} + isDisabled={readOnly || !department} > {(item) => } @@ -567,7 +573,7 @@ export const AppointmentForm = ({ value={date ? parseDate(date) : null} onChange={(val) => setDate(val ? val.toString() : '')} granularity="day" - isDisabled={!doctor} + isDisabled={readOnly || !doctor} /> @@ -585,7 +591,7 @@ export const AppointmentForm = ({ @@ -659,9 +666,11 @@ export const AppointmentForm = ({ - + {!readOnly && ( + + )}