Two faults, one root: the per-context booking work updated ScheduleSection but left the rest of the panel calling slot endpoints without clinic_uuid. Absent clinic_uuid means the personal practice, so the panel asked about a schedule the doctor barely uses and got nothing back. - useClinicContext() resolves the current environment once and is used by the appointments page, useDoctorBookingServices, ServiceSlotPicker and both queries in NewAppointmentDrawer (a fifth call site a sweep turned up). It returns null in a doctor's personal environment so the mirror-image bug — a doctor seeing the clinic's schedule at their own practice — cannot appear. clinicUuid is part of every query key; without it the cache leaks across environments. - appointment-slots returns empty_reason (no_schedule | holiday | day_off | outside_window). TurnsTimeline rendered «این روز تعطیل است» for any empty day, which is what the bug report actually saw; it now says which of the four it is. - booking-locations lists a location only when the context has an address and an active shift points at it. The dev data had three "personal" schedules whose shifts referenced the clinic's address, so the public site advertised a personal practice that could never be booked. - ?date= adds available_on_date per location, validated as a real calendar date. - MyAppointmentsController and AdminApiController resolved the appointment address with no context and could store the wrong one. Both now go through the new BookingContextResolver, which also replaces AppointmentController's private copy of the same membership check. - app:schedule:audit-locations reports shifts pointing at a missing or foreign address; --fix deactivates them rather than deleting. Verified against the reported doctor: same date, no clinic_uuid -> 0 sessions, with it -> 1 session; a full week matches the configured Sat/Tue/Wed/Thu. Suite: 417 tests, 2 failures — both pre-existing and unrelated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.4 KiB
TypeScript
29 lines
1.4 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { useAuthStore } from '../stores/authStore';
|
|
|
|
/**
|
|
* uuid کلینیکِ محیط جاری، یا null وقتی کاربر در محیط شخصی خودش است.
|
|
*
|
|
* تنظیمات نوبتدهی per-context است و نبودِ clinic_uuid در درخواست یعنی «مطب شخصی»،
|
|
* نه «هر برنامهای که پیدا شد». پس این تفکیک باید دقیق باشد: پزشکی که هم مطب شخصی
|
|
* دارد هم عضو کلینیک است، در محیط شخصی نباید برنامهٔ کلینیک را ببیند و برعکس.
|
|
*
|
|
* fallback به availableContexts فقط برای مالک کلینیک است — قبل از اولین
|
|
* switch-context، هنوز context پر نشده ولی نقش کاربر تکلیف را روشن میکند.
|
|
*/
|
|
export function useClinicContext(): string | null {
|
|
const dbUuid = useAuthStore(s => s.dbUuid);
|
|
const context = useAuthStore(s => s.context);
|
|
const primaryRole = useAuthStore(s => s.primaryRole);
|
|
const availableContexts = useAuthStore(s => s.availableContexts);
|
|
|
|
return useMemo(() => {
|
|
if (context?.type === 'clinic') return dbUuid;
|
|
if (context?.type === 'doctor') return null;
|
|
|
|
return primaryRole === 'clinic'
|
|
? availableContexts.find(c => c.type === 'clinic')?.db_uuid ?? dbUuid
|
|
: null;
|
|
}, [context, dbUuid, primaryRole, availableContexts]);
|
|
}
|