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) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 10:59:10 +05:30
parent 8cccd55fb6
commit d8f9174a55

View File

@@ -108,13 +108,16 @@ export const AppointmentForm = ({
apiClient.get<Array<{ time: string; label: string; clinicId: string; clinicName: string }>>(
`/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<string[]>([]);