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"; /** * 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 */ function AddUserToProject(): JSX.Element { const [name, setName] = useState(""); const [users, setUsers] = useState([]); const [role, setRole] = useState(""); GetAllUsers({ setUsersProp: setUsers }); const handleClick = (): boolean => { const newMember: NewProjMember = { username: name, projectname: localStorage.getItem("projectName") ?? "", role: "user", }; return MemberAdd({ 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}
  • ))}

); } export default AddUserToProject;