44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
"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}</>;
|
||
}
|