import React, { useState } from 'react'; import { useNavigate, useOutletContext } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Check, Loader2, CreditCard, Shield, Zap, Users, ArrowLeft } from 'lucide-react'; import { User, Business } from '../types'; type BillingPeriod = 'monthly' | 'annual'; type PlanTier = 'Professional' | 'Business' | 'Enterprise'; interface PlanFeature { text: string; included: boolean; } interface PlanDetails { name: string; description: string; monthlyPrice: number; annualPrice: number; features: PlanFeature[]; popular?: boolean; } /** * Upgrade Page * Allows businesses to upgrade from trial/free to a paid plan */ const Upgrade: React.FC = () => { const { t } = useTranslation(); const navigate = useNavigate(); const { user, business } = useOutletContext<{ user: User; business: Business }>(); const [billingPeriod, setBillingPeriod] = useState('monthly'); const [selectedPlan, setSelectedPlan] = useState('Professional'); const [isProcessing, setIsProcessing] = useState(false); const [error, setError] = useState(null); // Plan configurations const plans: Record = { Professional: { name: t('marketing.pricing.tiers.professional.name'), description: t('marketing.pricing.tiers.professional.description'), monthlyPrice: 29, annualPrice: 290, features: [ { text: t('upgrade.features.resources', { count: 10 }), included: true }, { text: t('upgrade.features.customDomain'), included: true }, { text: t('upgrade.features.stripeConnect'), included: true }, { text: t('upgrade.features.whitelabel'), included: true }, { text: t('upgrade.features.emailReminders'), included: true }, { text: t('upgrade.features.prioritySupport'), included: true }, { text: t('upgrade.features.apiAccess'), included: false }, ], }, Business: { name: t('marketing.pricing.tiers.business.name'), description: t('marketing.pricing.tiers.business.description'), monthlyPrice: 79, annualPrice: 790, popular: true, features: [ { text: t('upgrade.features.unlimitedResources'), included: true }, { text: t('upgrade.features.customDomain'), included: true }, { text: t('upgrade.features.stripeConnect'), included: true }, { text: t('upgrade.features.whitelabel'), included: true }, { text: t('upgrade.features.teamManagement'), included: true }, { text: t('upgrade.features.advancedAnalytics'), included: true }, { text: t('upgrade.features.apiAccess'), included: true }, { text: t('upgrade.features.phoneSupport'), included: true }, ], }, Enterprise: { name: t('marketing.pricing.tiers.enterprise.name'), description: t('marketing.pricing.tiers.enterprise.description'), monthlyPrice: 0, annualPrice: 0, features: [ { text: t('upgrade.features.everything'), included: true }, { text: t('upgrade.features.customIntegrations'), included: true }, { text: t('upgrade.features.dedicatedManager'), included: true }, { text: t('upgrade.features.sla'), included: true }, { text: t('upgrade.features.customContracts'), included: true }, { text: t('upgrade.features.onPremise'), included: true }, ], }, }; const currentPlan = plans[selectedPlan]; const price = billingPeriod === 'monthly' ? currentPlan.monthlyPrice : currentPlan.annualPrice; const isEnterprise = selectedPlan === 'Enterprise'; const handleUpgrade = async () => { if (isEnterprise) { // For Enterprise, redirect to contact page window.location.href = 'mailto:sales@smoothschedule.com?subject=Enterprise Plan Inquiry'; return; } setIsProcessing(true); setError(null); try { // TODO: Integrate with Stripe Checkout or dj-stripe subscription creation // This is a placeholder for the actual Stripe integration // Example flow: // 1. Call backend API to create Stripe Checkout session // 2. Redirect to Stripe Checkout // 3. Handle success/cancel callbacks await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate API call // For now, just show a message alert(`Upgrading to ${selectedPlan} (${billingPeriod})\nThis would redirect to Stripe Checkout.`); // After successful payment, redirect to dashboard navigate('/'); } catch (err) { setError(t('upgrade.errors.processingFailed')); console.error('Upgrade error:', err); } finally { setIsProcessing(false); } }; const calculateSavings = () => { if (billingPeriod === 'annual') { const monthlyCost = currentPlan.monthlyPrice * 12; const annualCost = currentPlan.annualPrice; return monthlyCost - annualCost; } return 0; }; return (
{/* Back Button */} {/* Header */}

{t('upgrade.title')}

{t('upgrade.subtitle', { businessName: business.name })}

{/* Billing Period Toggle */}
{/* Plan Cards */}
{(Object.entries(plans) as [PlanTier, PlanDetails][]).map(([tier, plan]) => { const isSelected = selectedPlan === tier; const tierPrice = billingPeriod === 'monthly' ? plan.monthlyPrice : plan.annualPrice; const isEnterprisePlan = tier === 'Enterprise'; return (
setSelectedPlan(tier)} className={`relative bg-white dark:bg-gray-800 rounded-2xl shadow-lg border-2 transition-all cursor-pointer ${ isSelected ? 'border-brand-600 shadow-brand-500/20 scale-105' : 'border-gray-200 dark:border-gray-700 hover:border-brand-300' } ${plan.popular ? 'ring-2 ring-brand-500' : ''}`} > {plan.popular && (
{t('upgrade.mostPopular')}
)}

{plan.name}

{plan.description}

{isEnterprisePlan ? (
{t('upgrade.custom')}
) : ( <>
${tierPrice} /{billingPeriod === 'monthly' ? t('upgrade.month') : t('upgrade.year')}
{billingPeriod === 'annual' && (
{t('upgrade.billing.saveAmount', { amount: (plan.monthlyPrice * 12 - plan.annualPrice) })}
)} )}
    {plan.features.map((feature, idx) => (
  • {feature.text}
  • ))}
{isSelected ? t('upgrade.selected') : t('upgrade.selectPlan')}
); })}
{/* Summary & Checkout */}

{t('upgrade.orderSummary')}

{currentPlan.name} {t('upgrade.plan')}
{billingPeriod === 'monthly' ? t('upgrade.billedMonthly') : t('upgrade.billedAnnually')}
{!isEnterprise && (
${price}
)}
{billingPeriod === 'annual' && !isEnterprise && calculateSavings() > 0 && (
{t('upgrade.annualSavings')}
-${calculateSavings()}
)}
{/* Trust Indicators */}
{t('upgrade.trust.secure')}
{t('upgrade.trust.instant')}
{t('upgrade.trust.support')}
{/* Error Message */} {error && (

{error}

)} {/* Upgrade Button */}

{t('upgrade.secureCheckout')}

{/* FAQ or Additional Info */}

{t('upgrade.questions')}{' '} {t('upgrade.contactUs')}

); }; export default Upgrade;