diff --git a/frontend/src/Components/AdminUserList.tsx b/frontend/src/Components/AdminUserList.tsx new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/Components/DeleteUser.tsx b/frontend/src/Components/DeleteUser.tsx new file mode 100644 index 0000000..db49724 --- /dev/null +++ b/frontend/src/Components/DeleteUser.tsx @@ -0,0 +1,34 @@ +import { User } from "../Types/goTypes"; +import { api, APIResponse } from "../API/API"; + +/** + * Use to remove a user from the system + * @param props - The username of user to remove + * @returns {boolean} True if removed, false if not + * @example + * const exampleUsername = "user"; + * DeleteUser({ usernameToDelete: exampleUsername }); + */ + +function DeleteUser(props: { usernameToDelete: string }): boolean { + //console.log(props.usernameToDelete); FOR DEBUG + let removed = false; + api + .removeUser( + props.usernameToDelete, + localStorage.getItem("accessToken") ?? "", + ) + .then((response: APIResponse) => { + if (response.success) { + removed = true; + } else { + console.error(response.message); + } + }) + .catch((error) => { + console.error("An error occurred during creation:", error); + }); + return removed; +} + +export default DeleteUser; diff --git a/frontend/src/Components/UserInfoModal.tsx b/frontend/src/Components/UserInfoModal.tsx new file mode 100644 index 0000000..a22ef01 --- /dev/null +++ b/frontend/src/Components/UserInfoModal.tsx @@ -0,0 +1,54 @@ +import { Link } from "react-router-dom"; +import Button from "./Button"; +import DeleteUser from "./DeleteUser"; +import UserProjectListAdmin from "./UserProjectListAdmin"; + +function UserInfoModal(props: { + isVisible: boolean; + username: string; + onClose: () => void; +}): JSX.Element { + if (!props.isVisible) return <>; + + return ( +
+
+

{props.username}

+ +

+ (Change Username) +

+ +
+

+ Member of these projects: +

+
+ +
+
+
+
+
+
+ ); +} + +export default UserInfoModal; diff --git a/frontend/src/Components/UserListAdmin.tsx b/frontend/src/Components/UserListAdmin.tsx index b86076a..3d2bcae 100644 --- a/frontend/src/Components/UserListAdmin.tsx +++ b/frontend/src/Components/UserListAdmin.tsx @@ -1,5 +1,6 @@ -import { Link } from "react-router-dom"; +import { useState } from "react"; import { PublicUser } from "../Types/goTypes"; +import UserInfoModal from "./UserInfoModal"; /** * The props for the UserProps component @@ -9,27 +10,52 @@ interface UserProps { } /** - * A list of users for admin manage users page, that links admin to the right user page - * thanks to the state property - * @param props - The users to display + * A list of users for admin manage users page, that sets an onClick + * function for eact user
  • element, which displays a modul with + * user info. + * @param props - An array of users users to display * @returns {JSX.Element} The user list * @example - * const users = [{ id: 1, userName: "Random name" }]; + * const users = [{ id: 1, userName: "ExampleName" }]; * return ; */ export function UserListAdmin(props: UserProps): JSX.Element { + const [modalVisible, setModalVisible] = useState(false); + const [username, setUsername] = useState(""); + + const handleClick = (username: string): void => { + setUsername(username); + setModalVisible(true); + }; + + const handleClose = (): void => { + setUsername(""); + setModalVisible(false); + }; + return ( -
    -
      - {props.users.map((user) => ( - -
    • + <> + +
      +
        + {props.users.map((user) => ( +
      • { + handleClick(user.username); + }} + > {user.username}
      • - - ))} -
      -
      + ))} +
    +
    + ); } diff --git a/frontend/src/Components/UserProjectListAdmin.tsx b/frontend/src/Components/UserProjectListAdmin.tsx index 69258a1..1b7b923 100644 --- a/frontend/src/Components/UserProjectListAdmin.tsx +++ b/frontend/src/Components/UserProjectListAdmin.tsx @@ -1,17 +1,17 @@ -import React, { useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { api } from "../API/API"; import { Project } from "../Types/goTypes"; -const UserProjectListAdmin: React.FC = () => { +function UserProjectListAdmin(): JSX.Element { const [projects, setProjects] = useState([]); useEffect(() => { const fetchProjects = async (): Promise => { try { const token = localStorage.getItem("accessToken") ?? ""; - const username = "NoUser"; // getUsernameFromContext(); // Assuming you have a function to get the username from your context + // const username = props.username; - const response = await api.getUserProjects(username, token); + const response = await api.getUserProjects(token); if (response.success) { setProjects(response.data ?? []); } else { @@ -26,18 +26,16 @@ const UserProjectListAdmin: React.FC = () => { }, []); return ( -
    -

    User Projects

    +
      {projects.map((project) => (
    • {project.name} - {/* Add any additional project details you want to display */}
    • ))}
    ); -}; +} export default UserProjectListAdmin; diff --git a/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx b/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx index 1756433..7eb2e2e 100644 --- a/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx +++ b/frontend/src/Pages/AdminPages/AdminChangeUsername.tsx @@ -1,3 +1,4 @@ +import BackButton from "../../Components/BackButton"; import BasicWindow from "../../Components/BasicWindow"; import Button from "../../Components/Button"; @@ -13,13 +14,7 @@ function AdminChangeUsername(): JSX.Element { }} type="button" /> -