import React, { useState, useEffect } from 'react'; import { Card, Text, Group, Stack, Badge, Button, Collapse, Alert, TextInput, Paper, Loader, Divider } from '@mantine/core'; import { useTranslation } from 'react-i18next'; import LocalIcon from '@app/components/shared/LocalIcon'; import RestartConfirmationModal from '@app/components/shared/config/RestartConfirmationModal'; import { useRestartServer } from '@app/components/shared/config/useRestartServer'; import { useAdminSettings } from '@app/hooks/useAdminSettings'; import PendingBadge from '@app/components/shared/config/PendingBadge'; import { alert } from '@app/components/toast'; import { LicenseInfo, mapLicenseToTier } from '@app/services/licenseService'; import { PLAN_FEATURES, PLAN_HIGHLIGHTS } from '@app/constants/planConstants'; import FeatureComparisonTable from '@app/components/shared/config/configSections/plan/FeatureComparisonTable'; interface PremiumSettingsData { key?: string; enabled?: boolean; } interface StaticPlanSectionProps { currentLicenseInfo?: LicenseInfo; } const StaticPlanSection: React.FC = ({ currentLicenseInfo }) => { const { t } = useTranslation(); const [showLicenseKey, setShowLicenseKey] = useState(false); const [showComparison, setShowComparison] = useState(false); // Premium/License key management const { restartModalOpened, showRestartModal, closeRestartModal, restartServer } = useRestartServer(); const { settings: premiumSettings, setSettings: setPremiumSettings, loading: premiumLoading, saving: premiumSaving, fetchSettings: fetchPremiumSettings, saveSettings: savePremiumSettings, isFieldPending, } = useAdminSettings({ sectionName: 'premium', }); useEffect(() => { fetchPremiumSettings(); }, []); const handleSaveLicense = async () => { try { await savePremiumSettings(); showRestartModal(); } catch (_error) { alert({ alertType: 'error', title: t('admin.error', 'Error'), body: t('admin.settings.saveError', 'Failed to save settings'), }); } }; const staticPlans = [ { id: 'free', name: t('plan.free.name', 'Free'), price: 0, currency: '£', period: '', highlights: PLAN_HIGHLIGHTS.FREE, features: PLAN_FEATURES.FREE, maxUsers: 5, }, { id: 'server', name: 'Server', price: 0, currency: '', period: '', popular: false, highlights: PLAN_HIGHLIGHTS.SERVER_MONTHLY, features: PLAN_FEATURES.SERVER, maxUsers: 'Unlimited users', }, { id: 'enterprise', name: t('plan.enterprise.name', 'Enterprise'), price: 0, currency: '', period: '', highlights: PLAN_HIGHLIGHTS.ENTERPRISE_MONTHLY, features: PLAN_FEATURES.ENTERPRISE, maxUsers: 'Custom', }, ]; const getCurrentPlan = () => { const tier = mapLicenseToTier(currentLicenseInfo || null); if (tier === 'enterprise') return staticPlans[2]; if (tier === 'server') return staticPlans[1]; return staticPlans[0]; // free }; const currentPlan = getCurrentPlan(); return (
{/* Available Plans */}

{t('plan.availablePlans.title', 'Available Plans')}

{t('plan.static.contactToUpgrade', 'Contact us to upgrade or customize your plan')}

{staticPlans.map((plan) => ( {plan.id === currentPlan.id && ( {t('plan.current', 'Current Plan')} )} {plan.popular && plan.id !== currentPlan.id && ( {t('plan.popular', 'Popular')} )}
{plan.name} {plan.price === 0 && plan.id !== 'free' ? t('plan.customPricing', 'Custom') : plan.price === 0 ? t('plan.free.name', 'Free') : `${plan.currency}${plan.price}`} {plan.period && ( {plan.period} )} {typeof plan.maxUsers === 'string' ? plan.maxUsers : `${t('plan.static.upTo', 'Up to')} ${plan.maxUsers} ${t('workspace.people.license.users', 'users')}`}
{plan.highlights.map((highlight, index) => ( • {highlight} ))}
))}
{/* Feature Comparison Toggle */}
{/* Feature Comparison Table */}
{/* License Key Section */}
} > {t('admin.settings.premium.licenseKey.info', 'If you have a license key or certificate file from a direct purchase, you can enter it here to activate premium or enterprise features.')} {premiumLoading ? ( ) : (
{t('admin.settings.premium.key.label', 'License Key')} } description={t('admin.settings.premium.key.description', 'Enter your premium or enterprise license key. Premium features will be automatically enabled when a key is provided.')} value={premiumSettings.key || ''} onChange={(e) => setPremiumSettings({ ...premiumSettings, key: e.target.value })} placeholder="00000000-0000-0000-0000-000000000000" />
)}
{/* Restart Confirmation Modal */}
); }; export default StaticPlanSection;