Add useEffect hook to handle authority navigation and log response in YourProjectsPage
This commit is contained in:
parent
f6b2d17b97
commit
164ff781b3
2 changed files with 12 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
import LoginPage from "./LoginPage";
|
import LoginPage from "./LoginPage";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
@ -6,13 +6,16 @@ import { useNavigate } from "react-router-dom";
|
||||||
function App(): JSX.Element {
|
function App(): JSX.Element {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [authority, setAuthority] = useState(0);
|
const [authority, setAuthority] = useState(0);
|
||||||
if (authority === 1) {
|
|
||||||
navigate("/admin");
|
useEffect(() => {
|
||||||
} else if (authority === 2) {
|
if (authority === 1) {
|
||||||
navigate("/pm");
|
navigate("/admin");
|
||||||
} else if (authority === 3) {
|
} else if (authority === 2) {
|
||||||
navigate("/user");
|
navigate("/pm");
|
||||||
}
|
} else if (authority === 3) {
|
||||||
|
navigate("/user");
|
||||||
|
}
|
||||||
|
}, [authority, navigate]);
|
||||||
|
|
||||||
return <LoginPage setAuthority={setAuthority} />;
|
return <LoginPage setAuthority={setAuthority} />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ function UserProjectPage(): JSX.Element {
|
||||||
const username = localStorage.getItem("username") ?? ""; // replace with actual username
|
const username = localStorage.getItem("username") ?? ""; // replace with actual username
|
||||||
const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token
|
const token = localStorage.getItem("accessToken") ?? ""; // replace with actual token
|
||||||
const response = await api.getUserProjects(username, token);
|
const response = await api.getUserProjects(username, token);
|
||||||
|
console.log(response);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setProjects(response.data ?? []);
|
setProjects(response.data ?? []);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue