diff --git a/frontend/src/Components/AddUserToProject.tsx b/frontend/src/Components/AddUserToProject.tsx index debd0f9..9f4439b 100644 --- a/frontend/src/Components/AddUserToProject.tsx +++ b/frontend/src/Components/AddUserToProject.tsx @@ -1,39 +1,13 @@ import { useState } from "react"; -import { APIResponse, api } from "../API/API"; import { NewProjMember } from "../Types/goTypes"; -import Logo from "../assets/Logo.svg"; import Button from "./Button"; import GetAllUsers from "./GetAllUsers"; +import AddMember from "./AddMember"; +import BackButton from "./BackButton"; /** - * Tries to add a member to a project - * @param {Object} props - A NewProjMember - * @returns {boolean} True if added, false if not - */ -function MemberAdd(props: { memberToAdd: NewProjMember }): boolean { - let added = false; - - api - .addUserToProject( - props.memberToAdd, - localStorage.getItem("accessToken") ?? "", - ) - .then((response: APIResponse) => { - if (response.success) { - added = true; - } else { - console.error(response.message); - } - }) - .catch((error) => { - console.error("An error occurred during member add:", error); - }); - return added; -} - -/** - * Provides UI for adding a project to the system. - * @returns {JSX.Element} - Returns the component UI for adding a project + * Provides UI for adding a member to a project. + * @returns {JSX.Element} - Returns the component UI for adding a member */ function AddUserToProject(): JSX.Element { const [name, setName] = useState(""); @@ -45,86 +19,72 @@ function AddUserToProject(): JSX.Element { const newMember: NewProjMember = { username: name, projectname: localStorage.getItem("projectName") ?? "", - role: "user", + role: role, }; - return MemberAdd({ memberToAdd: newMember }); + return AddMember({ memberToAdd: newMember }); }; return ( -
-
-
{ - e.preventDefault(); - MemberAdd({ - memberToAdd: { - username: "", - projectname: "", - role: "project_manager", - }, - }); - }} - > - TTIME Logo -

- Add {name} to {localStorage.getItem("projectName") ?? ""} as {role} -

-

Role for user:

-
-
    -
  • { - setRole("user"); - }} - > - {"User"} -
  • -
  • { - setRole("project_manager"); - }} - > - {"Project manager"} -
  • -
-
-

User to add:

-
-
    -
    - {users.map((user) => ( -
  • { - setName(user); - }} - > - {user} -
  • - ))} -
-
-
-
-
-

+
+

+ User chosen: [{name}] +

+

+ Role chosen: [{role}] +

+

+ Project chosen: [{localStorage.getItem("projectName") ?? ""}] +

+

Choose role:

+
+
    +
  • { + setRole("member"); + }} + > + {"Member"} +
  • +
  • { + setRole("project_manager"); + }} + > + {"Project manager"} +
  • +
+

Choose user:

+
+
    +
    + {users.map((user) => ( +
  • { + setName(user); + }} + > + {user} +
  • + ))} +
+
+
+
+

); }