Three pages, all on the existing design system: BranchesPage lists the current environment's booking locations with their working-hours and active-room counts, and two subpages edit the week and the rooms. The list page deliberately does not create or rename a branch — clinic and doctor detail pages already do that, and duplicating it would give one physical place two edit surfaces. Route permission reuses `appointment_settings` rather than inventing a new one. Two real bugs fell out of exercising this end to end: `days` was serialising as a JSON *array*, not an object keyed "0".."6" — keys 0..6 are sequential so json_encode collapses them to a list. The client reads days["0"] either way, so nothing looked broken, but the response shape was unstable: one missing day would flip the same field to an object. The controller now casts to stdClass and WorkingHoursTest::testDaysIsAJsonObjectNotAnArray pins it. Found by curling the endpoint for the docs, not by any test. `<input type="time">` caps at 23:59, so it can neither display nor produce the legal end value 1440. An all-day range would have vanished from the form and been corrupted by the first save. Ranges now carry an explicit end-of-day flag, with a round-trip test proving 1440 survives. docs/api/branch.md documents all eight endpoints with responses captured from real curl runs against ddev, including the 422 and 404 bodies. doctor.md records that active/timezone now appear on all nine existing address endpoints (additive), and tenancy.md gains the two lessons this task taught: an aggregate child whose root is itself declared global inherits no environment and needs a real pair, and TenantFilter is not a substitute for an explicit ownership check because hard isolation only applies to a *chosen* context. Verified: phpunit 1067 tests / 2974 assertions green; slot-mode frozen contract green; phpstan 14 errors before and after, none in touched files; tsc clean; vitest 87 files / 612 tests green. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
85 lines
5.5 KiB
TypeScript
85 lines
5.5 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
CreditCardIcon, UserIcon, CalendarDaysIcon, BuildingOffice2Icon,
|
|
BanknotesIcon, UsersIcon, ShieldCheckIcon,
|
|
TagIcon, ChatBubbleLeftRightIcon, UserCircleIcon, UserPlusIcon, ReceiptPercentIcon, MapPinIcon,
|
|
} from '@heroicons/react/24/outline';
|
|
import PurchaseSubscriptionSidebar from './PurchaseSubscriptionSidebar';
|
|
|
|
// ── Settings menu configuration ─────────────────────────────────────────────
|
|
// Source of truth for the *mobile* settings list (SettingsMenuPage). The desktop
|
|
// shell renders the shared PurchaseSubscriptionSidebar instead, so there is a
|
|
// single settings sidebar across all settings pages (no duplicate menu).
|
|
export type SettingsMenuItem = {
|
|
key: string;
|
|
label: string;
|
|
icon: React.ElementType;
|
|
to?: string;
|
|
/** when set, the item is only shown to these roles (omit = every role) */
|
|
roles?: string[];
|
|
/** [resource, action] — منشی فقط با داشتن این مجوز آیتم را میبیند. */
|
|
perm?: [string, string];
|
|
/** برای منشی همیشه نمایش داده میشود (حساب کاربری). */
|
|
alwaysOpen?: boolean;
|
|
};
|
|
|
|
export const SETTINGS_MENU: SettingsMenuItem[] = [
|
|
{ key: 'subscription', label: 'خرید اشتراک', icon: CreditCardIcon, to: '/admin/subscription', perm: ['subscription', 'view'] },
|
|
{ key: 'doctor', label: 'مدیریت پزشک', icon: UserIcon, to: '/admin/profile', roles: ['doctor'] },
|
|
{ key: 'appointment', label: 'مدیریت نوبت دهی', icon: CalendarDaysIcon, to: '/admin/appointment-settings', roles: ['doctor'], perm: ['appointment_settings', 'view'] },
|
|
{ key: 'appointment', label: 'مدیریت نوبت دهی', icon: CalendarDaysIcon, to: '/admin/settings/appointment-settings', roles: ['clinic'], perm: ['appointment_settings', 'view'] },
|
|
{ key: 'clinic-doctors', label: 'پزشکان کلینیک', icon: BuildingOffice2Icon, to: '/admin/settings/clinic-doctors', roles: ['clinic'], perm: ['clinic_doctors', 'view'] },
|
|
{ key: 'branches', label: 'شعبهها و اتاقها', icon: MapPinIcon, to: '/admin/branches', roles: ['doctor', 'clinic'], perm: ['appointment_settings', 'view'] },
|
|
{ key: 'payment', label: 'مدیریت پرداخت', icon: BanknotesIcon, to: '/admin/my-financial', perm: ['payments', 'view'] },
|
|
{ key: 'secretary', label: 'مدیریت منشی', icon: UsersIcon, to: '/admin/my-secretaries' },
|
|
{ key: 'staff', label: 'پرسنل', icon: UserPlusIcon, to: '/admin/staff', perm: ['staff', 'view'] },
|
|
{ key: 'insurance', label: 'مدیریت بیمه', icon: ShieldCheckIcon, to: '/admin/insurance-pricing', perm: ['insurances', 'view'] },
|
|
{ key: 'discounts', label: 'مدیریت تخفیفها', icon: ReceiptPercentIcon, to: '/admin/discounts', roles: ['doctor', 'clinic'], perm: ['discounts', 'view'] },
|
|
{ key: 'tags', label: 'برچسبها', icon: TagIcon, to: '/admin/tags-settings', perm: ['tags', 'view'] },
|
|
{ key: 'sms', label: 'پیامکها', icon: ChatBubbleLeftRightIcon, to: '/admin/sms-wallet', perm: ['sms', 'view'] },
|
|
{ key: 'account', label: 'حساب کاربری', icon: UserCircleIcon, to: '/admin/account-settings', alwaysOpen: true },
|
|
];
|
|
|
|
/**
|
|
* Menu items visible to the given role. برای منشی بر اساس مجوز فیلتر میشود
|
|
* (آیتمِ بدونِ perm/alwaysOpen پنهان است)؛ سایر نقشها با roles.
|
|
*/
|
|
export function menuForRole(
|
|
role: string | null | undefined,
|
|
can?: (resource: string, action: string) => boolean,
|
|
scope?: string | null,
|
|
): SettingsMenuItem[] {
|
|
// منشی و پزشکِ عضوِ کلینیک (scope=clinic) محدود-به-مجوزند؛ بقیه با فیلترِ نقشی.
|
|
const permissionRestricted = role === 'secretary' || (role === 'doctor' && scope === 'clinic');
|
|
return SETTINGS_MENU.filter((i) => {
|
|
if (permissionRestricted) {
|
|
if (i.alwaysOpen) return true;
|
|
if (!i.perm || !can || !can(i.perm[0], i.perm[1])) return false;
|
|
// واریانتِ نقشی (نوبتدهی/پزشکان کلینیک) را با scope تطبیق بده.
|
|
if (i.roles) return i.roles.includes(scope === 'clinic' ? 'clinic' : 'doctor');
|
|
return true;
|
|
}
|
|
return !i.roles || (role != null && i.roles.includes(role));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* SettingsLayout — presentational shell for the doctor/clinic settings area.
|
|
* Renders the shared settings sidebar (PurchaseSubscriptionSidebar) beside the
|
|
* page content, so every settings page shows the exact same menu as the
|
|
* subscription page. Full-width so the sidebar sits flush against the main nav.
|
|
*
|
|
* @param active key of the currently-open settings section (highlighted)
|
|
* @param children the section content (e.g. subscription plans)
|
|
*/
|
|
export default function SettingsLayout({ active, children }: { active: string; children: React.ReactNode }) {
|
|
return (
|
|
<div className="fade-in settings-shell" dir="rtl" style={{ width: '100%' }}>
|
|
<div className="grid grid-cols-1 lg:grid-cols-[248px_minmax(0,1fr)] gap-5">
|
|
<PurchaseSubscriptionSidebar active={active} />
|
|
<div style={{ minWidth: 0 }}>{children}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|