mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Some checks failed
CI/CD Pipeline / backend-lint (push) Failing after 31s
CI/CD Pipeline / backend-build (push) Has been skipped
CI/CD Pipeline / frontend-lint (push) Failing after 1m37s
CI/CD Pipeline / frontend-build (push) Has been skipped
CI/CD Pipeline / e2e-test (push) Has been skipped
- Replace all 'any' types with proper TypeScript interfaces - Fix React hooks setState in useEffect issues with lazy initialization - Remove unused variables and imports across all files - Fix React Compiler memoization dependency issues - Add comprehensive i18n translation keys for admin interfaces - Apply consistent prettier formatting throughout codebase - Clean up unused bulk editing functionality - Improve type safety and code quality across frontend Files changed: 39 - ImpactMetrics.tsx: Fixed any types and interfaces - AdminVerificationQueuePage.tsx: Added i18n keys, removed unused vars - LocalizationUIPage.tsx: Fixed memoization, added translations - LocalizationDataPage.tsx: Added type safety and translations - And 35+ other files with various lint fixes
171 lines
5.8 KiB
TypeScript
171 lines
5.8 KiB
TypeScript
import React from 'react';
|
|
import { clsx } from 'clsx';
|
|
import { Lock, Check } from 'lucide-react';
|
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/Card';
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogDescription,
|
|
} from '@/components/ui';
|
|
import { useSubscription } from '@/contexts/SubscriptionContext';
|
|
import { SubscriptionFeatureFlag, SUBSCRIPTION_PLANS, formatPrice } from '@/types/subscription';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { useTranslation } from '@/hooks/useI18n';
|
|
|
|
export interface PaywallProps {
|
|
feature: SubscriptionFeatureFlag | SubscriptionFeatureFlag[];
|
|
title?: string;
|
|
description?: string;
|
|
children?: React.ReactNode;
|
|
showUpgradeButton?: boolean;
|
|
requiredPlan?: 'basic' | 'professional' | 'enterprise';
|
|
className?: string;
|
|
}
|
|
|
|
/**
|
|
* Paywall component that blocks access to premium features
|
|
*/
|
|
export const Paywall = ({
|
|
feature,
|
|
title,
|
|
description,
|
|
children,
|
|
showUpgradeButton = true,
|
|
requiredPlan,
|
|
className,
|
|
}: PaywallProps) => {
|
|
const { canAccessFeature, subscription } = useSubscription();
|
|
const navigate = useNavigate();
|
|
const { t } = useTranslation();
|
|
const [showUpgradeDialog, setShowUpgradeDialog] = React.useState(false);
|
|
|
|
const features = Array.isArray(feature) ? feature : [feature];
|
|
const hasAccess = features.every((f) => canAccessFeature(f));
|
|
|
|
if (hasAccess) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
const featureName = features.length === 1 ? features[0].replace(/_/g, ' ') : 'premium features';
|
|
const displayTitle = title || `Upgrade to Access ${featureName}`;
|
|
const displayDescription =
|
|
description ||
|
|
`This feature is available in our premium plans. Upgrade your subscription to unlock ${featureName}.`;
|
|
|
|
// Determine minimum required plan
|
|
const currentPlan = subscription?.plan || 'free';
|
|
const plans = ['free', 'basic', 'professional', 'enterprise'] as const;
|
|
const currentPlanIndex = plans.indexOf(currentPlan);
|
|
const nextPlan =
|
|
requiredPlan ||
|
|
(currentPlanIndex < plans.length - 1 ? plans[currentPlanIndex + 1] : 'professional');
|
|
|
|
const handleUpgrade = () => {
|
|
setShowUpgradeDialog(true);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className={clsx(
|
|
'relative rounded-lg border-2 border-dashed border-muted-foreground/30 bg-muted/20 p-8',
|
|
'flex flex-col items-center justify-center text-center',
|
|
className
|
|
)}
|
|
>
|
|
<div className="mb-4 rounded-full bg-muted p-3">
|
|
<Lock className="h-8 w-8 text-muted-foreground" />
|
|
</div>
|
|
<h3 className="text-lg font-semibold mb-2">{displayTitle}</h3>
|
|
<p className="text-sm text-muted-foreground mb-6 max-w-md">{displayDescription}</p>
|
|
{showUpgradeButton && (
|
|
<Button onClick={handleUpgrade} variant="primary" size="lg">
|
|
{t('paywall.upgradeTo', { planName: SUBSCRIPTION_PLANS[nextPlan].name })}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
|
|
<Dialog open={showUpgradeDialog} onOpenChange={setShowUpgradeDialog}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{t('paywall.upgradeYourPlan')}</DialogTitle>
|
|
<DialogDescription>{t('paywall.choosePlanDescription')}</DialogDescription>
|
|
</DialogHeader>
|
|
<UpgradePlans
|
|
currentPlan={currentPlan}
|
|
onSelectPlan={(plan) => navigate(`/billing?plan=${plan}`)}
|
|
/>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</>
|
|
);
|
|
};
|
|
|
|
interface UpgradePlansProps {
|
|
currentPlan: string;
|
|
onSelectPlan: (plan: string) => void;
|
|
}
|
|
|
|
const UpgradePlans = ({ currentPlan, onSelectPlan }: UpgradePlansProps) => {
|
|
const { t } = useTranslation();
|
|
const plans = ['basic', 'professional', 'enterprise'] as const;
|
|
|
|
return (
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
|
|
{plans.map((plan) => {
|
|
const planDetails = SUBSCRIPTION_PLANS[plan];
|
|
const isCurrentPlan = currentPlan === plan;
|
|
const isUpgrade =
|
|
['free', 'basic', 'professional'].indexOf(currentPlan) < plans.indexOf(plan);
|
|
|
|
return (
|
|
<Card
|
|
key={plan}
|
|
className={clsx('relative', {
|
|
'border-primary border-2': planDetails.popular,
|
|
'opacity-60': isCurrentPlan,
|
|
})}
|
|
>
|
|
{planDetails.popular && (
|
|
<div className="absolute -top-3 left-1/2 -translate-x-1/2">
|
|
<span className="bg-primary text-primary-foreground px-3 py-1 rounded-full text-xs font-medium">
|
|
{t('paywall.mostPopular')}
|
|
</span>
|
|
</div>
|
|
)}
|
|
<CardHeader>
|
|
<CardTitle>{planDetails.name}</CardTitle>
|
|
<CardDescription>{planDetails.description}</CardDescription>
|
|
<div className="mt-4">
|
|
<span className="text-3xl font-bold">{formatPrice(planDetails.price.monthly)}</span>
|
|
<span className="text-muted-foreground">{t('paywall.perMonth')}</span>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<ul className="space-y-2 mb-6">
|
|
{planDetails.features.map((feature) => (
|
|
<li key={feature.id} className="flex items-start gap-2 text-sm">
|
|
<Check className="h-4 w-4 text-success mt-0.5 flex-shrink-0" />
|
|
<span>{feature.name}</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<Button
|
|
variant={planDetails.popular ? 'primary' : 'outline'}
|
|
className="w-full"
|
|
onClick={() => onSelectPlan(plan)}
|
|
disabled={isCurrentPlan}
|
|
>
|
|
{isCurrentPlan ? 'Current Plan' : isUpgrade ? 'Upgrade' : 'Downgrade'}
|
|
</Button>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
};
|