diff --git a/frontend/src/Components/AddProject.tsx b/frontend/src/Components/AddProject.tsx new file mode 100644 index 0000000..45814e3 --- /dev/null +++ b/frontend/src/Components/AddProject.tsx @@ -0,0 +1,94 @@ +import { useState } from "react"; +import { APIResponse, api } from "../API/API"; +import { NewProject, Project } from "../Types/goTypes"; +import InputField from "./InputField"; +import Logo from "../assets/Logo.svg"; +import Button from "./Button"; + +/** + * Tries to add a project to the system + * @param props - Project name and description + * @returns {boolean} True if created, false if not + */ +function CreateProject(props: { name: string; description: string }): boolean { + const project: NewProject = { + name: props.name, + description: props.description, + }; + + let created = false; + + api + .createProject(project, localStorage.getItem("accessToken") ?? "") + .then((response: APIResponse) => { + if (response.success) { + created = true; + } else { + console.error(response.message); + } + }) + .catch((error) => { + console.error("An error occurred during creation:", error); + }); + return created; +} + +/** + * Tries to add a project to the system + * @returns {JSX.Element} UI for project adding + */ +function AddProject(): JSX.Element { + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + + return ( +
+
+
{ + e.preventDefault(); + CreateProject({ name: name, description: description }); + }} + > + TTIME Logo +

+ Create a new project +

+ { + setName(e.target.value); + }} + /> + { + setDescription(e.target.value); + }} + /> +
+
+ +

+
+
+ ); +} + +export default AddProject; diff --git a/frontend/src/Components/Header.tsx b/frontend/src/Components/Header.tsx index ba0a939..7a1e8ba 100644 --- a/frontend/src/Components/Header.tsx +++ b/frontend/src/Components/Header.tsx @@ -5,7 +5,7 @@ function Header({ username }: { username: string }): JSX.Element { const [isOpen, setIsOpen] = useState(false); const handleLogout = (): void => { - // Add any logout logic here + localStorage.clear(); }; return ( diff --git a/frontend/src/Components/LoginCheck.tsx b/frontend/src/Components/LoginCheck.tsx index 3658cbf..786a96c 100644 --- a/frontend/src/Components/LoginCheck.tsx +++ b/frontend/src/Components/LoginCheck.tsx @@ -10,17 +10,21 @@ function LoginCheck(props: { username: string; password: string; setAuthority: Dispatch>; -}): number { +}): void { const user: NewUser = { username: props.username, password: props.password, }; + + localStorage.clear(); + api .login(user) .then((response: APIResponse) => { if (response.success) { if (response.data !== undefined) { const token = response.data; + localStorage.setItem("accessToken", token); //TODO: change so that it checks for user type (admin, user, pm) instead if (token !== "" && props.username === "admin") { props.setAuthority((prevAuth) => { @@ -42,14 +46,12 @@ function LoginCheck(props: { console.error("Token was undefined"); } } else { - console.error("Token could not be fetched"); + console.error("Token could not be fetched/No such user"); } }) .catch((error) => { console.error("An error occurred during login:", error); }); - - return 0; } export default LoginCheck; diff --git a/frontend/src/Components/Register.tsx b/frontend/src/Components/Register.tsx index ff1a06c..d8b2a47 100644 --- a/frontend/src/Components/Register.tsx +++ b/frontend/src/Components/Register.tsx @@ -3,34 +3,9 @@ import { NewUser } from "../Types/goTypes"; import { api } from "../API/API"; import Logo from "../assets/Logo.svg"; import Button from "./Button"; +import InputField from "./InputField"; import { useNavigate } from "react-router-dom"; -function InputField(props: { - label: string; - type: string; - value: string; - onChange: (e: React.ChangeEvent) => void; -}): JSX.Element { - return ( -
- - -
- ); -} - export default function Register(): JSX.Element { const [username, setUsername] = useState(); const [password, setPassword] = useState(); diff --git a/frontend/src/Components/UserListAdmin.tsx b/frontend/src/Components/UserListAdmin.tsx index e25ad5f..b86076a 100644 --- a/frontend/src/Components/UserListAdmin.tsx +++ b/frontend/src/Components/UserListAdmin.tsx @@ -1,11 +1,11 @@ import { Link } from "react-router-dom"; -import { User } from "../Types/goTypes"; +import { PublicUser } from "../Types/goTypes"; /** * The props for the UserProps component */ interface UserProps { - users: User[]; + users: PublicUser[]; } /** @@ -23,7 +23,7 @@ export function UserListAdmin(props: UserProps): JSX.Element {
    {props.users.map((user) => ( - +
  • {user.username}
  • diff --git a/frontend/src/Pages/AdminPages/AdminAddProject.tsx b/frontend/src/Pages/AdminPages/AdminAddProject.tsx index 2922400..6df8851 100644 --- a/frontend/src/Pages/AdminPages/AdminAddProject.tsx +++ b/frontend/src/Pages/AdminPages/AdminAddProject.tsx @@ -1,25 +1,13 @@ +import AddProject from "../../Components/AddProject"; +import BackButton from "../../Components/BackButton"; import BasicWindow from "../../Components/BasicWindow"; -import Button from "../../Components/Button"; function AdminAddProject(): JSX.Element { - const content = <>; + const content = ; const buttons = ( <> -