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([]);