From 72d27bb64480c1315f2b7ff3b48ed085f4333e14 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Thu, 11 Apr 2024 00:39:06 +0200 Subject: [PATCH] Added search functionality and inputfield for changing p-name --- frontend/src/Components/ProjectInfoModal.tsx | 136 ++++++++++++++----- 1 file changed, 105 insertions(+), 31 deletions(-) diff --git a/frontend/src/Components/ProjectInfoModal.tsx b/frontend/src/Components/ProjectInfoModal.tsx index 1f98d79..66cffc2 100644 --- a/frontend/src/Components/ProjectInfoModal.tsx +++ b/frontend/src/Components/ProjectInfoModal.tsx @@ -4,19 +4,47 @@ import GetUsersInProject, { ProjectMember } from "./GetUsersInProject"; import { Link } from "react-router-dom"; import GetProjectTimes, { projectTimes } from "./GetProjectTimes"; import DeleteProject from "./DeleteProject"; +import InputField from "./InputField"; function ProjectInfoModal(props: { projectname: string; onClose: () => void; onClick: (username: string) => void; }): JSX.Element { + const [showInput, setShowInput] = useState(false); const [users, setUsers] = useState([]); const [times, setTimes] = useState(); + const [search, setSearch] = useState(""); + const [newProjName, setNewProjName] = useState(""); const totalTime = useRef(0); GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers }); GetProjectTimes({ setTimesProp: setTimes, projectName: props.projectname }); + const handleChangeNameView = (): void => { + if (showInput) { + setShowInput(false); + } else { + setShowInput(true); + } + }; + + const handleClickChangeName = (): void => { + if (newProjName === "") return; + + if ( + confirm( + `Are you sure you want to change name of ${props.projectname} to ${newProjName}?`, + ) + ) { + //TODO: change and insert change name functionality + alert("Not implemented yet"); + setNewProjName(""); + } else { + alert("Name was not changed!"); + } + }; + useEffect(() => { if (times?.totalTime !== undefined) { totalTime.current = times.totalTime; @@ -28,44 +56,90 @@ function ProjectInfoModal(props: { className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm flex justify-center items-center" > -
+
-

- {props.projectname} -

-
-

Statistics:

-
-
-

Number of members: {users.length}

-

+

{props.projectname}

+

+ (Change project name) +

+ {showInput && ( + <> +

Change name:

+
+ +
+
+
+ + )} +

Statistics:

+
+

Number of members: {users.length}

+

Total time reported:{" "} {Math.floor(totalTime.current / 60 / 24) + " d "} {Math.floor((totalTime.current / 60) % 24) + " h "} {(totalTime.current % 60) + " m "}

-
-

Project members:

-
-
-
    -
    - {users.map((user) => ( -
  • { - props.onClick(user.Username); - }} - > - - Name: {user.Username} -
    - Role: {user.UserRole} -
    -
  • - ))} +

    Project members:

    +
    + { + setSearch(e.target.value); + }} + /> +
      + {users + .filter((user) => { + return search.toLowerCase() === "" + ? user.Username + : user.Username.toLowerCase().includes( + search.toLowerCase(), + ); + }) + .map((user) => ( +
    • { + props.onClick(user.Username); + }} + > + + Name: {user.Username} +
      + Role: {user.UserRole} +
      +
    • + ))}