From 95abbabb3605cf0154f12457a8df7f8c9c9bf2db Mon Sep 17 00:00:00 2001 From: Gitead Date: Thu, 16 Jul 2026 22:39:55 -0400 Subject: [PATCH] fix: patient selection in appointment form disappearing for non-recent patients Selecting a patient from search results only stored the ID, not the patient object. Closing the dropdown reset the search term and reverted the list to "recent 50" patients, which often didn't include the just selected patient, leaving nothing to render in the trigger. Also removed a redundant prefillPatient reset that nulled the fallback display before the list swap even happened. Co-Authored-By: Claude Sonnet 5 --- .../appointments/appointment-form.tsx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/Frontend/src/components/appointments/appointment-form.tsx b/apps/Frontend/src/components/appointments/appointment-form.tsx index c8da8537..1cdd592f 100755 --- a/apps/Frontend/src/components/appointments/appointment-form.tsx +++ b/apps/Frontend/src/components/appointments/appointment-form.tsx @@ -325,15 +325,6 @@ export function AppointmentForm({ setSelectOpen(open); if (!open) { setPatientSearchTerm(""); - if ( - prefillPatient && - patients && - patients.some( - (p) => Number(p.id) === Number(prefillPatient.id) - ) - ) { - setPrefillPatient(null); - } } else { if (!patients || patients.length === 0) refetchPatients(); } @@ -348,9 +339,15 @@ export function AppointmentForm({ ? "" : String(field.value) } - onValueChange={(val) => - field.onChange(val === "" ? undefined : Number(val)) - } + onValueChange={(val) => { + field.onChange(val === "" ? undefined : Number(val)); + if (val !== "") { + const picked = patients.find( + (p) => Number(p.id) === Number(val) + ); + if (picked) setPrefillPatient(picked); + } + }} >