diff --git a/app/tournaments/[id]/page.js b/app/tournaments/[id]/page.js index c3c40aa..89e15d2 100644 --- a/app/tournaments/[id]/page.js +++ b/app/tournaments/[id]/page.js @@ -1,145 +1,188 @@ -import Image from 'next/image'; -import Link from 'next/link'; -import { CalendarIcon, ClockIcon } from '@radix-ui/react-icons'; -import { Trophy, DollarSign, Users, Shield } from 'lucide-react'; -import dbConnect from '../../../lib/dbConnect'; -import Tournament from '../../../model/Tournament'; +import Image from "next/image"; +import Link from "next/link"; +import { CalendarIcon, ClockIcon } from "@radix-ui/react-icons"; +import { Trophy, DollarSign, Users, Shield } from "lucide-react"; +import dbConnect from "../../../lib/dbConnect"; +import Tournament from "../../../model/Tournament"; async function getTournament(id) { - await dbConnect(); - if (!id) { - console.error('Tournament ID is undefined'); - return null; - } - try { - const tournament = await Tournament.findById(id) - .populate('gameId') - .populate('organizerId') - .lean(); - return tournament ? JSON.parse(JSON.stringify(tournament)) : null; - } catch (error) { - console.error('Error fetching tournament:', error); - return null; - } + await dbConnect(); + if (!id) { + console.error("Tournament ID is undefined"); + return null; + } + try { + const tournament = await Tournament.findById(id) + .populate("gameId") + .populate("organizerId") + .lean(); + return tournament ? JSON.parse(JSON.stringify(tournament)) : null; + } catch (error) { + console.error("Error fetching tournament:", error); + return null; + } } export default async function TournamentPage({ params }) { - if (!params || !params.id) { - return
Invalid tournament ID
; - } + if (!params || !params.id) { + return
Invalid tournament ID
; + } - const tournament = await getTournament(params.id); + const tournament = await getTournament(params.id); - if (!tournament) { - return
Tournament not found
; - } + if (!tournament) { + return
Tournament not found
; + } - return ( -
-
-
- {tournament.tournamentName} -
-
-

{tournament.tournamentName}

-
- - - {new Date(tournament.tournamentDates.started).toLocaleDateString()} - - - - {new Date(tournament.tournamentDates.started).toLocaleTimeString()} - -
-
-
-
+ return ( +
+
+
+ {tournament.tournamentName} -
-
-
-

Tournament Details

-
-

- - Prize Pool: ${tournament.prize.reduce((sum, prize) => sum + prize.amount, 0)} -

-

- - Participants: {tournament.registeredNumber}/{tournament.slots} -

-

- - Mode: {tournament.gameType} -

-

- - Entry Fee: {tournament.prize[0].amount === 0 ? 'Free' : `₹${tournament.prize[0].amount}`} -

-

Status: new Date(tournament.tournamentDates.ended) ? 'bg-red-600' : - 'bg-yellow-600' - }`}> - {new Date() < new Date(tournament.tournamentDates.started) ? 'Open' : - new Date() > new Date(tournament.tournamentDates.ended) ? 'Completed' : - 'Live'} -

-
-
-
-

Host

-
- {tournament.organizerId?.orgName - {tournament.organizerId?.orgName || "Unknown Organizer"} -
-
-
+
+
+

+ {tournament.tournamentName} +

+
+ + + {new Date( + tournament.tournamentDates.started + ).toLocaleDateString()} + + + + {new Date( + tournament.tournamentDates.started + ).toLocaleTimeString()} + +
+
+
+
-
-

Description

-

{tournament.gameId?.profile || "No description available"}

-
+
+
+
+

Tournament Details

+
+

+ + Prize Pool: $ + {tournament.prize.reduce( + (sum, prize) => sum + prize.amount, + 0 + )} +

+

+ + Participants: {tournament.registeredNumber}/{tournament.slots} +

+

+ + Mode: {tournament.gameType} +

+

+ + Entry Fee:{" "} + {tournament.prize[0].amount === 0 + ? "Free" + : `₹${tournament.prize[0].amount}`} +

+

+ Status:{" "} + + new Date(tournament.tournamentDates.ended) + ? "bg-red-600" + : "bg-yellow-600" + }`} + > + {new Date() < new Date(tournament.tournamentDates.started) + ? "Open" + : new Date() > new Date(tournament.tournamentDates.ended) + ? "Completed" + : "Live"} + +

+
+
+
+

Host

+
+ {tournament.organizerId?.orgName + + {tournament.organizerId?.orgName || "Unknown Organizer"} + +
+
+
-
-

Rules

-

{tournament.rules}

-
+
+

Description

+

{tournament.gameId?.profile || "No description available"}

+
-
-

Schedule

-
-
- Tournament Start - {new Date(tournament.tournamentDates.started).toLocaleString()} -
-
- Tournament End - {new Date(tournament.tournamentDates.ended).toLocaleString()} -
-
-
+
+

Rules

+

{tournament.rules}

+
-
- - Register for Tournament - -
-
+
+

Schedule

+
+
+ Tournament Start + + {new Date( + tournament.tournamentDates.started + ).toLocaleString()} + +
+
+ Tournament End + + {new Date(tournament.tournamentDates.ended).toLocaleString()} + +
+
+ +
+ + Register for Tournament + +
- ); +
+
+ ); } // Add caching and revalidation @@ -176,4 +219,4 @@ export const revalidate = 60; // Revalidate this page every 60 seconds // { stage: "Semi Finals", date: "JUL 3, 2024", time: "7:00 PM" }, // { stage: "Finals", date: "JUL 4, 2024", time: "8:00 PM" } // ] -// }; \ No newline at end of file +// };