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,
player1P1: true,
player1P2: true,
player2P1: true,
player2P2: true,
},
orderBy: { playedAt: "asc" },
},
matchesAsP2: {
where: { playedAt: { gte: new Date() } },
include: {
event: true,
player1P1: true,
player1P2: true,
player2P1: true,
player2P2: true,
},
orderBy: { playedAt: "asc" },
},
matchesAsP3: {
where: { playedAt: { gte: new Date() } },
include: {
event: true,
player1P1: true,
player1P2: true,
player2P1: true,
player2P2: true,
},
orderBy: { playedAt: "asc" },
},
matchesAsP4: {
where: { playedAt: { gte: new Date() } },
include: {
event: true,
player1P1: true,
player1P2: true,
player2P1: true,
player2P2: 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,
},
})
return (
My Schedule
{/* Upcoming Matches */}
Upcoming Matches
{upcomingMatches.length === 0 ? (
No upcoming matches
) : (
{upcomingMatches.map((match) => {
const team1Players = [
match.player1P1?.name,
match.player1P2?.name,
].filter(Boolean).join(" + ")
const team2Players = [
match.player2P1?.name,
match.player2P2?.name,
].filter(Boolean).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) => {
// Since teams are now ephemeral, just check if player is a participant
const isParticipant = tournament.participants.some(
(p) => p.playerId === playerId
)
return (
{tournament.name}
{tournament.format} - {tournament.status}
{isParticipant && (
Participant in tournament
)}
{new Date(tournament.eventDate || tournament.createdAt).toLocaleDateString()}
)
})}
)}
)
}