From 79eb59ad46f15c6d7eccf3021e3ce116fb309618 Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Sun, 17 Mar 2024 14:13:35 +0100 Subject: [PATCH 1/5] button fix --- frontend/src/Pages/ProjectManagerPages/PMProjectMembers.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/Pages/ProjectManagerPages/PMProjectMembers.tsx b/frontend/src/Pages/ProjectManagerPages/PMProjectMembers.tsx index 2af1145..bbafd6a 100644 --- a/frontend/src/Pages/ProjectManagerPages/PMProjectMembers.tsx +++ b/frontend/src/Pages/ProjectManagerPages/PMProjectMembers.tsx @@ -14,6 +14,7 @@ function PMProjectMembers(): JSX.Element { onClick={(): void => { return; }} + type={"button"} /> @@ -22,6 +23,7 @@ function PMProjectMembers(): JSX.Element { onClick={(): void => { return; }} + type={"button"} /> From 141e5c8bb6120220f77f0d394c3d0b1b27999cda Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Sun, 17 Mar 2024 16:21:36 +0100 Subject: [PATCH 2/5] minor fix --- frontend/src/Pages/UserPages/UserNewTimeReportPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Pages/UserPages/UserNewTimeReportPage.tsx b/frontend/src/Pages/UserPages/UserNewTimeReportPage.tsx index 85c80df..ca84770 100644 --- a/frontend/src/Pages/UserPages/UserNewTimeReportPage.tsx +++ b/frontend/src/Pages/UserPages/UserNewTimeReportPage.tsx @@ -1,7 +1,7 @@ import BasicWindow from "../../Components/BasicWindow"; import Button from "../../Components/Button"; import NewTimeReport from "../../Components/TimeReport"; -import BackButton from "../../Components/BackButton"; +import { Link } from "react-router-dom"; function UserNewTimeReportPage(): JSX.Element { const content = ( From e7e79ced139eab82840c02f9485e0dfaebc26a58 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Sun, 17 Mar 2024 19:16:57 +0100 Subject: [PATCH 3/5] Now checks if user is in database with api.login and sets proper authority level based on name for now --- frontend/src/Components/LoginCheck.tsx | 74 ++++++++++++++++---------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/frontend/src/Components/LoginCheck.tsx b/frontend/src/Components/LoginCheck.tsx index ccf761d..3658cbf 100644 --- a/frontend/src/Components/LoginCheck.tsx +++ b/frontend/src/Components/LoginCheck.tsx @@ -1,34 +1,54 @@ -import { NewUser } from "../Types/Users"; +import { NewUser } from "../Types/goTypes"; +import { api, APIResponse } from "../API/API"; +import { Dispatch, SetStateAction } from "react"; -function LoginCheck(props: { username: string; password: string }): number { - //Example users for testing without backend, remove when using backend - const admin: NewUser = { - userName: "admin", - password: "123", - }; - const pmanager: NewUser = { - userName: "pmanager", - password: "123", - }; +/* + * Checks if user is in database with api.login and then sets proper authority level + * TODO: change so that it checks for user type (admin, user, pm) somehow instead + **/ +function LoginCheck(props: { + username: string; + password: string; + setAuthority: Dispatch>; +}): number { const user: NewUser = { - userName: "user", - password: "123", + username: props.username, + password: props.password, }; + api + .login(user) + .then((response: APIResponse) => { + if (response.success) { + if (response.data !== undefined) { + const token = response.data; + //TODO: change so that it checks for user type (admin, user, pm) instead + if (token !== "" && props.username === "admin") { + props.setAuthority((prevAuth) => { + prevAuth = 1; + return prevAuth; + }); + } else if (token !== "" && props.username === "pm") { + props.setAuthority((prevAuth) => { + prevAuth = 2; + return prevAuth; + }); + } else if (token !== "" && props.username === "user") { + props.setAuthority((prevAuth) => { + prevAuth = 3; + return prevAuth; + }); + } + } else { + console.error("Token was undefined"); + } + } else { + console.error("Token could not be fetched"); + } + }) + .catch((error) => { + console.error("An error occurred during login:", error); + }); - //TODO: Compare with db instead when finished - if (props.username === admin.userName && props.password === admin.password) { - return 1; - } else if ( - props.username === pmanager.userName && - props.password === pmanager.password - ) { - return 2; - } else if ( - props.username === user.userName && - props.password === user.password - ) { - return 3; - } return 0; } From b999e47f9424c71acf26b9e770635f053a82099e Mon Sep 17 00:00:00 2001 From: Peter KW Date: Sun, 17 Mar 2024 19:17:34 +0100 Subject: [PATCH 4/5] Changes to handlesubmit --- frontend/src/Pages/LoginPage.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/Pages/LoginPage.tsx b/frontend/src/Pages/LoginPage.tsx index f58f3e0..1ff8c9c 100644 --- a/frontend/src/Pages/LoginPage.tsx +++ b/frontend/src/Pages/LoginPage.tsx @@ -15,9 +15,10 @@ function LoginPage(props: { and if so, redirect to correct page */ function handleSubmit(event: FormEvent): void { event.preventDefault(); - props.setAuthority((prevAuth) => { - prevAuth = LoginCheck({ username: username, password: password }); - return prevAuth; + LoginCheck({ + username: username, + password: password, + setAuthority: props.setAuthority, }); } From 197712592313f7f3af2c62ba0bba236ea73cbabe Mon Sep 17 00:00:00 2001 From: Peter KW Date: Sun, 17 Mar 2024 19:18:03 +0100 Subject: [PATCH 5/5] Now exporting APIResponse interface --- frontend/src/API/API.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index bd6518b..6dfbc1e 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -7,7 +7,7 @@ import { } from "../Types/goTypes"; // This type of pattern should be hard to misuse -interface APIResponse { +export interface APIResponse { success: boolean; message?: string; data?: T;