TorbatYar/frontend/modules/workspace/components/WorkspaceEntitlementGate.tsx
Mortezakoohjani a483b47369 feat(workspace): complete production workspace and content operations
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-12 11:54:17 +03:30

44 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { FeatureLock } from "@/modules/commercial/components";
import { useWorkspaceEntitlement } from "@/modules/workspace/hooks/useWorkspaceEntitlement";
import { WorkspacePageLoader } from "@/modules/workspace/pages/shared";
import { useTenantId } from "@/hooks/useTenantId";
export function WorkspaceEntitlementGate({ children }: { children: React.ReactNode }) {
const { tenantId } = useTenantId();
const entitlement = useWorkspaceEntitlement();
if (!tenantId) return <>{children}</>;
if (entitlement.isLoading) return <WorkspacePageLoader label="در حال بررسی دسترسی تجاری…" />;
const data = entitlement.data;
if (data?.unavailable) {
return (
<div className="space-y-4">
<div className="rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-200">
بررسی اشتراک تجاری فعلاً در دسترس نیست. می‌توانید از فضای کاری استفاده کنید؛ محدودیت طرح اعمال نشده است.
</div>
{children}
</div>
);
}
if (data && !data.has_access) {
return (
<FeatureLock
featureKey="workspace.module.enabled"
tenantId={tenantId}
requiredCapability="workspace.module.enabled"
reason={data.reason}
requiredPlan={data.required_plan}
requiredBundle={data.required_bundle}
>
{children}
</FeatureLock>
);
}
return <>{children}</>;
}