diff --git a/src/app/matches/page.tsx b/src/app/matches/page.tsx new file mode 100644 index 0000000..0a301e0 --- /dev/null +++ b/src/app/matches/page.tsx @@ -0,0 +1,126 @@ +import { prisma } from "@/lib/prisma"; +import Navigation from "@/components/Navigation"; +import Link from "next/link"; +import { redirect } from "next/navigation"; +import { getSession } from "@/lib/auth-simple"; +import { hasRole } from "@/lib/permissions"; + +export const dynamic = "force-dynamic"; + +export default async function MatchesListPage() { + // Check if user is logged in + const session = await getSession(); + if (!session) { + redirect("/auth/login"); + } + + // Get user role + const userId = session.user?.id || session.user?.userId; + const user = await prisma.user.findUnique({ + where: { id: userId }, + }); + + // Fetch all matches with player data + const matches = await prisma.match.findMany({ + orderBy: { createdAt: "desc" }, + take: 50, + include: { + team1P1: true, + team1P2: true, + team2P1: true, + team2P2: true, + event: true, + }, + }); + + return ( +
+ + +
+
+ {/* Page Header */} +
+
+
+

All Matches

+

+ View recent matches played. +

+
+
+
+ + {/* Matches List */} +
+
+ + + + + + + + + + + + + {matches.map((match) => ( + + + + + + + + + ))} + +
+ Match ID + + Team 1 + + Team 2 + + Score + + Date + + Actions +
+ #{match.id} + + {match.team1P1.name} & {match.team1P2.name} + + {match.team2P1.name} & {match.team2P2.name} + + {match.team1Score} + - + {match.team2Score} + + {match.playedAt + ? new Date(match.playedAt).toLocaleDateString() + : "-"} + + + View + +
+
+ + {matches.length === 0 && ( +
+

No matches found.

+
+ )} +
+
+
+
+ ); +}