From 164ff781b3e4799f977872bbd1455644d83cd7c4 Mon Sep 17 00:00:00 2001 From: Davenludd Date: Mon, 18 Mar 2024 10:43:52 +0100 Subject: [PATCH] Add useEffect hook to handle authority navigation and log response in YourProjectsPage --- frontend/src/Pages/App.tsx | 19 +++++++++++-------- frontend/src/Pages/YourProjectsPage.tsx | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frontend/src/Pages/App.tsx b/frontend/src/Pages/App.tsx index 7ded3b6..4263815 100644 --- a/frontend/src/Pages/App.tsx +++ b/frontend/src/Pages/App.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import LoginPage from "./LoginPage"; import { useNavigate } from "react-router-dom"; @@ -6,13 +6,16 @@ import { useNavigate } from "react-router-dom"; function App(): JSX.Element { const navigate = useNavigate(); const [authority, setAuthority] = useState(0); - if (authority === 1) { - navigate("/admin"); - } else if (authority === 2) { - navigate("/pm"); - } else if (authority === 3) { - navigate("/user"); - } + + useEffect(() => { + if (authority === 1) { + navigate("/admin"); + } else if (authority === 2) { + navigate("/pm"); + } else if (authority === 3) { + navigate("/user"); + } + }, [authority, navigate]); return ; } diff --git a/frontend/src/Pages/YourProjectsPage.tsx b/frontend/src/Pages/YourProjectsPage.tsx index 4e43bb6..30912a6 100644 --- a/frontend/src/Pages/YourProjectsPage.tsx +++ b/frontend/src/Pages/YourProjectsPage.tsx @@ -11,6 +11,7 @@ function UserProjectPage(): JSX.Element { const username = localStorage.getItem("username") ?? ""; // replace with actual username const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token const response = await api.getUserProjects(username, token); + console.log(response); if (response.success) { setProjects(response.data ?? []); } else {