mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import { useSubscription } from '@/contexts/SubscriptionContext';
|
|
import { SubscriptionFeatureFlag } from '@/types/subscription';
|
|
import { Paywall } from './Paywall';
|
|
|
|
export interface FeatureGateProps {
|
|
children: React.ReactNode;
|
|
feature: SubscriptionFeatureFlag | SubscriptionFeatureFlag[];
|
|
fallback?: React.ReactNode;
|
|
showPaywall?: boolean;
|
|
paywallTitle?: string;
|
|
paywallDescription?: string;
|
|
requiredPlan?: 'basic' | 'professional' | 'enterprise';
|
|
}
|
|
|
|
/**
|
|
* Component that conditionally renders children based on subscription features
|
|
*/
|
|
export const FeatureGate = ({
|
|
children,
|
|
feature,
|
|
fallback = null,
|
|
showPaywall = false,
|
|
paywallTitle,
|
|
paywallDescription,
|
|
requiredPlan,
|
|
}: FeatureGateProps) => {
|
|
const { canAccessFeature } = useSubscription();
|
|
const features = Array.isArray(feature) ? feature : [feature];
|
|
const hasAccess = features.every((f) => canAccessFeature(f));
|
|
|
|
if (!hasAccess) {
|
|
if (showPaywall) {
|
|
return (
|
|
<Paywall
|
|
feature={feature}
|
|
title={paywallTitle}
|
|
description={paywallDescription}
|
|
requiredPlan={requiredPlan}
|
|
/>
|
|
);
|
|
}
|
|
return <>{fallback}</>;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
};
|