From 6c32d76d7e432fe99e7b5c388f8d1c7ea5c5e5f6 Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Wed, 15 Apr 2026 13:50:10 +0530 Subject: [PATCH] fix(appointment-form): keep saved doctor visible on edit when department filter mismatches Edit mode prefilled clinic + department + doctorId, but the doctor Select rendered blank because the doctor-list filter (doctors where department === selectedDept) excluded the saved doctor. Root cause: the Appointment.department string doesn't always match the doctor's current department enum value. Fix: doctorSelectItems now always includes the currently-selected doctor as the first item, even when the department filter would exclude them. Once the user changes department or doctor, the filter behaves normally. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/call-desk/appointment-form.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/call-desk/appointment-form.tsx b/src/components/call-desk/appointment-form.tsx index 9aa475a..e1c2142 100644 --- a/src/components/call-desk/appointment-form.tsx +++ b/src/components/call-desk/appointment-form.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faUserPen } from '@fortawesome/pro-duotone-svg-icons'; import { Input } from '@/components/base/input/input'; @@ -242,7 +242,19 @@ export const AppointmentForm = ({ const filteredDoctors = department ? doctors.filter(d => d.department === department) : doctors; - const doctorSelectItems = filteredDoctors.map(d => ({ id: d.id, label: d.name })); + // Always include the currently-selected doctor even if the department + // filter would exclude them. Needed for edit mode: the saved + // Appointment.department may be stored as a display string ("ENT") or + // a legacy value that doesn't match the doctor's current department + // enum — without this, the Select renders blank. + const doctorSelectItems = useMemo(() => { + const items = filteredDoctors.map(d => ({ id: d.id, label: d.name })); + if (doctor && !items.some(i => i.id === doctor)) { + const selected = doctors.find(d => d.id === doctor); + if (selected) items.unshift({ id: selected.id, label: selected.name }); + } + return items; + }, [filteredDoctors, doctors, doctor]); const timeSlotSelectItems = timeSlotItems.map(slot => ({ ...slot,