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 <noreply@anthropic.com>
This commit is contained in:
2026-07-16 22:39:55 -04:00
parent 6004bcb73d
commit 95abbabb36

View File

@@ -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);
}
}}
>
<FormControl>
<SelectTrigger>