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:
@@ -325,15 +325,6 @@ export function AppointmentForm({
|
|||||||
setSelectOpen(open);
|
setSelectOpen(open);
|
||||||
if (!open) {
|
if (!open) {
|
||||||
setPatientSearchTerm("");
|
setPatientSearchTerm("");
|
||||||
if (
|
|
||||||
prefillPatient &&
|
|
||||||
patients &&
|
|
||||||
patients.some(
|
|
||||||
(p) => Number(p.id) === Number(prefillPatient.id)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
setPrefillPatient(null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!patients || patients.length === 0) refetchPatients();
|
if (!patients || patients.length === 0) refetchPatients();
|
||||||
}
|
}
|
||||||
@@ -348,9 +339,15 @@ export function AppointmentForm({
|
|||||||
? ""
|
? ""
|
||||||
: String(field.value)
|
: String(field.value)
|
||||||
}
|
}
|
||||||
onValueChange={(val) =>
|
onValueChange={(val) => {
|
||||||
field.onChange(val === "" ? undefined : Number(val))
|
field.onChange(val === "" ? undefined : Number(val));
|
||||||
}
|
if (val !== "") {
|
||||||
|
const picked = patients.find(
|
||||||
|
(p) => Number(p.id) === Number(val)
|
||||||
|
);
|
||||||
|
if (picked) setPrefillPatient(picked);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
|
|||||||
Reference in New Issue
Block a user