fix: update documentation and configuration files
This commit is contained in:
@@ -1,109 +1,94 @@
|
||||
"use client"
|
||||
|
||||
import { useSession, signOut } from "next-auth/react"
|
||||
import Link from "next/link"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useSession } from "./SessionProvider"
|
||||
import { authClient } from "@/lib/auth-client"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export default function Navigation() {
|
||||
const { data: session, status } = useSession()
|
||||
const pathname = usePathname()
|
||||
const { session, loading } = useSession()
|
||||
const [userRole, setUserRole] = useState<string | null>(null)
|
||||
|
||||
const isActive = (path: string) => pathname === path
|
||||
useEffect(() => {
|
||||
// Fetch user role from database if session exists
|
||||
if (session?.user?.id) {
|
||||
fetch(`/api/users/${session.user.id}/role`)
|
||||
.then(res => res.json())
|
||||
.then(data => setUserRole(data.role))
|
||||
.catch(() => setUserRole(null));
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
const handleLogout = async () => {
|
||||
await authClient.signOut()
|
||||
window.location.href = '/auth/login'
|
||||
}
|
||||
|
||||
return (
|
||||
<nav className="bg-green-800 text-white shadow-lg">
|
||||
<nav className="bg-white shadow-sm">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="flex items-center justify-between h-16">
|
||||
{/* Logo */}
|
||||
<div className="flex-shrink-0">
|
||||
<Link href="/" className="text-xl font-bold">
|
||||
<div className="flex justify-between h-16">
|
||||
<div className="flex items-center">
|
||||
<Link href="/" className="text-xl font-bold text-gray-900">
|
||||
EuchreCamp
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Navigation Links */}
|
||||
<div className="flex items-center space-x-4">
|
||||
<Link
|
||||
href="/rankings"
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
isActive("/rankings")
|
||||
? "bg-green-900 text-white"
|
||||
: "text-green-100 hover:bg-green-700 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
Rankings
|
||||
</Link>
|
||||
|
||||
{status === "authenticated" && session?.user && (
|
||||
<>
|
||||
<Link
|
||||
href={`/players/${session.user.playerId}/profile`}
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
isActive(`/players/${session.user.playerId}/profile`)
|
||||
? "bg-green-900 text-white"
|
||||
: "text-green-100 hover:bg-green-700 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
My Profile
|
||||
</Link>
|
||||
<Link
|
||||
href={`/players/${session.user.playerId}/schedule`}
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
isActive(`/players/${session.user.playerId}/schedule`)
|
||||
? "bg-green-900 text-white"
|
||||
: "text-green-100 hover:bg-green-700 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
My Schedule
|
||||
</Link>
|
||||
{(session.user.role === "tournament_admin" ||
|
||||
session.user.role === "club_admin") && (
|
||||
<div className="hidden md:ml-6 md:flex md:space-x-8">
|
||||
<Link
|
||||
href="/rankings"
|
||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||
>
|
||||
Rankings
|
||||
</Link>
|
||||
{session && (
|
||||
<>
|
||||
<Link
|
||||
href="/admin"
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
isActive("/admin")
|
||||
? "bg-green-900 text-white"
|
||||
: "text-green-100 hover:bg-green-700 hover:text-white"
|
||||
}`}
|
||||
href="/admin/tournaments"
|
||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||
>
|
||||
Admin
|
||||
Tournaments
|
||||
</Link>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{userRole === "club_admin" && (
|
||||
<Link
|
||||
href="/admin"
|
||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||
>
|
||||
Admin
|
||||
</Link>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* User Menu */}
|
||||
<div className="flex items-center space-x-4">
|
||||
{status === "loading" ? (
|
||||
<span className="text-green-100">Loading...</span>
|
||||
) : status === "authenticated" ? (
|
||||
<>
|
||||
<span className="text-green-100">
|
||||
<div className="flex items-center">
|
||||
{loading ? (
|
||||
<div className="text-gray-500">Loading...</div>
|
||||
) : session ? (
|
||||
<div className="flex items-center space-x-4">
|
||||
<span className="text-gray-700 text-sm font-medium">
|
||||
{session.user?.name || session.user?.email}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => signOut({ callbackUrl: "/" })}
|
||||
className="px-3 py-2 rounded-md text-sm font-medium bg-green-700 text-white hover:bg-green-600 transition-colors"
|
||||
onClick={handleLogout}
|
||||
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
||||
>
|
||||
Logout
|
||||
Sign out
|
||||
</button>
|
||||
</>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center space-x-4">
|
||||
<Link
|
||||
href="/auth/login"
|
||||
className="px-3 py-2 rounded-md text-sm font-medium bg-green-700 text-white hover:bg-green-600 transition-colors"
|
||||
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
||||
>
|
||||
Login
|
||||
Sign in
|
||||
</Link>
|
||||
<Link
|
||||
href="/auth/register"
|
||||
className="px-3 py-2 rounded-md text-sm font-medium bg-green-600 text-white hover:bg-green-500 transition-colors"
|
||||
className="bg-green-600 text-white px-3 py-1 rounded-md text-sm font-medium hover:bg-green-700"
|
||||
>
|
||||
Register
|
||||
Sign up
|
||||
</Link>
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user