import React from 'react'; import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography, Box, Alert, Paper } from '@mui/material'; import { CreditCard, Warning, ArrowForward } from '@mui/icons-material'; interface SubscriptionExpiredModalProps { open: boolean; onClose: () => void; onRenewSubscription: () => void; subscriptionData?: { plan?: string; tier?: string; limits?: any; } | null; errorData?: { provider?: string; usage_info?: any; message?: string; } | null; } const SubscriptionExpiredModal: React.FC = ({ open, onClose, onRenewSubscription, subscriptionData, errorData }) => { // Debug logging to verify modal state React.useEffect(() => { console.log('SubscriptionExpiredModal: State update', { open, errorData, hasUsageInfo: !!errorData?.usage_info, errorDataKeys: errorData ? Object.keys(errorData) : null }); if (open) { console.log('SubscriptionExpiredModal: Modal should be visible now', { open, errorData, hasUsageInfo: !!errorData?.usage_info }); } else { console.log('SubscriptionExpiredModal: Modal is closed'); } }, [open, errorData]); const handleDialogClose = (_event: object, reason?: string) => { if (reason === 'backdropClick') { console.log('SubscriptionExpiredModal: Ignoring backdrop click close'); return; } onClose(); }; const handleRenewClick = () => { onRenewSubscription(); onClose(); }; return ( {errorData?.usage_info ? 'Usage Limit Reached' : 'Subscription Expired'} } > {errorData?.usage_info ? 'You\'ve reached your API usage limit' : 'Your subscription has expired'} {/* Main error message */} {errorData?.message || (errorData?.usage_info ? 'You\'ve reached your monthly usage limit for this plan. Upgrade your plan to get higher limits.' : 'To continue using Alwrity and access all features, you need to renew your subscription.' )} {/* Detailed usage information */} {errorData?.usage_info && ( Usage Information: {/* Provider and operation type */} {errorData.provider && ( Provider: {errorData.provider} )} {errorData.usage_info.operation_type && ( Operation: {errorData.usage_info.operation_type.replace(/_/g, ' ')} )} {/* Token usage details (if available) */} {(errorData.usage_info.current_tokens !== undefined || errorData.usage_info.current_calls !== undefined) && ( {errorData.usage_info.current_tokens !== undefined && ( <> Token Usage: {errorData.usage_info.current_tokens?.toLocaleString() || 0} / {errorData.usage_info.limit?.toLocaleString() || 0} ({((errorData.usage_info.current_tokens / errorData.usage_info.limit) * 100).toFixed(1)}% used) {errorData.usage_info.requested_tokens && ( Requested: {errorData.usage_info.requested_tokens.toLocaleString()} tokens {errorData.usage_info.current_tokens + errorData.usage_info.requested_tokens > errorData.usage_info.limit && ( (Would exceed by: {((errorData.usage_info.current_tokens + errorData.usage_info.requested_tokens) - errorData.usage_info.limit).toLocaleString()} tokens) )} )} )} {errorData.usage_info.current_calls !== undefined && ( <> API Call Usage: {errorData.usage_info.current_calls?.toLocaleString() || 0} / {(errorData.usage_info.limit || errorData.usage_info.call_limit || 0)?.toLocaleString()} {(() => { const limit = errorData.usage_info.limit || errorData.usage_info.call_limit || 0; const current = errorData.usage_info.current_calls || 0; const percentage = limit > 0 ? ((current / limit) * 100).toFixed(1) : '0.0'; return `(${percentage}% used)`; })()} )} )} {/* Error type badge */} {errorData.usage_info.error_type && ( {errorData.usage_info.error_type.replace(/_/g, ' ')} )} )} {/* Current plan information */} {subscriptionData && ( {subscriptionData.plan && ( Current Plan: {subscriptionData.plan} )} )} Renewing your subscription will restore access to: ✓ AI Content Generation ✓ Website Analysis ✓ Research Tools ✓ All Premium Features ); }; export default SubscriptionExpiredModal;