import { prisma } from "@/lib/prisma" export const dynamic = "force-dynamic"; import Navigation from "@/components/Navigation" import Link from "next/link" import { notFound } from "next/navigation" interface PageProps { params: { id: string } } export default async function PlayerSchedulePage({ params }: PageProps) { // Next.js 16 requires awaiting params const { id } = await params const playerId = parseInt(id, 10) if (isNaN(playerId)) { notFound() } const player = await prisma.player.findUnique({ where: { id: playerId }, include: { // Get upcoming matches matchesAsP1: { where: { playedAt: { gte: new Date() } }, include: { event: true, team1P1: true, team1P2: true, team2P1: true, team2P2: true, }, orderBy: { playedAt: "asc" }, }, matchesAsP2: { where: { playedAt: { gte: new Date() } }, include: { event: true, team1P1: true, team1P2: true, team2P1: true, team2P2: true, }, orderBy: { playedAt: "asc" }, }, matchesAsP3: { where: { playedAt: { gte: new Date() } }, include: { event: true, team1P1: true, team1P2: true, team2P1: true, team2P2: true, }, orderBy: { playedAt: "asc" }, }, matchesAsP4: { where: { playedAt: { gte: new Date() } }, include: { event: true, team1P1: true, team1P2: true, team2P1: true, team2P2: true, }, orderBy: { playedAt: "asc" }, }, }, }) if (!player) { notFound() } // Combine all upcoming matches const upcomingMatches = [ ...player.matchesAsP1, ...player.matchesAsP2, ...player.matchesAsP3, ...player.matchesAsP4, ].sort((a, b) => new Date(a.playedAt!).getTime() - new Date(b.playedAt!).getTime()) // Get active tournaments (events with status 'active' or 'in_progress') const activeTournaments = await prisma.event.findMany({ where: { status: { in: ['active', 'in_progress', 'started'] }, participants: { some: { playerId: playerId, }, }, }, include: { participants: true, teams: { include: { player1: true, player2: true, }, }, }, }) return (

My Schedule

{/* Upcoming Matches */}

Upcoming Matches

{upcomingMatches.length === 0 ? (

No upcoming matches scheduled.

) : (
{upcomingMatches.map((match) => { const team1Players = [ match.team1P1.name, match.team1P2.name, ].join(" + ") const team2Players = [ match.team2P1.name, match.team2P2.name, ].join(" + ") return (

{match.event?.name || "Tournament"} - {match.playedAt?.toLocaleDateString()}

{team1Players} vs {team2Players}

{match.playedAt?.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
) })}
)}
{/* Active Tournaments */}

Active Tournaments

{activeTournaments.length === 0 ? (

No active tournaments.

) : (
{activeTournaments.map((tournament) => { const playerTeam = tournament.teams.find( (team) => team.player1Id === playerId || team.player2Id === playerId ) return (
{tournament.name}

{tournament.format} - {tournament.status}

{playerTeam && (

Team: {playerTeam.player1.name} + {playerTeam.player2.name}

)}

{new Date(tournament.eventDate || tournament.createdAt).toLocaleDateString()}

) })}
)}
) }