diff --git a/src/components/call-desk/appointment-form.tsx b/src/components/call-desk/appointment-form.tsx index 7eead57..8495b9d 100644 --- a/src/components/call-desk/appointment-form.tsx +++ b/src/components/call-desk/appointment-form.tsx @@ -264,13 +264,16 @@ export const AppointmentForm = ({ if (!resolvedPatientId && callerNumber) { const trimmedName = patientName.trim(); const nameParts = { - firstName: trimmedName.split(' ')[0] || 'Unknown', + firstName: trimmedName.split(' ')[0] || '', lastName: trimmedName.split(' ').slice(1).join(' ') || '', }; + // Normalize phone to +91XXXXXXXXXX format + const phoneDigits = callerNumber.replace(/\D/g, '').slice(-10); + const phoneE164 = `+91${phoneDigits}`; try { const created = await apiClient.graphql<{ createPatient: { id: string } }>( `mutation($data: PatientCreateInput!) { createPatient(data: $data) { id } }`, - { data: { fullName: nameParts, phones: { primaryPhoneNumber: callerNumber }, patientType: 'NEW' } }, + { data: { fullName: nameParts, phones: { primaryPhoneNumber: phoneE164 }, patientType: 'NEW' } }, ); resolvedPatientId = created.createPatient.id; } catch (err) { diff --git a/src/pages/call-history.tsx b/src/pages/call-history.tsx index 3af72d3..3b35a94 100644 --- a/src/pages/call-history.tsx +++ b/src/pages/call-history.tsx @@ -234,7 +234,8 @@ export const CallHistoryPage = () => { {(call) => { - const patientName = call.leadName ?? leadNameMap.get(call.leadId ?? '') ?? 'Unknown'; + const phoneRawForName = call.callerNumber?.[0]?.number ?? ''; + const patientName = call.leadName ?? leadNameMap.get(call.leadId ?? '') ?? (phoneRawForName ? formatPhone({ number: phoneRawForName, callingCode: '+91' }) : 'Unknown'); const phoneDisplay = formatPhoneDisplay(call); const phoneRaw = call.callerNumber?.[0]?.number ?? ''; const dispositionCfg = call.disposition !== null ? dispositionConfig[call.disposition] : null;