mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
fixed a bit
This commit is contained in:
1 parent
c62413eafa
commit
4ed0480d08
10 files changed
+138
-149
No files matched your search
@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function TeamPage({ params }) {
|
||||
const { data: session, status } = useSession();
|
||||
const { status } = useSession();
|
||||
const [team, setTeam] = useState(null);
|
||||
const [teamMembers, setTeamMembers] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -88,9 +88,9 @@ export default function TeamPage({ params }) {
|
||||
<div className="add-users-button">Add Users</div>
|
||||
|
||||
<div className="users-container">
|
||||
{teamMembers.map((member, index) => (
|
||||
{teamMembers.map((member) => (
|
||||
<div key={member.id} className="user-card">
|
||||
User #{index + 1}
|
||||
{member.username}
|
||||
</div>
|
||||
))}
|
||||
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
// app/(main)/team/[teamId]/route.js
|
||||
import { queryOne, query } from "../../../../lib/db";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "../../../api/auth/[...nextauth]/route";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
||||
import { queryOne, query } from "@/lib/db";
|
||||
|
||||
export async function GET(request, context) {
|
||||
export async function GET(_, context) {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session) {
|
||||
// Redirect to login page instead of returning JSON
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
try {
|
||||
const { teamId } = context.params;
|
||||
const params = await context.params;
|
||||
const teamId = params.teamId;
|
||||
|
||||
// Instead of returning JSON, we should let the page component handle rendering
|
||||
// This route.js file should only be used for API endpoints, not page rendering
|
||||
const team = await queryOne("SELECT * FROM teams WHERE id = ?", [teamId]);
|
||||
|
||||
// Redirect to the page component
|
||||
return redirect(`/team/${teamId}`);
|
||||
if (!team) {
|
||||
return new Response(
|
||||
JSON.stringify({ success: false, error: "Team not found" }),
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const members = await query(
|
||||
"SELECT id, username FROM users WHERE team_id = ?",
|
||||
[teamId]
|
||||
);
|
||||
|
||||
return new Response(JSON.stringify({ success: true, team, members }), {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Team fetch error:", error);
|
||||
return new Response(
|
||||
JSON.stringify({ error: "Failed to fetch team details" }),
|
||||
JSON.stringify({ success: false, error: "Failed to fetch team" }),
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user