From d8f9174a55006fdf4cf47e5f04b25dc40b508b98 Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Mon, 13 Apr 2026 10:59:10 +0530 Subject: [PATCH] fix: filter time slots by selected clinic/branch Slots were fetched by doctor+date but not filtered by clinic. A doctor visiting multiple branches showed all slots regardless of selected branch. Now filters by clinicId when a clinic is selected. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/call-desk/appointment-form.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/call-desk/appointment-form.tsx b/src/components/call-desk/appointment-form.tsx index 9c95d2a..acb5bc8 100644 --- a/src/components/call-desk/appointment-form.tsx +++ b/src/components/call-desk/appointment-form.tsx @@ -108,13 +108,16 @@ export const AppointmentForm = ({ apiClient.get>( `/api/masterdata/slots?doctorId=${doctor}&date=${date}`, ).then(slots => { - setTimeSlotItems(slots.map(s => ({ id: s.time, label: s.label }))); - // Auto-select clinic from the slot's clinic - if (slots.length > 0 && !clinic) { + // Filter by selected clinic — doctor may visit multiple branches + const filtered = clinic ? slots.filter(s => s.clinicId === clinic) : slots; + setTimeSlotItems(filtered.map(s => ({ id: s.time, label: s.label }))); + // Auto-select clinic from the slot's clinic only if no clinic chosen + if (filtered.length === 0 && slots.length > 0 && !clinic) { setClinic(slots[0].clinicId); + setTimeSlotItems(slots.filter(s => s.clinicId === slots[0].clinicId).map(s => ({ id: s.time, label: s.label }))); } }).catch(() => setTimeSlotItems([])); - }, [doctor, date]); + }, [doctor, date, clinic]); // Availability state const [bookedSlots, setBookedSlots] = useState([]);