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: {
player1P1: true,
player1P2: true,
player2P1: true,
player2P2: true,
event: true,
},
});
return (
{/* Page Header */}
All Matches
View recent matches played.
{/* Matches List */}
|
Match ID
|
Team 1
|
Team 2
|
Score
|
Date
|
Actions
|
{matches.map((match) => (
|
#{match.id}
|
{match.player1P1?.name} & {match.player1P2?.name}
|
{match.player2P1?.name} & {match.player2P2?.name}
|
{match.team1Score}
-
{match.team2Score}
|
{match.playedAt
? new Date(match.playedAt).toLocaleDateString()
: "-"}
|
View
|
))}
{matches.length === 0 && (
)}
);
}