diff --git a/src/components/call-desk/active-call-card.tsx b/src/components/call-desk/active-call-card.tsx index 9289b9b..8d6b39f 100644 --- a/src/components/call-desk/active-call-card.tsx +++ b/src/components/call-desk/active-call-card.tsx @@ -2,7 +2,7 @@ import { useState, useRef } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPhone, faPhoneHangup, faMicrophone, faMicrophoneSlash, - faPause, faPlay, faCalendarPlus, faCheckCircle, + faPause, faPlay, faCalendarPlus, faPhoneArrowRight, faRecordVinyl, faClipboardQuestion, } from '@fortawesome/pro-duotone-svg-icons'; import { Button } from '@/components/base/buttons/button'; @@ -42,7 +42,6 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete const setCallerNumber = useSetAtom(sipCallerNumberAtom); const setCallUcid = useSetAtom(sipCallUcidAtom); const [postCallStage, setPostCallStage] = useState(null); - const [savedDisposition, setSavedDisposition] = useState(null); const [appointmentOpen, setAppointmentOpen] = useState(false); const [appointmentBookedDuringCall, setAppointmentBookedDuringCall] = useState(false); const [transferOpen, setTransferOpen] = useState(false); @@ -60,7 +59,6 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete const phoneDisplay = phone ? formatPhone(phone) : callerPhone || 'Unknown'; const handleDisposition = async (disposition: CallDisposition, notes: string) => { - setSavedDisposition(disposition); // Submit disposition to sidecar — handles Ozonetel ACW release if (callUcid) { @@ -76,12 +74,8 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete }).catch((err) => console.warn('Disposition failed:', err)); } - if (disposition === 'APPOINTMENT_BOOKED') { - setPostCallStage('appointment'); - setAppointmentOpen(true); - } else if (disposition === 'FOLLOW_UP_SCHEDULED') { - setPostCallStage('follow-up'); - // Create follow-up + // Side effects per disposition type + if (disposition === 'FOLLOW_UP_SCHEDULED') { try { await apiClient.graphql(`mutation($data: FollowUpCreateInput!) { createFollowUp(data: $data) { id } }`, { data: { @@ -97,27 +91,23 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete } catch { notify.info('Follow-up', 'Could not auto-create follow-up'); } - setPostCallStage('done'); - } else { - notify.success('Call Logged', `Disposition: ${disposition.replace(/_/g, ' ').toLowerCase()}`); - setPostCallStage('done'); } + + // Disposition is the last step — return to worklist immediately + notify.success('Call Logged', `Disposition: ${disposition.replace(/_/g, ' ').toLowerCase()}`); + handleReset(); }; const handleAppointmentSaved = () => { setAppointmentOpen(false); notify.success('Appointment Booked', 'Payment link will be sent to the patient'); - // If booked during active call, don't skip to 'done' — wait for disposition after call ends if (callState === 'active') { setAppointmentBookedDuringCall(true); - } else { - setPostCallStage('done'); } }; const handleReset = () => { setPostCallStage(null); - setSavedDisposition(null); setCallState('idle'); setCallerNumber(null); setCallUcid(null); @@ -192,50 +182,6 @@ export const ActiveCallCard = ({ lead, callerPhone, missedCallId, onCallComplete // Post-call flow takes priority over active state (handles race between hangup + SIP ended event) if (postCallStage !== null || callState === 'ended' || callState === 'failed') { - // Done state - if (postCallStage === 'done') { - return ( -
- -

Call Completed

-

- {savedDisposition ? savedDisposition.replace(/_/g, ' ').toLowerCase() : 'logged'} -

- -
- ); - } - - // Appointment booking after disposition — auto-return when form closes - if (postCallStage === 'appointment') { - return ( - <> -
- -

Booking Appointment

-

for {fullName || phoneDisplay}

- -
- { - setAppointmentOpen(open); - if (!open) setPostCallStage('done'); - }} - callerNumber={callerPhone} - leadName={fullName || null} - leadId={lead?.id ?? null} - patientId={(lead as any)?.patientId ?? null} - onSaved={handleAppointmentSaved} - /> - - ); - } - // Disposition form + enquiry access return ( <>