'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useLanguage } from '@/context/LanguageContext'; import { useAuth } from '@/context/AuthContext'; import { dashboardApi, NextEventInfo, UserTicket, UserPayment, } from '@/lib/api'; import toast from 'react-hot-toast'; import { CardListSkeleton } from '@/components/ui/Skeleton'; import OverviewTab from './components/OverviewTab'; import TicketsTab from './components/TicketsTab'; import PaymentsTab from './components/PaymentsTab'; import AccountTab from './components/AccountTab'; type Tab = 'overview' | 'tickets' | 'payments' | 'account'; export default function DashboardPage() { const router = useRouter(); const { locale } = useLanguage(); const { user, isLoading: authLoading, token } = useAuth(); const [activeTab, setActiveTab] = useState('overview'); const [nextEvent, setNextEvent] = useState(null); const [tickets, setTickets] = useState([]); const [payments, setPayments] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { if (!authLoading && !user) { router.push('/login'); return; } if (user && token) { loadDashboardData(); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [user, authLoading, token]); const loadDashboardData = async () => { setLoading(true); try { const [nextEventRes, ticketsRes, paymentsRes] = await Promise.all([ dashboardApi.getNextEvent(), dashboardApi.getTickets(), dashboardApi.getPayments(), ]); setNextEvent(nextEventRes.nextEvent); setTickets(ticketsRes.tickets); setPayments(paymentsRes.payments); } catch (error) { console.error('Failed to load dashboard:', error); toast.error(locale === 'es' ? 'Error al cargar el panel' : 'Failed to load dashboard data'); } finally { setLoading(false); } }; const tabs: { id: Tab; label: { en: string; es: string } }[] = [ { id: 'overview', label: { en: 'Overview', es: 'Resumen' } }, { id: 'tickets', label: { en: 'Tickets', es: 'Entradas' } }, { id: 'payments', label: { en: 'Payments', es: 'Pagos' } }, { id: 'account', label: { en: 'Account', es: 'Cuenta' } }, ]; if (authLoading || !user) { return (
); } return (
{/* Welcome header */}

{locale === 'es' ? `¡Hola, ${user.name}!` : `Welcome, ${user.name}!`}

{/* Tab navigation */}
{/* Tab content */} {loading ? ( ) : ( <> {activeTab === 'overview' && ( )} {activeTab === 'tickets' && ( )} {activeTab === 'payments' && ( )} {activeTab === 'account' && } )}
); }