mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
231 lines
5.7 KiB
JavaScript
231 lines
5.7 KiB
JavaScript
"use client";
|
|
import { useState, useEffect } from "react";
|
|
import { useSession } from "next-auth/react";
|
|
import { useRouter } from "next/navigation";
|
|
import Link from "next/link";
|
|
|
|
export default function TeamPage({ params }) {
|
|
const { status } = useSession();
|
|
const [team, setTeam] = useState(null);
|
|
const [teamMembers, setTeamMembers] = useState([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState("");
|
|
const router = useRouter();
|
|
const { teamId } = params;
|
|
|
|
useEffect(() => {
|
|
async function fetchTeamData() {
|
|
try {
|
|
if (!teamId || isNaN(parseInt(teamId, 10))) {
|
|
throw new Error("Invalid team ID");
|
|
}
|
|
|
|
const response = await fetch(`/api/teams/${teamId}`, {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
credentials: "include",
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
throw new Error(errorData.error || "Failed to fetch team data");
|
|
}
|
|
|
|
const data = await response.json();
|
|
if (!data.team) {
|
|
throw new Error("Team not found");
|
|
}
|
|
|
|
setTeam(data.team);
|
|
setTeamMembers(data.members || []);
|
|
} catch (err) {
|
|
console.error("Team page error:", err);
|
|
setError(err.message);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
if (status === "authenticated" && teamId) {
|
|
fetchTeamData();
|
|
const interval = setInterval(fetchTeamData, 5000); // Refresh every 5 seconds
|
|
return () => clearInterval(interval);
|
|
}
|
|
}, [teamId, status]);
|
|
|
|
useEffect(() => {
|
|
if (status === "unauthenticated") {
|
|
router.push("/login");
|
|
}
|
|
}, [status, router]);
|
|
|
|
if (status === "loading" || loading) {
|
|
return <div className="loading">Loading...</div>;
|
|
}
|
|
|
|
if (error) {
|
|
return <div className="error">Error: {error}</div>;
|
|
}
|
|
|
|
if (!team) {
|
|
return <div className="error">Team not found</div>;
|
|
}
|
|
|
|
return (
|
|
<div className="team-page">
|
|
<div className="header">
|
|
<Link href="/team-selection" className="back-button">
|
|
←
|
|
</Link>
|
|
<div className="team-name">{team.name}</div>
|
|
<div className="team-code">{team.code}</div>
|
|
<div className="timer">00:00</div>
|
|
</div>
|
|
|
|
<div className="content-container">
|
|
<div className="add-users-button">Add Users</div>
|
|
|
|
<div className="users-container">
|
|
{teamMembers.map((member) => (
|
|
<div key={member.id} className="user-card">
|
|
{member.username}
|
|
</div>
|
|
))}
|
|
|
|
<div className="add-user-icon">
|
|
<div className="plus-icon">+</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="navbar">
|
|
<div className="nav-item">
|
|
<div className="nav-icon">🏠</div>
|
|
</div>
|
|
<div className="nav-item">
|
|
<div className="nav-icon">📊</div>
|
|
</div>
|
|
<div className="nav-item">
|
|
<div className="nav-icon">🏆</div>
|
|
</div>
|
|
<div className="nav-item">
|
|
<div className="nav-icon">👤</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style jsx>{`
|
|
.team-page {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
.header {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
padding: 15px 10px;
|
|
background-color: #c8b6a6;
|
|
color: white;
|
|
font-weight: bold;
|
|
position: relative;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.back-button {
|
|
font-size: 24px;
|
|
color: black;
|
|
text-decoration: none;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.team-name,
|
|
.team-code {
|
|
text-align: center;
|
|
font-weight: 600;
|
|
color: black;
|
|
}
|
|
|
|
.timer {
|
|
text-align: right;
|
|
color: black;
|
|
}
|
|
|
|
.content-container {
|
|
flex: 1;
|
|
background-color: #8ecae6;
|
|
display: flex;
|
|
flex-direction: column;
|
|
padding: 10px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.add-users-button {
|
|
background-color: #e9c46a;
|
|
color: black;
|
|
text-align: center;
|
|
padding: 15px;
|
|
margin: 10px 0;
|
|
border-radius: 15px;
|
|
font-weight: bold;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.users-container {
|
|
flex: 1;
|
|
background-color: #f6bd60;
|
|
border-radius: 10px;
|
|
padding: 10px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.user-card {
|
|
background-color: #c8b6a6;
|
|
color: black;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
font-weight: bold;
|
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.add-user-icon {
|
|
display: flex;
|
|
justify-content: center;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.plus-icon {
|
|
width: 30px;
|
|
height: 30px;
|
|
background-color: #c8b6a6;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 20px;
|
|
color: black;
|
|
}
|
|
|
|
.navbar {
|
|
display: flex;
|
|
justify-content: space-around;
|
|
padding: 15px 0;
|
|
background-color: #c8b6a6;
|
|
}
|
|
|
|
.nav-icon {
|
|
font-size: 24px;
|
|
}
|
|
`}</style>
|
|
</div>
|
|
);
|
|
}
|