feat(subscription): gate insurance pages behind "insurance" plan feature

Wrap InsurancePricingPage and ClaimsPage in <FeatureGate feature="insurance">
so direct-URL access is blocked without an active subscription that enables
the feature. Add feature: "insurance" to the sidebar links (doctor/clinic/
secretary sections) so the menu items hide when the plan lacks it.

Make AdminSubscriptionPage feature controls dynamic: derive the plan feature
checkboxes from FEATURE_LABELS (now including "insurance") and switch the Zod
schema to z.record, so adding a feature only touches the label map.

No backend/migration change: plan.features is free-form JSON; existing plans
default to insurance:false and admins enable it per plan.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-24 03:21:52 +03:30
co-authored by Claude Opus 4.8
parent fc87e4a04e
commit 15e7d92fc1
5 changed files with 181 additions and 16 deletions
@@ -197,11 +197,13 @@ function buildSections(
to: "/admin/insurance-pricing",
icon: ShieldCheckIcon,
label: "قیمت‌گذاری بیمه",
feature: "insurance",
},
{
to: "/admin/claims",
icon: DocumentTextIcon,
label: "مطالبات بیمه",
feature: "insurance",
},
{ to: "/admin/staff", icon: UserPlusIcon, label: "پرسنل" },
{
@@ -276,11 +278,13 @@ function buildSections(
to: "/admin/insurance-pricing",
icon: ShieldCheckIcon,
label: "قیمت‌گذاری بیمه",
feature: "insurance",
},
{
to: "/admin/claims",
icon: DocumentTextIcon,
label: "مطالبات بیمه",
feature: "insurance",
},
{ to: "/admin/staff", icon: UserPlusIcon, label: "پرسنل" },
{
@@ -345,11 +349,13 @@ function buildSections(
to: "/admin/insurance-pricing",
icon: ShieldCheckIcon,
label: "قیمت‌گذاری بیمه",
feature: "insurance",
},
{
to: "/admin/claims",
icon: DocumentTextIcon,
label: "مطالبات بیمه",
feature: "insurance",
},
],
},
+10 -8
View File
@@ -34,11 +34,7 @@ const planSchema = z.object({
name: z.string().min(1, 'نام الزامی است'),
level: z.coerce.number().min(0),
max_secretaries: z.coerce.number().min(1),
features: z.object({
patient_records: z.boolean(),
services: z.boolean(),
sms_panel: z.boolean(),
}),
features: z.record(z.string(), z.boolean()),
active: z.boolean(),
});
type PlanForm = z.infer<typeof planSchema>;
@@ -60,8 +56,14 @@ const FEATURE_LABELS: Record<string, string> = {
patient_records: 'پرونده بیمار',
services: 'سرویس‌ها',
sms_panel: 'پنل پیامک',
insurance: 'بیمه و مطالبات',
};
const FEATURE_KEYS = Object.keys(FEATURE_LABELS);
const emptyFeatures = (): Record<string, boolean> =>
Object.fromEntries(FEATURE_KEYS.map((k) => [k, false]));
const PLAN_DISPLAY: Record<string, string> = {
free: 'رایگان',
basic: 'پایه',
@@ -86,7 +88,7 @@ function PlansTab() {
const planForm = useForm<PlanForm>({
resolver: zodResolver(planSchema),
defaultValues: { features: { patient_records: false, services: false, sms_panel: false }, active: true },
defaultValues: { features: emptyFeatures(), active: true },
});
const periodForm = useForm<PeriodForm>({
@@ -129,7 +131,7 @@ function PlansTab() {
name: plan.name,
level: plan.level,
max_secretaries: plan.max_secretaries,
features: { patient_records: plan.features.patient_records ?? false, services: plan.features.services ?? false, sms_panel: plan.features.sms_panel ?? false },
features: { ...emptyFeatures(), ...plan.features },
active: (plan as any).active ?? true,
});
setPlanModal(plan);
@@ -157,7 +159,7 @@ function PlansTab() {
return (
<>
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: 16 }}>
<button className="btn primary sm" onClick={() => { planForm.reset({ features: { patient_records: false, services: false, sms_panel: false }, active: true, level: 0, max_secretaries: 1 }); setPlanModal('create'); }}>
<button className="btn primary sm" onClick={() => { planForm.reset({ features: emptyFeatures(), active: true, level: 0, max_secretaries: 1 }); setPlanModal('create'); }}>
<PlusIcon style={{ width: 16 }} /> پنل جدید
</button>
</div>
+3
View File
@@ -7,6 +7,7 @@ import { formatRial, formatNumber } from '../lib/utils';
import PageHeader from '../components/ui/PageHeader';
import Modal from '../components/ui/Modal';
import SearchableSelect from '../components/ui/SearchableSelect';
import FeatureGate from '../components/ui/FeatureGate';
interface ClaimItem {
invoice_item_id: number;
@@ -80,6 +81,7 @@ export default function ClaimsPage() {
});
return (
<FeatureGate feature="insurance">
<div className="fade-in">
<PageHeader title="مطالبات بیمه" description="پیگیری مطالبات و بدهی بیمه‌ها" />
@@ -189,5 +191,6 @@ export default function ClaimsPage() {
</div>
</Modal>
</div>
</FeatureGate>
);
}
+11 -8
View File
@@ -1,16 +1,19 @@
import PageHeader from '../components/ui/PageHeader';
import TenantInsuranceContracts from '../components/TenantInsuranceContracts';
import FreeVisitPrice from '../components/FreeVisitPrice';
import FeatureGate from '../components/ui/FeatureGate';
export default function InsurancePricingPage() {
return (
<div className="fade-in">
<PageHeader
title="بیمه و قیمت‌گذاری"
description="قیمت ویزیت آزاد و قراردادهای بیمه (پایه و تکمیلی)"
/>
<FreeVisitPrice />
<TenantInsuranceContracts />
</div>
<FeatureGate feature="insurance">
<div className="fade-in">
<PageHeader
title="بیمه و قیمت‌گذاری"
description="قیمت ویزیت آزاد و قراردادهای بیمه (پایه و تکمیلی)"
/>
<FreeVisitPrice />
<TenantInsuranceContracts />
</div>
</FeatureGate>
);
}