- Delete duplicate page-new.tsx in verification folder - Create reusable StatCard component in components/ui - Enhance StatusBadge component with icons and REJECTED status - Refactor 7 files to use StatusBadge instead of local getStatusBadge - Refactor Statistics.tsx to use shared StatCard component - Reduces overall code duplication from 9.85% to lower 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
359 lines
17 KiB
TypeScript
359 lines
17 KiB
TypeScript
"use client";
|
|
import { useEffect, useState, useCallback } from "react";
|
|
import { useAuth } from "@/contexts/AuthContext";
|
|
import { useRouter } from "next/navigation";
|
|
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/Card";
|
|
import { StatusBadge } from "@/components/ui/StatusBadge";
|
|
import Button from "@/components/Button";
|
|
import { Loading } from "@/components/ui/Loading";
|
|
import { Ticket } from "@/types";
|
|
import { gameService } from "@/services/game.service";
|
|
import { ROUTES, PRIZE_CONFIG } from "@/utils/constants";
|
|
import { Calendar, Search } from "lucide-react";
|
|
|
|
export default function HistoriquePage() {
|
|
const { user, isAuthenticated, isLoading: authLoading } = useAuth();
|
|
const router = useRouter();
|
|
const [tickets, setTickets] = useState<Ticket[]>([]);
|
|
const [filteredTickets, setFilteredTickets] = useState<Ticket[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [filter, setFilter] = useState<'ALL' | 'CLAIMED' | 'PENDING' | 'REJECTED'>('ALL');
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
const [stats, setStats] = useState({
|
|
total: 0,
|
|
claimed: 0,
|
|
pending: 0,
|
|
rejected: 0,
|
|
});
|
|
|
|
const loadUserTickets = useCallback(async () => {
|
|
try {
|
|
const response = await gameService.getMyTickets(1, 1000);
|
|
const ticketsData = response?.data || [];
|
|
setTickets(ticketsData);
|
|
setFilteredTickets(ticketsData);
|
|
|
|
const total = ticketsData.length;
|
|
const claimed = ticketsData.filter((t: Ticket) => t.status === "CLAIMED").length;
|
|
const pending = ticketsData.filter((t: Ticket) => t.status === "PENDING").length;
|
|
const rejected = ticketsData.filter((t: Ticket) => t.status === "REJECTED").length;
|
|
|
|
setStats({ total, claimed, pending, rejected });
|
|
} catch (error) {
|
|
console.error("Error loading tickets:", error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
const filterTickets = useCallback(() => {
|
|
let result = [...tickets];
|
|
|
|
if (filter !== 'ALL') {
|
|
result = result.filter((t) => t.status === filter);
|
|
}
|
|
|
|
if (searchQuery) {
|
|
result = result.filter((t) =>
|
|
t.code.toLowerCase().includes(searchQuery.toLowerCase())
|
|
);
|
|
}
|
|
|
|
setFilteredTickets(result);
|
|
}, [tickets, filter, searchQuery]);
|
|
|
|
useEffect(() => {
|
|
if (!authLoading && !isAuthenticated) {
|
|
router.push(ROUTES.LOGIN);
|
|
return;
|
|
}
|
|
|
|
if (isAuthenticated) {
|
|
loadUserTickets();
|
|
}
|
|
}, [authLoading, isAuthenticated, router, loadUserTickets]);
|
|
|
|
useEffect(() => {
|
|
filterTickets();
|
|
}, [filterTickets]);
|
|
|
|
if (authLoading || isLoading) {
|
|
return (
|
|
<div className="min-h-[calc(100vh-8rem)] flex items-center justify-center">
|
|
<Loading size="lg" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isAuthenticated) {
|
|
return null;
|
|
}
|
|
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gradient-to-br from-[#f5f5f0] via-[#faf9f5] to-[#f5f5f0] py-8">
|
|
<div className="container mx-auto px-4">
|
|
<div className="mb-8">
|
|
<h1 className="text-4xl font-bold text-[#5a5a4e] mb-2 flex items-center gap-3">
|
|
<Calendar className="w-10 h-10 text-[#d4a574]" />
|
|
Historique de mes participations
|
|
</h1>
|
|
<p className="text-[#8a8a7a]">
|
|
Consultez l'historique complet de vos participations et gains
|
|
</p>
|
|
</div>
|
|
|
|
<div className="grid md:grid-cols-4 gap-6 mb-8">
|
|
<div className="bg-white rounded-xl shadow-md p-6 border border-[#e5e4dc]">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="text-sm font-medium text-[#8a8a7a] mb-2">Total</p>
|
|
<p className="text-4xl font-bold text-blue-600">{stats.total}</p>
|
|
</div>
|
|
<div className="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center">
|
|
<svg className="w-8 h-8 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-xl shadow-md p-6 border border-[#e5e4dc]">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="text-sm font-medium text-[#8a8a7a] mb-2">Réclamés</p>
|
|
<p className="text-4xl font-bold text-green-600">{stats.claimed}</p>
|
|
</div>
|
|
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center">
|
|
<svg className="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-xl shadow-md p-6 border border-[#e5e4dc]">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="text-sm font-medium text-[#8a8a7a] mb-2">En attente</p>
|
|
<p className="text-4xl font-bold text-yellow-600">{stats.pending}</p>
|
|
</div>
|
|
<div className="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center">
|
|
<svg className="w-8 h-8 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-xl shadow-md p-6 border border-[#e5e4dc]">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="text-sm font-medium text-[#8a8a7a] mb-2">Rejetés</p>
|
|
<p className="text-4xl font-bold text-red-600">{stats.rejected}</p>
|
|
</div>
|
|
<div className="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center">
|
|
<svg className="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
</svg>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-xl shadow-md p-6 mb-6 border border-[#e5e4dc]">
|
|
<div className="flex flex-col md:flex-row gap-4">
|
|
<div className="flex-1">
|
|
<div className="relative">
|
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-[#8a8a7a] w-5 h-5" />
|
|
<input
|
|
type="text"
|
|
placeholder="Rechercher par code ticket..."
|
|
value={searchQuery}
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
className="w-full pl-10 pr-4 py-3 border-2 border-[#e5e4dc] rounded-lg focus:ring-2 focus:ring-[#d4a574] focus:border-[#d4a574] focus:outline-none"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex gap-2">
|
|
<button
|
|
onClick={() => setFilter('ALL')}
|
|
className={`px-4 py-2 rounded-lg font-semibold transition-all ${
|
|
filter === 'ALL'
|
|
? 'bg-gradient-to-r from-[#d4a574] to-[#c4956a] text-white shadow-lg'
|
|
: 'bg-[#f5f5f0] text-[#5a5a4e] hover:bg-[#e5e4dc]'
|
|
}`}
|
|
>
|
|
Tous ({tickets.length})
|
|
</button>
|
|
<button
|
|
onClick={() => setFilter('CLAIMED')}
|
|
className={`px-4 py-2 rounded-lg font-semibold transition-all ${
|
|
filter === 'CLAIMED'
|
|
? 'bg-green-600 text-white shadow-lg'
|
|
: 'bg-[#f5f5f0] text-[#5a5a4e] hover:bg-[#e5e4dc]'
|
|
}`}
|
|
>
|
|
Réclamés ({stats.claimed})
|
|
</button>
|
|
<button
|
|
onClick={() => setFilter('PENDING')}
|
|
className={`px-4 py-2 rounded-lg font-semibold transition-all ${
|
|
filter === 'PENDING'
|
|
? 'bg-yellow-600 text-white shadow-lg'
|
|
: 'bg-[#f5f5f0] text-[#5a5a4e] hover:bg-[#e5e4dc]'
|
|
}`}
|
|
>
|
|
En attente ({stats.pending})
|
|
</button>
|
|
<button
|
|
onClick={() => setFilter('REJECTED')}
|
|
className={`px-4 py-2 rounded-lg font-semibold transition-all ${
|
|
filter === 'REJECTED'
|
|
? 'bg-red-600 text-white shadow-lg'
|
|
: 'bg-[#f5f5f0] text-[#5a5a4e] hover:bg-[#e5e4dc]'
|
|
}`}
|
|
>
|
|
Rejetés ({stats.rejected})
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white rounded-xl shadow-md overflow-hidden border border-[#e5e4dc]">
|
|
<div className="px-6 py-4 border-b border-[#e5e4dc]">
|
|
<h2 className="text-xl font-bold text-[#5a5a4e]">Tous mes tickets ({filteredTickets.length})</h2>
|
|
</div>
|
|
<div className="p-6">
|
|
{filteredTickets.length === 0 ? (
|
|
<div className="text-center py-12">
|
|
<div className="text-6xl mb-4">🎲</div>
|
|
<p className="text-[#8a8a7a] mb-4">
|
|
{searchQuery || filter !== 'ALL'
|
|
? 'Aucun ticket trouvé avec ces filtres'
|
|
: 'Vous n\'avez pas encore participé au jeu'}
|
|
</p>
|
|
{!searchQuery && filter === 'ALL' && (
|
|
<button
|
|
onClick={() => router.push(ROUTES.GAME)}
|
|
className="bg-gradient-to-r from-[#d4a574] to-[#c4956a] hover:from-[#e5b685] hover:to-[#d4a574] text-white font-bold px-6 py-3 rounded-lg transition-all shadow-lg hover:scale-105 duration-300"
|
|
>
|
|
Jouer maintenant
|
|
</button>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div className="overflow-x-auto">
|
|
<table className="min-w-full">
|
|
<thead>
|
|
<tr className="border-b border-[#e5e4dc]">
|
|
<th className="px-6 py-3 text-left text-xs font-semibold text-[#5a5a4e] uppercase tracking-wider">
|
|
Code Ticket
|
|
</th>
|
|
<th className="px-6 py-3 text-left text-xs font-semibold text-[#5a5a4e] uppercase tracking-wider">
|
|
Gain
|
|
</th>
|
|
<th className="px-6 py-3 text-left text-xs font-semibold text-[#5a5a4e] uppercase tracking-wider">
|
|
Statut
|
|
</th>
|
|
<th className="px-6 py-3 text-left text-xs font-semibold text-[#5a5a4e] uppercase tracking-wider">
|
|
Date de participation
|
|
</th>
|
|
<th className="px-6 py-3 text-left text-xs font-semibold text-[#5a5a4e] uppercase tracking-wider">
|
|
Date de réclamation
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-[#e5e4dc]">
|
|
{filteredTickets.map((ticket) => {
|
|
const prizeConfig = ticket.prize
|
|
? PRIZE_CONFIG[ticket.prize.type as keyof typeof PRIZE_CONFIG]
|
|
: null;
|
|
|
|
return (
|
|
<tr key={ticket.id} className="hover:bg-gradient-to-r hover:from-[#d4a574]/5 hover:to-[#c4956a]/5 transition-colors">
|
|
<td className="px-6 py-4 whitespace-nowrap">
|
|
<span className="font-mono text-sm font-semibold text-[#5a5a4e]">
|
|
{ticket.code}
|
|
</span>
|
|
</td>
|
|
<td className="px-6 py-4">
|
|
<div className="flex items-center gap-3">
|
|
{prizeConfig && (
|
|
<>
|
|
<div className={`w-10 h-10 rounded-full flex items-center justify-center ${prizeConfig.color}`}>
|
|
{ticket.prize?.type === 'INFUSEUR' && (
|
|
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M20 3H4v10c0 2.21 1.79 4 4 4h6c2.21 0 4-1.79 4-4v-3h2c1.11 0 2-.9 2-2V5c0-1.11-.89-2-2-2zm0 5h-2V5h2v3zM4 19h16v2H4z"/>
|
|
</svg>
|
|
)}
|
|
{ticket.prize?.type === 'THE_SIGNATURE' && (
|
|
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M20 3H4v10c0 2.21 1.79 4 4 4h6c2.21 0 4-1.79 4-4v-3h2c1.11 0 2-.9 2-2V5c0-1.11-.89-2-2-2zm0 5h-2V5h2v3z"/>
|
|
</svg>
|
|
)}
|
|
{ticket.prize?.type === 'COFFRET_DECOUVERTE' && (
|
|
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M20 6h-2.18c.11-.31.18-.65.18-1 0-1.66-1.34-3-3-3-1.05 0-1.96.54-2.5 1.35l-.5.67-.5-.68C10.96 2.54 10.05 2 9 2 7.34 2 6 3.34 6 5c0 .35.07.69.18 1H4c-1.11 0-1.99.89-1.99 2L2 19c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V8c0-1.11-.89-2-2-2zm-5-2c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zM9 4c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm11 15H4v-2h16v2zm0-5H4V8h5.08L7 10.83 8.62 12 11 8.76l1-1.36 1 1.36L15.38 12 17 10.83 14.92 8H20v6z"/>
|
|
</svg>
|
|
)}
|
|
{ticket.prize?.type === 'COFFRET_PRESTIGE' && (
|
|
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M12 2L4 5v6.09c0 5.05 3.41 9.76 8 10.91 4.59-1.15 8-5.86 8-10.91V5l-8-3zm6 9.09c0 4-2.55 7.7-6 8.83-3.45-1.13-6-4.82-6-8.83v-4.7l6-2.25 6 2.25v4.7zM8 10.5l1.5 1.5L15 6.5 13.5 5z"/>
|
|
</svg>
|
|
)}
|
|
{ticket.prize?.type === 'THE_GRATUIT' && (
|
|
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
|
|
<path d="M20 3H4v10c0 2.21 1.79 4 4 4h6c2.21 0 4-1.79 4-4v-3h2c1.11 0 2-.9 2-2V5c0-1.11-.89-2-2-2zm0 5h-2V5h2v3zM4 19h16v2H4z"/>
|
|
</svg>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<p className="text-sm font-medium text-[#5a5a4e]">
|
|
{prizeConfig.name}
|
|
</p>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</td>
|
|
<td className="px-6 py-4 whitespace-nowrap">
|
|
<StatusBadge type="ticket" value={ticket.status} />
|
|
</td>
|
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-[#8a8a7a]">
|
|
{ticket.playedAt
|
|
? new Date(ticket.playedAt).toLocaleDateString("fr-FR", {
|
|
day: 'numeric',
|
|
month: 'long',
|
|
year: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
})
|
|
: "-"}
|
|
</td>
|
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-[#8a8a7a]">
|
|
{ticket.claimedAt
|
|
? new Date(ticket.claimedAt).toLocaleDateString("fr-FR", {
|
|
day: 'numeric',
|
|
month: 'long',
|
|
year: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
})
|
|
: "-"}
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|