diff --git a/frontend/src/Components/DisplayUserProjects.tsx b/frontend/src/Components/DisplayUserProjects.tsx index f4fd782..1d1ecfe 100644 --- a/frontend/src/Components/DisplayUserProjects.tsx +++ b/frontend/src/Components/DisplayUserProjects.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react"; import { Project } from "../Types/goTypes"; -import { Link } from "react-router-dom"; +import { Link, useNavigate } from "react-router-dom"; import { api } from "../API/API"; /** @@ -9,6 +9,7 @@ import { api } from "../API/API"; */ function DisplayUserProject(): JSX.Element { const [projects, setProjects] = useState([]); + const navigate = useNavigate(); const getProjects = async (): Promise => { const token = localStorage.getItem("accessToken") ?? ""; @@ -21,6 +22,26 @@ function DisplayUserProject(): JSX.Element { } }; + const handleProjectClick = async (projectName: string): Promise => { + const username = localStorage.getItem("username") ?? ""; + const token = localStorage.getItem("accessToken") ?? ""; + const response = await api.checkIfProjectManager( + username, + projectName, + token, + ); + if (response.success) { + if (response.data) { + navigate(`/PMProjectPage/${projectName}`); + } else { + navigate(`/project/${projectName}`); + } + } else { + // handle error + console.error(response.message); + } + }; + // Call getProjects when the component mounts useEffect(() => { void getProjects(); @@ -30,12 +51,15 @@ function DisplayUserProject(): JSX.Element { <>

Your Projects

- {projects.map((project, index) => ( - + {projects.map((project) => ( +
void handleProjectClick(project.name)} + key={project.id} + >

{project.name}

- +
))}