feat(appointment-settings): let clinics manage each member doctor's booking
The API and React components were already parameterized by doctor uuid, but 14 copy-pasted identity checks limited every endpoint to "the doctor themselves or an admin", so a clinic owner could not touch a member doctor's booking setup. - Replaces those 14 checks with one denyDoctorAccess() that also admits the owner of a clinic the doctor belongs to, and a member doctor holding the clinic's appointment_settings permission (view for GET, update for writes). A doctor's own settings short-circuit before any permission lookup. - Moves ScheduleSection and its tabs out of DoctorDetailPage into components/schedule/ScheduleSection.tsx so the doctor panel and the new clinic page render the same module instead of one page importing another. Pure relocation — no logic changed. - Adds ClinicAppointmentSettingsPage: one tab per clinic doctor, each rendering that same section. The tab wrapper is keyed by doctor uuid so in-progress schedule edits cannot leak onto the wrong doctor. - insurance-pricing accepts an optional doctor_uuid (query on GET, body on PUT) under the same access rule, so the visit-price card works inside the clinic tabs. Fixes saveInsurancePricing calling getInsurancePricing with the wrong argument by extracting the shared pricingPayload(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,15 +6,18 @@ import { formatRial, rialToToman, tomanToRial } from '../lib/utils';
|
||||
|
||||
interface Pricing { free_visit_price_rials: number; require_visit_price: boolean }
|
||||
|
||||
export default function FreeVisitPrice() {
|
||||
/** بدون doctorUuid روی موجودیت کاربر جاری کار میکند؛ با آن، قیمت همان پزشک. */
|
||||
export default function FreeVisitPrice({ doctorUuid }: { doctorUuid?: string }) {
|
||||
const qc = useQueryClient();
|
||||
const [value, setValue] = useState('');
|
||||
const [required, setRequired] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const { data } = useQuery<{ data: Pricing }>({
|
||||
queryKey: ['insurance-pricing'],
|
||||
queryFn: () => api.get('/api/v1/insurance-pricing'),
|
||||
queryKey: ['insurance-pricing', doctorUuid ?? 'self'],
|
||||
queryFn: () => api.get(doctorUuid
|
||||
? `/api/v1/insurance-pricing?doctor_uuid=${doctorUuid}`
|
||||
: '/api/v1/insurance-pricing'),
|
||||
});
|
||||
const pricing = (data as any)?.data as Pricing | undefined;
|
||||
|
||||
@@ -29,10 +32,11 @@ export default function FreeVisitPrice() {
|
||||
mutationFn: () => api.put('/api/v1/insurance-pricing', {
|
||||
free_visit_price_rials: tomanToRial(Number(value) || 0),
|
||||
require_visit_price: required,
|
||||
...(doctorUuid ? { doctor_uuid: doctorUuid } : {}),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
toast.success('قیمت ویزیت ذخیره شد');
|
||||
qc.invalidateQueries({ queryKey: ['insurance-pricing'] });
|
||||
qc.invalidateQueries({ queryKey: ['insurance-pricing', doctorUuid ?? 'self'] });
|
||||
},
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user