2025-11-19 21:01:06 +01:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
import { Crown, Users, MapPin, Package, TrendingUp, RefreshCw, AlertCircle, CheckCircle, ArrowRight, Star, ExternalLink, Download, CreditCard, X, Activity, Database, Zap, HardDrive, ShoppingCart, ChefHat, Settings, Sparkles, ChevronDown, ChevronUp } from 'lucide-react';
|
2025-09-24 22:22:01 +02:00
|
|
|
import { Button, Card, Badge, Modal } from '../../../../components/ui';
|
2025-10-29 06:58:05 +01:00
|
|
|
import { DialogModal } from '../../../../components/ui/DialogModal/DialogModal';
|
2025-09-24 22:22:01 +02:00
|
|
|
import { PageHeader } from '../../../../components/layout';
|
|
|
|
|
import { useAuthUser } from '../../../../stores/auth.store';
|
|
|
|
|
import { useCurrentTenant } from '../../../../stores';
|
2025-10-30 21:08:07 +01:00
|
|
|
import { showToast } from '../../../../utils/toast';
|
2025-09-24 22:22:01 +02:00
|
|
|
import { subscriptionService, type UsageSummary, type AvailablePlans } from '../../../../api';
|
2025-10-29 06:58:05 +01:00
|
|
|
import { useSubscriptionEvents } from '../../../../contexts/SubscriptionEventsContext';
|
2025-10-19 19:22:37 +02:00
|
|
|
import { SubscriptionPricingCards } from '../../../../components/subscription/SubscriptionPricingCards';
|
2025-11-19 21:01:06 +01:00
|
|
|
import { PlanComparisonTable, ROICalculator, UsageMetricCard } from '../../../../components/subscription';
|
|
|
|
|
import { useSubscription } from '../../../../hooks/useSubscription';
|
|
|
|
|
import {
|
|
|
|
|
trackSubscriptionPageViewed,
|
|
|
|
|
trackUpgradeCTAClicked,
|
|
|
|
|
trackUsageMetricViewed
|
|
|
|
|
} from '../../../../utils/subscriptionAnalytics';
|
2026-01-03 15:55:24 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-09-24 22:22:01 +02:00
|
|
|
|
|
|
|
|
const SubscriptionPage: React.FC = () => {
|
|
|
|
|
const user = useAuthUser();
|
|
|
|
|
const currentTenant = useCurrentTenant();
|
2025-10-29 06:58:05 +01:00
|
|
|
const { notifySubscriptionChanged } = useSubscriptionEvents();
|
2026-01-03 15:55:24 +01:00
|
|
|
const { t } = useTranslation('subscription');
|
2025-09-24 22:22:01 +02:00
|
|
|
|
|
|
|
|
const [usageSummary, setUsageSummary] = useState<UsageSummary | null>(null);
|
|
|
|
|
const [availablePlans, setAvailablePlans] = useState<AvailablePlans | null>(null);
|
|
|
|
|
const [subscriptionLoading, setSubscriptionLoading] = useState(false);
|
|
|
|
|
const [upgradeDialogOpen, setUpgradeDialogOpen] = useState(false);
|
|
|
|
|
const [selectedPlan, setSelectedPlan] = useState<string>('');
|
|
|
|
|
const [upgrading, setUpgrading] = useState(false);
|
2025-09-25 14:30:47 +02:00
|
|
|
const [cancellationDialogOpen, setCancellationDialogOpen] = useState(false);
|
|
|
|
|
const [cancelling, setCancelling] = useState(false);
|
|
|
|
|
const [invoices, setInvoices] = useState<any[]>([]);
|
|
|
|
|
const [invoicesLoading, setInvoicesLoading] = useState(false);
|
2025-10-31 11:54:19 +01:00
|
|
|
const [invoicesLoaded, setInvoicesLoaded] = useState(false);
|
2025-09-24 22:22:01 +02:00
|
|
|
|
2025-11-19 21:01:06 +01:00
|
|
|
// New state for enhanced features
|
|
|
|
|
const [showComparison, setShowComparison] = useState(false);
|
|
|
|
|
const [showROI, setShowROI] = useState(false);
|
|
|
|
|
|
|
|
|
|
// Use new subscription hook for usage forecast data
|
|
|
|
|
const { subscription: subscriptionData, usage: forecastUsage, forecast } = useSubscription();
|
|
|
|
|
|
2025-09-24 22:22:01 +02:00
|
|
|
// Load subscription data on component mount
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
loadSubscriptionData();
|
2025-10-31 11:54:19 +01:00
|
|
|
loadInvoices();
|
2025-09-24 22:22:01 +02:00
|
|
|
}, []);
|
|
|
|
|
|
2025-11-19 21:01:06 +01:00
|
|
|
// Track page view
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (usageSummary) {
|
|
|
|
|
trackSubscriptionPageViewed(usageSummary.plan);
|
|
|
|
|
}
|
|
|
|
|
}, [usageSummary]);
|
|
|
|
|
|
|
|
|
|
// Track high usage metrics
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (forecast?.metrics) {
|
|
|
|
|
forecast.metrics.forEach(metric => {
|
|
|
|
|
if (metric.usage_percentage >= 80) {
|
|
|
|
|
trackUsageMetricViewed(
|
|
|
|
|
metric.metric,
|
|
|
|
|
metric.current,
|
|
|
|
|
metric.limit,
|
|
|
|
|
metric.usage_percentage,
|
|
|
|
|
metric.days_until_breach
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [forecast]);
|
|
|
|
|
|
2025-09-24 22:22:01 +02:00
|
|
|
const loadSubscriptionData = async () => {
|
|
|
|
|
const tenantId = currentTenant?.id || user?.tenant_id;
|
|
|
|
|
|
|
|
|
|
if (!tenantId) {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('No se encontró información del tenant');
|
2025-09-24 22:22:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setSubscriptionLoading(true);
|
|
|
|
|
const [usage, plans] = await Promise.all([
|
|
|
|
|
subscriptionService.getUsageSummary(tenantId),
|
2025-10-15 16:12:49 +02:00
|
|
|
subscriptionService.fetchAvailablePlans()
|
2025-09-24 22:22:01 +02:00
|
|
|
]);
|
|
|
|
|
|
2025-12-18 13:26:32 +01:00
|
|
|
// CRITICAL: No more mock data - show real errors instead
|
2025-10-12 18:47:33 +02:00
|
|
|
if (!usage || !usage.usage) {
|
2025-12-18 13:26:32 +01:00
|
|
|
throw new Error('No subscription found. Please contact support or create a new subscription.');
|
2025-10-12 18:47:33 +02:00
|
|
|
}
|
2025-12-18 13:26:32 +01:00
|
|
|
|
|
|
|
|
setUsageSummary(usage);
|
2025-09-24 22:22:01 +02:00
|
|
|
setAvailablePlans(plans);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error loading subscription data:', error);
|
2025-12-18 13:26:32 +01:00
|
|
|
showToast.error(
|
|
|
|
|
error instanceof Error && error.message.includes('No subscription')
|
|
|
|
|
? error.message
|
|
|
|
|
: "No se pudo cargar la información de suscripción. Por favor, contacte con soporte."
|
|
|
|
|
);
|
2025-09-24 22:22:01 +02:00
|
|
|
} finally {
|
|
|
|
|
setSubscriptionLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-19 21:01:06 +01:00
|
|
|
const handleUpgradeClick = (planKey: string, source: string = 'pricing_cards') => {
|
|
|
|
|
if (usageSummary) {
|
|
|
|
|
trackUpgradeCTAClicked(usageSummary.plan, planKey, source);
|
|
|
|
|
}
|
2025-09-24 22:22:01 +02:00
|
|
|
setSelectedPlan(planKey);
|
|
|
|
|
setUpgradeDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleUpgradeConfirm = async () => {
|
|
|
|
|
const tenantId = currentTenant?.id || user?.tenant_id;
|
|
|
|
|
|
|
|
|
|
if (!tenantId || !selectedPlan) {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('Información de tenant no disponible');
|
2025-09-24 22:22:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setUpgrading(true);
|
|
|
|
|
|
|
|
|
|
const validation = await subscriptionService.validatePlanUpgrade(
|
|
|
|
|
tenantId,
|
|
|
|
|
selectedPlan
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!validation.can_upgrade) {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error(validation.reason || 'No se puede actualizar el plan');
|
2025-09-24 22:22:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await subscriptionService.upgradePlan(tenantId, selectedPlan);
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.success(result.message);
|
|
|
|
|
|
|
|
|
|
// Invalidate cache to ensure fresh data on next fetch
|
|
|
|
|
subscriptionService.invalidateCache();
|
2025-09-24 22:22:01 +02:00
|
|
|
|
2025-10-29 06:58:05 +01:00
|
|
|
// Broadcast subscription change event to refresh sidebar and other components
|
|
|
|
|
notifySubscriptionChanged();
|
|
|
|
|
|
2025-09-24 22:22:01 +02:00
|
|
|
await loadSubscriptionData();
|
|
|
|
|
setUpgradeDialogOpen(false);
|
|
|
|
|
setSelectedPlan('');
|
|
|
|
|
} else {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('Error al cambiar el plan');
|
2025-09-24 22:22:01 +02:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error upgrading plan:', error);
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('Error al procesar el cambio de plan');
|
2025-09-24 22:22:01 +02:00
|
|
|
} finally {
|
|
|
|
|
setUpgrading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-25 14:30:47 +02:00
|
|
|
const handleCancellationClick = () => {
|
|
|
|
|
setCancellationDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCancelSubscription = async () => {
|
|
|
|
|
const tenantId = currentTenant?.id || user?.tenant_id;
|
|
|
|
|
|
|
|
|
|
if (!tenantId) {
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('Información de tenant no disponible');
|
2025-09-25 14:30:47 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setCancelling(true);
|
|
|
|
|
|
2025-10-16 07:28:04 +02:00
|
|
|
const result = await subscriptionService.cancelSubscription(tenantId, 'User requested cancellation');
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
const daysRemaining = result.days_remaining;
|
|
|
|
|
const effectiveDate = new Date(result.cancellation_effective_date).toLocaleDateString('es-ES', {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
day: 'numeric'
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.success(
|
|
|
|
|
`Suscripción cancelada. Acceso de solo lectura a partir del ${effectiveDate} (${daysRemaining} días restantes)`
|
2025-10-16 07:28:04 +02:00
|
|
|
);
|
|
|
|
|
}
|
2025-09-25 14:30:47 +02:00
|
|
|
|
|
|
|
|
await loadSubscriptionData();
|
|
|
|
|
setCancellationDialogOpen(false);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error cancelling subscription:', error);
|
2025-10-30 21:08:07 +01:00
|
|
|
showToast.error('Error al cancelar la suscripción');
|
2025-09-25 14:30:47 +02:00
|
|
|
} finally {
|
|
|
|
|
setCancelling(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadInvoices = async () => {
|
|
|
|
|
const tenantId = currentTenant?.id || user?.tenant_id;
|
|
|
|
|
|
|
|
|
|
if (!tenantId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setInvoicesLoading(true);
|
2025-10-31 11:54:19 +01:00
|
|
|
const fetchedInvoices = await subscriptionService.getInvoices(tenantId);
|
|
|
|
|
setInvoices(fetchedInvoices);
|
|
|
|
|
setInvoicesLoaded(true);
|
2025-09-25 14:30:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error loading invoices:', error);
|
2025-10-31 11:54:19 +01:00
|
|
|
// Don't show error toast on initial load, just log it
|
|
|
|
|
if (invoicesLoaded) {
|
|
|
|
|
showToast.error('Error al cargar las facturas');
|
|
|
|
|
}
|
2025-09-25 14:30:47 +02:00
|
|
|
} finally {
|
|
|
|
|
setInvoicesLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-31 11:54:19 +01:00
|
|
|
const handleDownloadInvoice = (invoice: any) => {
|
|
|
|
|
if (invoice.invoice_pdf) {
|
|
|
|
|
window.open(invoice.invoice_pdf, '_blank');
|
|
|
|
|
} else if (invoice.hosted_invoice_url) {
|
|
|
|
|
window.open(invoice.hosted_invoice_url, '_blank');
|
|
|
|
|
} else {
|
|
|
|
|
showToast.warning('No hay PDF disponible para esta factura');
|
|
|
|
|
}
|
2025-09-25 14:30:47 +02:00
|
|
|
};
|
|
|
|
|
|
2025-09-24 22:22:01 +02:00
|
|
|
const ProgressBar: React.FC<{ value: number; className?: string }> = ({ value, className = '' }) => {
|
|
|
|
|
const getProgressColor = () => {
|
|
|
|
|
if (value >= 90) return 'bg-red-500';
|
|
|
|
|
if (value >= 80) return 'bg-yellow-500';
|
|
|
|
|
return 'bg-green-500';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={`w-full bg-[var(--bg-tertiary)] border border-[var(--border-secondary)] rounded-full h-3 ${className}`}>
|
|
|
|
|
<div
|
|
|
|
|
className={`${getProgressColor()} h-full rounded-full transition-all duration-500 relative`}
|
|
|
|
|
style={{ width: `${Math.min(100, Math.max(0, value))}%` }}
|
|
|
|
|
>
|
|
|
|
|
<div className="absolute inset-0 bg-gradient-to-r from-transparent to-white/20 rounded-full"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="p-6 space-y-6">
|
|
|
|
|
<PageHeader
|
|
|
|
|
title="Suscripción y Facturación"
|
|
|
|
|
description="Gestiona tu suscripción, uso de recursos y facturación"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{subscriptionLoading ? (
|
|
|
|
|
<div className="flex items-center justify-center min-h-[400px]">
|
|
|
|
|
<div className="flex flex-col items-center gap-4">
|
|
|
|
|
<RefreshCw className="w-8 h-8 animate-spin text-[var(--color-primary)]" />
|
|
|
|
|
<p className="text-[var(--text-secondary)]">Cargando información de suscripción...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : !usageSummary || !availablePlans ? (
|
|
|
|
|
<div className="flex items-center justify-center min-h-[400px]">
|
|
|
|
|
<div className="flex flex-col items-center gap-4">
|
|
|
|
|
<AlertCircle className="w-12 h-12 text-[var(--text-tertiary)]" />
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)] mb-2">No se pudo cargar la información</h3>
|
|
|
|
|
<p className="text-[var(--text-secondary)] mb-4">Hubo un problema al cargar los datos de suscripción</p>
|
|
|
|
|
<Button onClick={loadSubscriptionData} variant="primary">
|
|
|
|
|
<RefreshCw className="w-4 h-4 mr-2" />
|
|
|
|
|
Reintentar
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{/* Current Plan Overview */}
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)] flex items-center">
|
|
|
|
|
<Crown className="w-5 h-5 mr-2 text-yellow-500" />
|
2025-10-31 11:54:19 +01:00
|
|
|
Plan Actual
|
2025-09-24 22:22:01 +02:00
|
|
|
</h3>
|
|
|
|
|
<Badge
|
|
|
|
|
variant={usageSummary.status === 'active' ? 'success' : 'default'}
|
|
|
|
|
className="text-sm font-medium"
|
|
|
|
|
>
|
|
|
|
|
{usageSummary.status === 'active' ? 'Activo' : usageSummary.status}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-10-31 11:54:19 +01:00
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)]">
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="text-sm text-[var(--text-secondary)] mb-1">Plan</span>
|
|
|
|
|
<span className="font-semibold text-[var(--text-primary)] text-lg capitalize">{usageSummary.plan}</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-31 11:54:19 +01:00
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)]">
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="text-sm text-[var(--text-secondary)] mb-1">Precio Mensual</span>
|
|
|
|
|
<span className="font-semibold text-[var(--text-primary)] text-lg">{subscriptionService.formatPrice(usageSummary.monthly_price)}</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-31 11:54:19 +01:00
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)]">
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="text-sm text-[var(--text-secondary)] mb-1">Próxima Facturación</span>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)] text-lg">
|
|
|
|
|
{new Date(usageSummary.next_billing_date).toLocaleDateString('es-ES', { day: '2-digit', month: '2-digit', year: 'numeric' })}
|
2025-09-24 22:22:01 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-31 11:54:19 +01:00
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)]">
|
|
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="text-sm text-[var(--text-secondary)] mb-1">Ciclo de Facturación</span>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)] text-lg capitalize">
|
|
|
|
|
{usageSummary.billing_cycle === 'monthly' ? 'Mensual' : 'Anual'}
|
2025-09-24 22:22:01 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Usage Details */}
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<h3 className="text-lg font-semibold mb-6 text-[var(--text-primary)] flex items-center">
|
|
|
|
|
<TrendingUp className="w-5 h-5 mr-2 text-orange-500" />
|
|
|
|
|
Uso de Recursos
|
|
|
|
|
</h3>
|
2025-10-15 16:12:49 +02:00
|
|
|
|
|
|
|
|
{/* Team & Organization Metrics */}
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
<h4 className="text-sm font-semibold text-[var(--text-secondary)] mb-4 uppercase tracking-wide">Equipo & Organización</h4>
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
|
|
|
{/* Users */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-blue-500/10 rounded-lg border border-blue-500/20">
|
|
|
|
|
<Users className="w-4 h-4 text-blue-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Usuarios</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.users.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.users.unlimited ? '∞' : usageSummary.usage.users.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<ProgressBar value={usageSummary.usage.users.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.users.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.users.unlimited ? 'Ilimitado' : `${(usageSummary.usage.users.limit ?? 0) - usageSummary.usage.users.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Locations */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-green-500/10 rounded-lg border border-green-500/20">
|
|
|
|
|
<MapPin className="w-4 h-4 text-green-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Ubicaciones</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.locations.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.locations.unlimited ? '∞' : usageSummary.usage.locations.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.locations.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.locations.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.locations.unlimited ? 'Ilimitado' : `${(usageSummary.usage.locations.limit ?? 0) - usageSummary.usage.locations.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
</div>
|
2025-09-24 22:22:01 +02:00
|
|
|
|
2025-10-15 16:12:49 +02:00
|
|
|
{/* Product & Inventory Metrics */}
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
<h4 className="text-sm font-semibold text-[var(--text-secondary)] mb-4 uppercase tracking-wide">Productos & Inventario</h4>
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
|
|
|
{/* Products */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-purple-500/10 rounded-lg border border-purple-500/20">
|
|
|
|
|
<Package className="w-4 h-4 text-purple-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Productos</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.products.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.products.unlimited ? '∞' : usageSummary.usage.products.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<ProgressBar value={usageSummary.usage.products.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.products.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.products.unlimited ? 'Ilimitado' : `${(usageSummary.usage.products.limit ?? 0) - usageSummary.usage.products.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Recipes */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-amber-500/10 rounded-lg border border-amber-500/20">
|
|
|
|
|
<ChefHat className="w-4 h-4 text-amber-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Recetas</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.recipes.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.recipes.unlimited ? '∞' : usageSummary.usage.recipes.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.recipes.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.recipes.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.recipes.unlimited ? 'Ilimitado' : `${(usageSummary.usage.recipes.limit ?? 0) - usageSummary.usage.recipes.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Suppliers */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-teal-500/10 rounded-lg border border-teal-500/20">
|
|
|
|
|
<ShoppingCart className="w-4 h-4 text-teal-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Proveedores</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.suppliers.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.suppliers.unlimited ? '∞' : usageSummary.usage.suppliers.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.suppliers.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.suppliers.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.suppliers.unlimited ? 'Ilimitado' : `${(usageSummary.usage.suppliers.limit ?? 0) - usageSummary.usage.suppliers.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
</div>
|
2025-09-24 22:22:01 +02:00
|
|
|
|
2025-10-15 16:12:49 +02:00
|
|
|
{/* ML & Analytics Metrics (Daily) */}
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
<h4 className="text-sm font-semibold text-[var(--text-secondary)] mb-4 uppercase tracking-wide">IA & Analíticas (Uso Diario)</h4>
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
{/* Training Jobs Today */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-indigo-500/10 rounded-lg border border-indigo-500/20">
|
|
|
|
|
<Database className="w-4 h-4 text-indigo-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Entrenamientos IA Hoy</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.training_jobs_today.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.training_jobs_today.unlimited ? '∞' : usageSummary.usage.training_jobs_today.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-15 16:12:49 +02:00
|
|
|
<ProgressBar value={usageSummary.usage.training_jobs_today.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.training_jobs_today.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.training_jobs_today.unlimited ? 'Ilimitado' : `${(usageSummary.usage.training_jobs_today.limit ?? 0) - usageSummary.usage.training_jobs_today.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Forecasts Today */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-pink-500/10 rounded-lg border border-pink-500/20">
|
|
|
|
|
<TrendingUp className="w-4 h-4 text-pink-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Pronósticos Hoy</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.forecasts_today.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.forecasts_today.unlimited ? '∞' : usageSummary.usage.forecasts_today.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.forecasts_today.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.forecasts_today.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.forecasts_today.unlimited ? 'Ilimitado' : `${(usageSummary.usage.forecasts_today.limit ?? 0) - usageSummary.usage.forecasts_today.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* API & Storage Metrics */}
|
|
|
|
|
<div>
|
|
|
|
|
<h4 className="text-sm font-semibold text-[var(--text-secondary)] mb-4 uppercase tracking-wide">API & Almacenamiento</h4>
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
{/* API Calls This Hour */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-orange-500/10 rounded-lg border border-orange-500/20">
|
|
|
|
|
<Zap className="w-4 h-4 text-orange-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Llamadas API (Esta Hora)</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.api_calls_this_hour.current}<span className="text-[var(--text-tertiary)]">/</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.api_calls_this_hour.unlimited ? '∞' : usageSummary.usage.api_calls_this_hour.limit ?? 0}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.api_calls_this_hour.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.api_calls_this_hour.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.api_calls_this_hour.unlimited ? 'Ilimitado' : `${(usageSummary.usage.api_calls_this_hour.limit ?? 0) - usageSummary.usage.api_calls_this_hour.current} restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* File Storage */}
|
|
|
|
|
<div className="space-y-3 p-4 bg-[var(--bg-secondary)] border border-[var(--border-secondary)] rounded-lg">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 bg-cyan-500/10 rounded-lg border border-cyan-500/20">
|
|
|
|
|
<HardDrive className="w-4 h-4 text-cyan-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-medium text-[var(--text-primary)]">Almacenamiento</span>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="text-sm font-bold text-[var(--text-primary)]">
|
|
|
|
|
{usageSummary.usage.file_storage_used_gb.current.toFixed(2)}<span className="text-[var(--text-tertiary)]">/</span>
|
|
|
|
|
<span className="text-[var(--text-tertiary)]">{usageSummary.usage.file_storage_used_gb.unlimited ? '∞' : `${usageSummary.usage.file_storage_used_gb.limit} GB`}</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<ProgressBar value={usageSummary.usage.file_storage_used_gb.usage_percentage} />
|
|
|
|
|
<p className="text-xs text-[var(--text-secondary)] flex items-center justify-between">
|
|
|
|
|
<span>{usageSummary.usage.file_storage_used_gb.usage_percentage}% utilizado</span>
|
2025-10-30 21:08:07 +01:00
|
|
|
<span className="font-medium">{usageSummary.usage.file_storage_used_gb.unlimited ? 'Ilimitado' : `${((usageSummary.usage.file_storage_used_gb.limit ?? 0) - usageSummary.usage.file_storage_used_gb.current).toFixed(2)} GB restantes`}</span>
|
2025-10-15 16:12:49 +02:00
|
|
|
</p>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
|
2025-11-19 21:01:06 +01:00
|
|
|
{/* Enhanced Usage Metrics with Predictive Analytics */}
|
|
|
|
|
{forecastUsage && forecast && (
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)] flex items-center">
|
|
|
|
|
<TrendingUp className="w-5 h-5 mr-2 text-purple-500" />
|
|
|
|
|
Análisis Predictivo de Uso
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)]">
|
|
|
|
|
Predicciones basadas en tendencias de crecimiento
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
|
|
|
{/* Products */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="products"
|
|
|
|
|
label="Productos"
|
|
|
|
|
current={forecastUsage.products.current}
|
|
|
|
|
limit={forecastUsage.products.limit}
|
|
|
|
|
trend={forecastUsage.products.trend}
|
|
|
|
|
predictedBreachDate={forecastUsage.products.predictedBreachDate}
|
|
|
|
|
daysUntilBreach={forecastUsage.products.daysUntilBreach}
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={500}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_products')}
|
|
|
|
|
icon={<Package className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Users */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="users"
|
|
|
|
|
label="Usuarios"
|
|
|
|
|
current={forecastUsage.users.current}
|
|
|
|
|
limit={forecastUsage.users.limit}
|
|
|
|
|
trend={forecastUsage.users.trend}
|
|
|
|
|
predictedBreachDate={forecastUsage.users.predictedBreachDate}
|
|
|
|
|
daysUntilBreach={forecastUsage.users.daysUntilBreach}
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={20}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_users')}
|
|
|
|
|
icon={<Users className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Locations */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="locations"
|
|
|
|
|
label="Ubicaciones"
|
|
|
|
|
current={forecastUsage.locations.current}
|
|
|
|
|
limit={forecastUsage.locations.limit}
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={3}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_locations')}
|
|
|
|
|
icon={<MapPin className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Training Jobs */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="training_jobs"
|
|
|
|
|
label="Entrenamientos IA"
|
|
|
|
|
current={forecastUsage.trainingJobs.current}
|
|
|
|
|
limit={forecastUsage.trainingJobs.limit}
|
|
|
|
|
unit="/día"
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={5}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_training')}
|
|
|
|
|
icon={<Database className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Forecasts */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="forecasts"
|
|
|
|
|
label="Pronósticos"
|
|
|
|
|
current={forecastUsage.forecasts.current}
|
|
|
|
|
limit={forecastUsage.forecasts.limit}
|
|
|
|
|
unit="/día"
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={100}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_forecasts')}
|
|
|
|
|
icon={<TrendingUp className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Storage */}
|
|
|
|
|
<UsageMetricCard
|
|
|
|
|
metric="storage"
|
|
|
|
|
label="Almacenamiento"
|
|
|
|
|
current={forecastUsage.storage.current}
|
|
|
|
|
limit={forecastUsage.storage.limit}
|
|
|
|
|
unit=" GB"
|
|
|
|
|
trend={forecastUsage.storage.trend}
|
|
|
|
|
predictedBreachDate={forecastUsage.storage.predictedBreachDate}
|
|
|
|
|
daysUntilBreach={forecastUsage.storage.daysUntilBreach}
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
upgradeTier="professional"
|
|
|
|
|
upgradeLimit={10}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'usage_metric_storage')}
|
|
|
|
|
icon={<HardDrive className="w-5 h-5" />}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* High Usage Warning Banner (Starter tier with >80% usage) */}
|
|
|
|
|
{usageSummary.plan === 'starter' && forecastUsage && forecastUsage.highUsageMetrics.length > 0 && (
|
|
|
|
|
<Card className="p-6 bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-900/20 dark:to-purple-900/20 border-2 border-blue-500">
|
|
|
|
|
<div className="flex items-start gap-4">
|
|
|
|
|
<div className="w-12 h-12 rounded-full bg-gradient-to-br from-blue-600 to-purple-600 flex items-center justify-center flex-shrink-0">
|
|
|
|
|
<Sparkles className="w-6 h-6 text-white" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h3 className="text-lg font-bold mb-2">
|
|
|
|
|
¡Estás superando el plan Starter!
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)] mb-4">
|
|
|
|
|
Estás usando {forecastUsage.highUsageMetrics.length} métrica{forecastUsage.highUsageMetrics.length > 1 ? 's' : ''} con más del 80% de capacidad.
|
|
|
|
|
Actualiza a Professional para obtener 10 veces más capacidad y funciones avanzadas.
|
|
|
|
|
</p>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => handleUpgradeClick('professional', 'high_usage_banner')}
|
|
|
|
|
className="bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white"
|
|
|
|
|
>
|
|
|
|
|
Actualizar a Professional
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={() => setShowROI(true)}
|
|
|
|
|
>
|
|
|
|
|
Ver Tus Ahorros
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* ROI Calculator (Starter tier only) */}
|
|
|
|
|
{usageSummary.plan === 'starter' && (
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<div className="flex items-center justify-between mb-4">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)]">Calcula Tus Ahorros</h3>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setShowROI(!showROI)}
|
|
|
|
|
className="text-sm text-[var(--color-primary)] hover:underline flex items-center gap-1"
|
|
|
|
|
>
|
|
|
|
|
{showROI ? (
|
|
|
|
|
<>
|
|
|
|
|
<ChevronUp className="w-4 h-4" />
|
|
|
|
|
Ocultar Calculadora
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<ChevronDown className="w-4 h-4" />
|
|
|
|
|
Mostrar Calculadora
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{showROI && (
|
|
|
|
|
<ROICalculator
|
|
|
|
|
currentTier="starter"
|
|
|
|
|
targetTier="professional"
|
|
|
|
|
monthlyPrice={149}
|
|
|
|
|
context="settings"
|
|
|
|
|
defaultExpanded={false}
|
|
|
|
|
onUpgrade={() => handleUpgradeClick('professional', 'roi_calculator')}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Plan Comparison */}
|
|
|
|
|
{availablePlans && (
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<div className="flex items-center justify-between mb-4">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)]">Comparar Planes</h3>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setShowComparison(!showComparison)}
|
|
|
|
|
className="text-sm text-[var(--color-primary)] hover:underline flex items-center gap-1"
|
|
|
|
|
>
|
|
|
|
|
{showComparison ? (
|
|
|
|
|
<>
|
|
|
|
|
<ChevronUp className="w-4 h-4" />
|
|
|
|
|
Ocultar Comparación
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<ChevronDown className="w-4 h-4" />
|
|
|
|
|
Mostrar Comparación Detallada
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{showComparison && (
|
|
|
|
|
<PlanComparisonTable
|
|
|
|
|
plans={availablePlans}
|
|
|
|
|
currentTier={usageSummary.plan}
|
|
|
|
|
onSelectPlan={(tier) => handleUpgradeClick(tier, 'comparison_table')}
|
|
|
|
|
mode="inline"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-09-24 22:22:01 +02:00
|
|
|
{/* Available Plans */}
|
2025-10-31 11:54:19 +01:00
|
|
|
<Card className="p-6">
|
2025-09-24 22:22:01 +02:00
|
|
|
<h3 className="text-lg font-semibold mb-6 text-[var(--text-primary)] flex items-center">
|
|
|
|
|
<Crown className="w-5 h-5 mr-2 text-yellow-500" />
|
|
|
|
|
Planes Disponibles
|
|
|
|
|
</h3>
|
2025-10-19 19:22:37 +02:00
|
|
|
<SubscriptionPricingCards
|
2025-11-19 21:01:06 +01:00
|
|
|
mode="settings"
|
2025-10-19 19:22:37 +02:00
|
|
|
selectedPlan={usageSummary.plan}
|
2025-11-19 21:01:06 +01:00
|
|
|
onPlanSelect={(plan) => handleUpgradeClick(plan, 'pricing_cards')}
|
2025-10-19 19:22:37 +02:00
|
|
|
showPilotBanner={false}
|
|
|
|
|
/>
|
2025-10-31 11:54:19 +01:00
|
|
|
</Card>
|
2025-09-25 14:30:47 +02:00
|
|
|
|
|
|
|
|
{/* Invoices Section */}
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<div className="flex items-center justify-between mb-6">
|
|
|
|
|
<h3 className="text-lg font-semibold text-[var(--text-primary)] flex items-center">
|
|
|
|
|
<Download className="w-5 h-5 mr-2 text-blue-500" />
|
|
|
|
|
Historial de Facturas
|
|
|
|
|
</h3>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-10-31 11:54:19 +01:00
|
|
|
{invoicesLoading && !invoicesLoaded ? (
|
2025-09-25 14:30:47 +02:00
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
<div className="flex flex-col items-center gap-4">
|
|
|
|
|
<RefreshCw className="w-8 h-8 animate-spin text-[var(--color-primary)]" />
|
|
|
|
|
<p className="text-[var(--text-secondary)]">Cargando facturas...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : invoices.length === 0 ? (
|
|
|
|
|
<div className="text-center py-8">
|
2025-10-31 11:54:19 +01:00
|
|
|
<div className="flex flex-col items-center gap-3">
|
|
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-full">
|
|
|
|
|
<Download className="w-8 h-8 text-[var(--text-tertiary)]" />
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-[var(--text-secondary)]">No hay facturas disponibles</p>
|
|
|
|
|
<p className="text-sm text-[var(--text-tertiary)]">Las facturas aparecerán aquí una vez realizados los pagos</p>
|
|
|
|
|
</div>
|
2025-09-25 14:30:47 +02:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="overflow-x-auto">
|
|
|
|
|
<table className="w-full">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr className="border-b border-[var(--border-color)]">
|
2025-10-31 11:54:19 +01:00
|
|
|
<th className="text-left py-3 px-4 text-[var(--text-secondary)] font-medium text-sm">Fecha</th>
|
|
|
|
|
<th className="text-left py-3 px-4 text-[var(--text-secondary)] font-medium text-sm">Descripción</th>
|
|
|
|
|
<th className="text-right py-3 px-4 text-[var(--text-secondary)] font-medium text-sm">Monto</th>
|
|
|
|
|
<th className="text-center py-3 px-4 text-[var(--text-secondary)] font-medium text-sm">Estado</th>
|
|
|
|
|
<th className="text-center py-3 px-4 text-[var(--text-secondary)] font-medium text-sm">Acciones</th>
|
2025-09-25 14:30:47 +02:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{invoices.map((invoice) => (
|
2025-10-31 11:54:19 +01:00
|
|
|
<tr key={invoice.id} className="border-b border-[var(--border-color)] hover:bg-[var(--bg-secondary)] transition-colors">
|
|
|
|
|
<td className="py-3 px-4 text-[var(--text-primary)] font-medium">
|
|
|
|
|
{new Date(invoice.date).toLocaleDateString('es-ES', {
|
|
|
|
|
day: '2-digit',
|
|
|
|
|
month: 'short',
|
|
|
|
|
year: 'numeric'
|
|
|
|
|
})}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="py-3 px-4 text-[var(--text-primary)]">
|
|
|
|
|
{invoice.description || 'Suscripción'}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="py-3 px-4 text-[var(--text-primary)] font-semibold text-right">
|
|
|
|
|
{subscriptionService.formatPrice(invoice.amount)}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="py-3 px-4 text-center">
|
|
|
|
|
<Badge variant={invoice.status === 'paid' ? 'success' : invoice.status === 'open' ? 'warning' : 'default'}>
|
|
|
|
|
{invoice.status === 'paid' ? 'Pagada' : invoice.status === 'open' ? 'Pendiente' : invoice.status}
|
2025-09-25 14:30:47 +02:00
|
|
|
</Badge>
|
|
|
|
|
</td>
|
2025-10-31 11:54:19 +01:00
|
|
|
<td className="py-3 px-4 text-center">
|
2025-09-25 14:30:47 +02:00
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
2025-10-31 11:54:19 +01:00
|
|
|
onClick={() => handleDownloadInvoice(invoice)}
|
|
|
|
|
disabled={!invoice.invoice_pdf && !invoice.hosted_invoice_url}
|
|
|
|
|
className="flex items-center gap-2 mx-auto"
|
2025-09-25 14:30:47 +02:00
|
|
|
>
|
|
|
|
|
<Download className="w-4 h-4" />
|
2025-10-31 11:54:19 +01:00
|
|
|
{invoice.invoice_pdf ? 'PDF' : 'Ver'}
|
2025-09-25 14:30:47 +02:00
|
|
|
</Button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
))}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
{/* Subscription Management */}
|
|
|
|
|
<Card className="p-6">
|
|
|
|
|
<h3 className="text-lg font-semibold mb-6 text-[var(--text-primary)] flex items-center">
|
2025-10-31 11:54:19 +01:00
|
|
|
<Settings className="w-5 h-5 mr-2 text-purple-500" />
|
2025-09-25 14:30:47 +02:00
|
|
|
Gestión de Suscripción
|
|
|
|
|
</h3>
|
2025-10-31 11:54:19 +01:00
|
|
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
|
|
|
{/* Payment Method Card */}
|
|
|
|
|
<div className="p-6 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)] hover:border-[var(--color-primary)]/30 transition-colors">
|
|
|
|
|
<div className="flex items-start gap-4">
|
|
|
|
|
<div className="p-3 bg-blue-500/10 rounded-lg border border-blue-500/20 flex-shrink-0">
|
|
|
|
|
<CreditCard className="w-6 h-6 text-blue-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h4 className="font-semibold text-[var(--text-primary)] mb-2">Método de Pago</h4>
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)] mb-4 leading-relaxed">
|
|
|
|
|
Actualiza tu información de pago para asegurar la continuidad de tu servicio sin interrupciones.
|
|
|
|
|
</p>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
className="flex items-center gap-2 w-full sm:w-auto"
|
|
|
|
|
onClick={() => showToast.info('Función disponible próximamente')}
|
|
|
|
|
>
|
|
|
|
|
<CreditCard className="w-4 h-4" />
|
|
|
|
|
Actualizar Método de Pago
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-09-25 14:30:47 +02:00
|
|
|
</div>
|
2025-10-31 11:54:19 +01:00
|
|
|
|
|
|
|
|
{/* Cancel Subscription Card */}
|
|
|
|
|
<div className="p-6 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-secondary)] hover:border-red-500/30 transition-colors">
|
|
|
|
|
<div className="flex items-start gap-4">
|
|
|
|
|
<div className="p-3 bg-red-500/10 rounded-lg border border-red-500/20 flex-shrink-0">
|
|
|
|
|
<AlertCircle className="w-6 h-6 text-red-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<h4 className="font-semibold text-[var(--text-primary)] mb-2">Cancelar Suscripción</h4>
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)] mb-4 leading-relaxed">
|
|
|
|
|
Si cancelas, mantendrás acceso de solo lectura hasta el final de tu período de facturación actual.
|
|
|
|
|
</p>
|
|
|
|
|
<Button
|
|
|
|
|
variant="danger"
|
|
|
|
|
onClick={handleCancellationClick}
|
|
|
|
|
className="flex items-center gap-2 w-full sm:w-auto"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
Cancelar Suscripción
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Additional Info */}
|
|
|
|
|
<div className="mt-6 p-4 bg-blue-500/5 border border-blue-500/20 rounded-lg">
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
<Activity className="w-5 h-5 text-blue-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-sm text-[var(--text-primary)] font-medium mb-1">
|
|
|
|
|
¿Necesitas ayuda?
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)]">
|
|
|
|
|
Si tienes preguntas sobre tu suscripción o necesitas asistencia, contacta a nuestro equipo de soporte en{' '}
|
2025-11-18 22:17:56 +01:00
|
|
|
<a href="mailto:support@bakery-ia.com" className="text-blue-500 hover:text-white hover:bg-blue-500 px-2 py-0.5 rounded transition-all duration-200 no-underline">
|
2025-10-31 11:54:19 +01:00
|
|
|
support@bakery-ia.com
|
|
|
|
|
</a>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2025-09-25 14:30:47 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
2025-09-24 22:22:01 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-10-29 06:58:05 +01:00
|
|
|
{/* Upgrade Dialog */}
|
2025-09-24 22:22:01 +02:00
|
|
|
{upgradeDialogOpen && selectedPlan && availablePlans && (
|
2025-10-29 06:58:05 +01:00
|
|
|
<DialogModal
|
2025-09-24 22:22:01 +02:00
|
|
|
isOpen={upgradeDialogOpen}
|
|
|
|
|
onClose={() => setUpgradeDialogOpen(false)}
|
|
|
|
|
title="Confirmar Cambio de Plan"
|
2025-10-29 06:58:05 +01:00
|
|
|
message={
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<p>¿Estás seguro de que quieres cambiar tu plan de suscripción?</p>
|
|
|
|
|
{availablePlans.plans[selectedPlan as keyof typeof availablePlans.plans] && usageSummary && (
|
|
|
|
|
<div className="p-4 bg-[var(--bg-secondary)] rounded-lg space-y-2">
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span>Plan actual:</span>
|
2026-01-03 15:55:24 +01:00
|
|
|
<span>{t(`plans.${usageSummary.plan}.name`, usageSummary.plan)}</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-between">
|
|
|
|
|
<span>Nuevo plan:</span>
|
2026-01-03 15:55:24 +01:00
|
|
|
<span>{t(`plans.${selectedPlan}.name`, availablePlans.plans[selectedPlan as keyof typeof availablePlans.plans].name)}</span>
|
2025-10-29 06:58:05 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-between font-medium">
|
|
|
|
|
<span>Nuevo precio:</span>
|
|
|
|
|
<span>{subscriptionService.formatPrice(availablePlans.plans[selectedPlan as keyof typeof availablePlans.plans].monthly_price)}/mes</span>
|
|
|
|
|
</div>
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-29 06:58:05 +01:00
|
|
|
)}
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
2025-10-29 06:58:05 +01:00
|
|
|
}
|
|
|
|
|
type="confirm"
|
|
|
|
|
onConfirm={handleUpgradeConfirm}
|
|
|
|
|
onCancel={() => setUpgradeDialogOpen(false)}
|
|
|
|
|
confirmLabel="Confirmar Cambio"
|
|
|
|
|
cancelLabel="Cancelar"
|
|
|
|
|
loading={upgrading}
|
|
|
|
|
/>
|
2025-09-24 22:22:01 +02:00
|
|
|
)}
|
2025-09-25 14:30:47 +02:00
|
|
|
|
2025-10-29 06:58:05 +01:00
|
|
|
{/* Cancellation Dialog */}
|
2025-09-25 14:30:47 +02:00
|
|
|
{cancellationDialogOpen && (
|
2025-10-29 06:58:05 +01:00
|
|
|
<DialogModal
|
2025-09-25 14:30:47 +02:00
|
|
|
isOpen={cancellationDialogOpen}
|
|
|
|
|
onClose={() => setCancellationDialogOpen(false)}
|
|
|
|
|
title="Cancelar Suscripción"
|
2025-10-29 06:58:05 +01:00
|
|
|
message={
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<p>¿Estás seguro de que deseas cancelar tu suscripción? Esta acción no se puede deshacer.</p>
|
|
|
|
|
<p>Perderás acceso a las funcionalidades premium al final del período de facturación actual.</p>
|
2025-09-25 14:30:47 +02:00
|
|
|
</div>
|
2025-10-29 06:58:05 +01:00
|
|
|
}
|
|
|
|
|
type="warning"
|
|
|
|
|
onConfirm={handleCancelSubscription}
|
|
|
|
|
onCancel={() => setCancellationDialogOpen(false)}
|
|
|
|
|
confirmLabel="Confirmar Cancelación"
|
|
|
|
|
cancelLabel="Volver"
|
|
|
|
|
loading={cancelling}
|
|
|
|
|
/>
|
2025-09-25 14:30:47 +02:00
|
|
|
)}
|
2025-09-24 22:22:01 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-25 14:30:47 +02:00
|
|
|
export default SubscriptionPage;
|