Files
clinicpro/assets/admin/pages/ClinicDoctorsPage.tsx
T
hamedandClaude Opus 4.8 a3b29404f4 fix(secretary): gate CRUD action buttons across all panel pages by permission
Backend already returned 403 for ungranted secretary actions, but the UI still
showed the add/edit/delete buttons (e.g. clinic-services showed «بخش جدید» to a
secretary without services.create). Sweep every secretary-reachable page so each
create/edit/delete/manage control renders only when the matching
usePermissions().can(resource, action) is true. Owner/doctor/clinic are
unaffected — can() returns true when there is no permission context — so this
restricts only secretaries and mirrors the server checks.

Pages/components gated (resource):
- services: ClinicServicesPage, ServiceDetailPage (+ its tabs)
- inventory: InventoryPage, InventoryItemsTable, InventoryActionsMenu, PackagesView
- tags: TagsSettingsPage · staff: StaffPage · discounts: DiscountTab
- sms: SmsWalletPage · insurances: TenantInsuranceContracts
- clinic_doctors: ClinicDoctorsPage + ClinicDoctorsManager (props, default true)
- patients: PatientsListPage, MyPatientsPage, PatientDetailPage (records/notes/
  sessions/attachments/calls/wallet — create/update/delete split)
- appointments: AppointmentsPage (add + empty-slot booking gated by create),
  TurnsTable (status dropdown → read-only badge without update_status; actions
  menu hidden without manage/cancel)
- appointment_settings: AppointmentSettingsPage + ClinicAppointmentSettingsPage
  pass readOnly to ScheduleSection + FreeVisitPrice (new readOnly prop)

Not gated: view/read, search, filter, tabs, navigation, export, and modal
submit buttons reachable only via an already-gated trigger.

tsc clean; full frontend suite 501/501 passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 18:39:58 +03:30

74 lines
3.0 KiB
TypeScript

import { useEffect, useMemo } from 'react';
import { Link } from 'react-router-dom';
import { PencilIcon } from '@heroicons/react/24/outline';
import { useAuthStore } from '../stores/authStore';
import { usePermissions } from '../hooks/usePermissions';
import SettingsLayout from '../components/layout/SettingsLayout';
import ClinicDoctorsManager from '../components/ClinicDoctorsManager';
/**
* ClinicDoctorsPage — the clinic-owner settings tab for managing the clinic's
* doctors (list, invite, detach) and pending invitations. Renders inside the
* settings shell instead of jumping to the standalone admin ClinicDetailPage.
* Clinic-info editing (name, gallery, addresses, specialties) stays on the full
* detail page, reachable via the "ویرایش اطلاعات کلینیک" link.
*/
function ClinicDoctorsContent() {
const { dbUuid, context, availableContexts, fetchMe } = useAuthStore();
// مجوزهای منشی؛ برای owner/کلینیک همیشه true (usePermissions بدون context آزاد است).
const { can } = usePermissions();
const canCreate = can('clinic_doctors', 'create');
const canUpdate = can('clinic_doctors', 'update');
const canDelete = can('clinic_doctors', 'delete');
useEffect(() => {
if (!dbUuid) fetchMe();
}, [dbUuid, fetchMe]);
// یک کاربر می‌تواند همزمان context پزشک و کلینیک داشته باشد؛ dbUuid فقط context فعال است.
// این صفحه همیشه باید uuid کلینیک را بفرستد، وگرنه همه اندپوینت‌های کلینیک ۴۰۴ می‌دهند.
const clinicUuid = useMemo(() => {
if (context?.type === 'clinic') return dbUuid;
return availableContexts.find(c => c.type === 'clinic')?.db_uuid ?? null;
}, [context, dbUuid, availableContexts]);
if (!clinicUuid) {
return (
<div style={{ padding: 40, textAlign: 'center' }}>
<p style={{ color: 'var(--text-3)', fontSize: 14 }}>
{dbUuid ? 'کلینیکی برای این حساب کاربری یافت نشد' : 'در حال بارگذاری اطلاعات کلینیک...'}
</p>
</div>
);
}
return (
<div className="fade-in" style={{ display: 'flex', flexDirection: 'column', gap: 'var(--gap)' }}>
<div className="card-title-row">
<div>
<h1 className="section-title">پزشکان کلینیک</h1>
<div className="muted">مدیریت پزشکان و دعوت‌نامه‌های کلینیک</div>
</div>
<Link className="btn ghost sm" to={`/admin/clinics/${clinicUuid}`}>
<PencilIcon style={{ width: 15, height: 15 }} /> ویرایش اطلاعات کلینیک
</Link>
</div>
<ClinicDoctorsManager
clinicUuid={clinicUuid}
canCreate={canCreate}
canUpdate={canUpdate}
canDelete={canDelete}
/>
</div>
);
}
export default function ClinicDoctorsPage() {
return (
<SettingsLayout active="clinic-doctors">
<ClinicDoctorsContent />
</SettingsLayout>
);
}