import React, { useState } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Check, X, Crown, Zap, CheckCircle2, AlertCircle } from 'lucide-react'; import toast from 'react-hot-toast'; import { useTranslation } from 'react-i18next'; import { getLicenseInfo, activateLicense, deactivateLicense } from '../../services/api'; import ProBadge from '../ui/ProBadge'; import type { LicenseInfo } from '../../types/license'; export default function LicenseManager() { const { t } = useTranslation(); const [licenseKey, setLicenseKey] = useState(''); const queryClient = useQueryClient(); // Fetch license info const { data: licenseData, isLoading } = useQuery({ queryKey: ['license', 'info'], queryFn: async () => { const response = await getLicenseInfo(); return response.data; // Extract data from API response }, }); const license = licenseData; // licenseData is already the license object // Debug logging React.useEffect(() => { console.log('[LicenseManager] licenseData:', licenseData); console.log('[LicenseManager] license:', license); console.log('[LicenseManager] license?.is_active:', license?.is_active); }, [licenseData, license]); // Activate mutation const activateMutation = useMutation({ mutationFn: (key: string) => activateLicense(key), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['license'] }); toast.success(t('license.activation_success')); setLicenseKey(''); }, onError: (error: any) => { console.error('[License] Activation error:', error); // 🔒 SECURITY: Handle rate limiting and other errors if (error.response?.status === 429) { toast.error( error.response?.data?.message || t('license.rate_limit_error', { defaultValue: 'Too many activation attempts. Please try again in 15 minutes.' }) ); } else { toast.error(error.response?.data?.message || t('license.activation_error')); } }, }); // Deactivate mutation const deactivateMutation = useMutation({ mutationFn: () => deactivateLicense(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['license'] }); toast.success(t('license.deactivation_success')); }, }); if (isLoading) { return (
); } return (
{/* LICENSE ACTIVATION SECTION */}

{t('license.activation_title')}

{t('license.activation_subtitle')}

setLicenseKey(e.target.value)} placeholder="VH-PRO-YYYY-XXXX-XXXX-XXXX" disabled={activateMutation.isPending} className="flex-1 px-4 py-2.5 border border-blue-300 rounded-lg bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:opacity-50" />
{/* ACTIVE LICENSE STATUS (if license active) */} {license?.is_active && (

{t('license.active_license')}

{t('license.tier')}:{' '} {license.tier_label}

{t('license.license_key')}:{' '} {license.license_key}

{t('license.expires')}:{' '} {license.expires}

)} {/* UPGRADE TO PRO CARD - Only show if license is NOT active */} {!license?.is_active && (
{/* Header */}

{t('license.upgrade_card_title')}

{t('license.upgrade_card_description')}

{/* Pricing */}
{t('license.current_tier_free')}
$0
{t('license.tier_pro')}
$29 / {t('license.per_year')}

{t('license.price_details')}

{/* FIRST CTA BUTTON - after pricing */} {t('license.upgrade_card_title')} {/* 2-COLUMN FEATURE COMPARISON TABLE */}

{t('license.features_comparison')}

{/* Header Row */}
{t('license.free_tier')}
{t('license.pro_tier')}
{/* Excel-like Table */}
{t('features.excel_like')}
{/* CSV Export */}
{t('features.csv_export')}
200 {t('features.rows')}
{t('features.unlimited')}
{/* Bulk Operations */}
{t('features.bulk_operations')}
10 {t('features.variations')}
{t('features.unlimited')}
{/* XLSX Format */}
{t('features.xlsx_format')}
{/* SKU Generator */}
{t('features.sku_generator')}
{/* Attribute Manager */}
{t('features.attribute_manager')}
{/* Performance Tools */}
{t('features.performance_tools')}
{/* MARKETING DESCRIPTIONS - Expanded Features */}
{/* Excel-like Table View */}

{t('features.excel_like')}

{t('features.excel_like_desc')}

{/* Unlimited CSV Export/Import */}

{t('features.csv_unlimited')}

{t('features.csv_unlimited_desc')}

{/* Bulk Operations */}

{t('features.bulk_operations')}

{t('features.bulk_operations_desc')}

{/* XLSX Format */}

{t('features.xlsx_format')}

{t('features.xlsx_format_desc')}

{/* SKU Generator */}

{t('features.sku_generator')}

{t('features.sku_generator_desc')}

{/* Attribute Manager */}

{t('features.attribute_manager')}

{t('features.attribute_manager_desc')}

{/* Performance Optimization */}

{t('features.performance_tools')}

{t('features.performance_tools_desc')}

{/* SECOND CTA BUTTON */} {t('license.purchase_button')} {/* Money-back Guarantee */}

✓ {t('license.money_back_guarantee')}

)}
); }