import { redirect } from 'next/navigation' import Link from 'next/link' import { auth } from '@/lib/auth' import { db } from '@/lib/db' import { rounds, roundPlayers, courses, tees } from '@/lib/db/schema' import { eq, inArray } from 'drizzle-orm' import { buttonVariants } from '@/components/ui/button-variants' import { cn } from '@/lib/utils' import { headers } from 'next/headers' export default async function DashboardPage() { const session = await auth.api.getSession({ headers: await headers() }) if (!session) redirect('/login') const memberships = await db .select({ roundId: roundPlayers.roundId }) .from(roundPlayers) .where(eq(roundPlayers.userId, session.user.id)) const roundIds = memberships.map((m) => m.roundId) const activeRounds = roundIds.length > 0 ? await db .select({ id: rounds.id, name: rounds.name, date: rounds.date, status: rounds.status, holesCount: rounds.holesCount, courseName: courses.name, teeName: tees.name, teeColor: tees.color, }) .from(rounds) .innerJoin(courses, eq(rounds.courseId, courses.id)) .innerJoin(tees, eq(rounds.teeId, tees.id)) .where(inArray(rounds.id, roundIds)) .orderBy(rounds.date) : [] const visibleRounds = activeRounds.filter((r) => r.status !== 'completed') return (

Rounds

New round
{visibleRounds.length === 0 && (

No active rounds. Start one!

)}
{visibleRounds.map((round) => (
{round.courseName}
{round.name && {round.name} · } {round.teeName} · {round.holesCount} holes ·{' '} {new Date(round.date).toLocaleDateString()}
))}
) } function StatusBadge({ status }: { status: string }) { const styles: Record = { lobby: 'bg-yellow-100 text-yellow-800', active: 'bg-green-100 text-green-800', completed: 'bg-gray-100 text-gray-600', } return ( {status} ) }