Add hunts table and default row; improve error handling and UI for team management

This commit is contained in:
bobbert committed 2025-03-12 15:48:35 +00:00
1 parent cd9c106ba1
commit a6ed24b2e6
8 files changed
+156 -52

No files matched your search

+56 -3
View File
@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
import Link from "next/link";
export default function TeamPage({ params }) {
const { status } = useSession();
const { status, data: session } = useSession();
const [team, setTeam] = useState(null);
const [teamMembers, setTeamMembers] = useState([]);
const [loading, setLoading] = useState(true);
@@ -20,6 +20,7 @@ export default function TeamPage({ params }) {
throw new Error("Invalid team ID");
}
// Fix the API endpoint path - ensure it matches your route structure
const response = await fetch(`/api/teams/${teamId}`, {
method: "GET",
headers: {
@@ -28,9 +29,17 @@ export default function TeamPage({ params }) {
credentials: "include",
});
// Add better error handling for debugging
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || "Failed to fetch team data");
const text = await response.text();
let errorMessage;
try {
const errorData = JSON.parse(text);
errorMessage = errorData.error || "Failed to fetch team data";
} catch (e) {
errorMessage = `Failed to fetch team data: ${response.status} ${text.slice(0, 100)}`;
}
throw new Error(errorMessage);
}
const data = await response.json();
@@ -100,6 +109,26 @@ export default function TeamPage({ params }) {
</div>
</div>
<div className="team-footer">
<button
className="leave-button"
onClick={() => {
/* implement leave logic */
}}
>
Leave Team
</button>
<button
className="start-hunt-button"
disabled={session?.user?.role !== "admin"}
onClick={() => {
/* implement start-hunt logic */
}}
>
Start Hunt
</button>
</div>
<div className="navbar">
<div className="nav-item">
<div className="nav-icon">🏠</div>
@@ -214,6 +243,30 @@ export default function TeamPage({ params }) {
color: black;
}
.team-footer {
display: flex;
justify-content: space-around;
padding: 15px 0;
background-color: #c8b6a6;
}
.leave-button,
.start-hunt-button {
background-color: #e9c46a;
color: black;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
}
.leave-button:disabled,
.start-hunt-button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.navbar {
display: flex;
justify-content: space-around;