"use client"; import { useEffect, useState } from "react"; import { useAuth } from "@/contexts/AuthContext"; import { useRouter } from "next/navigation"; import { Loading } from "@/components/ui/Loading"; import { TicketTableRow } from "@/components/ui/TicketTableRow"; import { Ticket } from "@/types"; import { gameService } from "@/services/game.service"; import { ROUTES } from "@/utils/constants"; import Link from "next/link"; export default function ClientPage() { const { user, isAuthenticated, isLoading: authLoading } = useAuth(); const router = useRouter(); const [tickets, setTickets] = useState([]); const [isLoading, setIsLoading] = useState(true); const [stats, setStats] = useState({ total: 0, claimed: 0, pending: 0, }); useEffect(() => { if (!authLoading && !isAuthenticated) { router.push(ROUTES.LOGIN); return; } if (isAuthenticated) { loadUserTickets(); } }, [authLoading, isAuthenticated, router]); const loadUserTickets = async () => { try { const response = await gameService.getMyTickets(1, 100); const ticketsData = response?.data || []; setTickets(ticketsData); // Calculate stats const total = ticketsData.length; const claimed = ticketsData.filter((t: Ticket) => t.status === "CLAIMED").length; const pending = ticketsData.filter((t: Ticket) => t.status === "PENDING").length; setStats({ total, claimed, pending }); } catch (error) { console.error("Error loading tickets:", error); } finally { setIsLoading(false); } }; if (authLoading || isLoading) { return (
); } if (!isAuthenticated) { return null; } return (
{/* Welcome Section */}

Bonjour {user?.firstName} !

Bienvenue dans votre espace client

{/* Quick Action */}

Vous avez un nouveau ticket ?

Entrez votre code et découvrez votre gain instantanément

{/* Statistics Cards */}

Total Participations

{stats.total}

Gains réclamés

{stats.claimed}

En attente

{stats.pending}

{/* Recent Tickets */}

Mes derniers tickets

{tickets.length === 0 ? (
🎲

Vous n'avez pas encore participé au jeu

) : (
{tickets.slice(0, 5).map((ticket) => ( ))}
Code Ticket Gain Statut Date
)}
); }