"use client"; // Mark as a Client Component import { useState, useEffect } from "react"; import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { joinTeam } from "../../actions/auth"; // Add CSS to fix the navbar at the bottom const styles = { navbar: { position: "fixed", bottom: 0, width: "100%", backgroundColor: "#fff", borderTop: "1px solid #ccc", padding: "10px 0", textAlign: "center", }, }; export default function TeamSelection() { const { data: session, status } = useSession(); const [teamCode, setTeamCode] = useState(""); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); // Use useEffect for navigation instead of doing it in render useEffect(() => { // Redirect if not authenticated if (status === "unauthenticated") { router.push("/login"); } // Redirect if user is admin if (status === "authenticated" && session?.user?.role === "admin") { router.push("/admin"); } }, [status, session, router]); const handleJoinTeam = async (e) => { e.preventDefault(); setIsLoading(true); setError(""); try { const result = await joinTeam(session.user.id, teamCode); if (result.success) { router.push(`/team/${result.teamId}`); } else { setError(result.error || "Team not found"); } } catch (err) { setError("An unexpected error occurred"); console.error(err); } finally { setIsLoading(false); } }; if (status === "loading") { return
Loading...
; } // Don't render anything if redirecting if ( status === "unauthenticated" || (status === "authenticated" && session?.user?.role === "admin") ) { return null; } return (
Team Selection

Team Selection

setTeamCode(e.target.value)} required className="auth-input" />
{error &&

{error}

}
🏠
📊
🏆
👤
); }