diff --git a/frontend/src/Components/AddUserToProject.tsx b/frontend/src/Components/AddUserToProject.tsx index f567560..43d9345 100644 --- a/frontend/src/Components/AddUserToProject.tsx +++ b/frontend/src/Components/AddUserToProject.tsx @@ -1,9 +1,9 @@ import { useEffect, useState } from "react"; import Button from "./Button"; import AddMember, { AddMemberInfo } from "./AddMember"; -import BackButton from "./BackButton"; import GetUsersInProject, { ProjectMember } from "./GetUsersInProject"; import GetAllUsers from "./GetAllUsers"; +import InputField from "./InputField"; /** * Provides UI for adding a member to a project. @@ -13,6 +13,7 @@ function AddUserToProject(props: { projectName: string }): JSX.Element { const [names, setNames] = useState([]); const [users, setUsers] = useState([]); const [usersProj, setUsersProj] = useState([]); + const [search, setSearch] = useState(""); // Gets all users and project members for filtering GetAllUsers({ setUsersProp: setUsers }); @@ -36,8 +37,10 @@ function AddUserToProject(props: { projectName: string }): JSX.Element { // Attempts to add all of the selected users to the project const handleAddClick = async (): Promise => { - if (names.length === 0) + if (names.length === 0) { alert("You have to choose at least one user to add"); + return; + } for (const name of names) { const newMember: AddMemberInfo = { userName: name, @@ -60,32 +63,47 @@ function AddUserToProject(props: { projectName: string }): JSX.Element { }; return ( -
+

{props.projectName}

Choose users to add:

-
-
    + +
    + { + setSearch(e.target.value); + }} + /> +
      - {users.map((user) => ( -
    • { - handleUserClick(user); - }} - > - {user} -
    • - ))} + {users + .filter((user) => { + return search.toLowerCase() === "" + ? user + : user.toLowerCase().includes(search.toLowerCase()); + }) + .map((user) => ( +
    • { + handleUserClick(user); + }} + > + {user} +
    • + ))}

    @@ -99,9 +117,7 @@ function AddUserToProject(props: { projectName: string }): JSX.Element { }} type="button" /> -

-

); }