Can now remove users from projects
This commit is contained in:
parent
0cb6af03e4
commit
2d8d200340
2 changed files with 49 additions and 5 deletions
|
@ -1,8 +1,8 @@
|
||||||
import Button from "./Button";
|
import Button from "./Button";
|
||||||
import DeleteUser from "./DeleteUser";
|
|
||||||
import UserProjectListAdmin from "./UserProjectListAdmin";
|
import UserProjectListAdmin from "./UserProjectListAdmin";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import ChangeRoleView from "./ChangeRoleView";
|
import ChangeRoleView from "./ChangeRoleView";
|
||||||
|
import RemoveUserFromProj from "./RemoveUserFromProj";
|
||||||
|
|
||||||
function MemberInfoModal(props: {
|
function MemberInfoModal(props: {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
@ -42,13 +42,16 @@ function MemberInfoModal(props: {
|
||||||
<UserProjectListAdmin username={props.username} />
|
<UserProjectListAdmin username={props.username} />
|
||||||
<div className="items-center space-x-6">
|
<div className="items-center space-x-6">
|
||||||
<Button
|
<Button
|
||||||
text={"Delete"}
|
text={"Remove"}
|
||||||
onClick={function (): void {
|
onClick={function (): void {
|
||||||
if (
|
if (
|
||||||
window.confirm("Are you sure you want to delete this user?")
|
window.confirm(
|
||||||
|
"Are you sure you want to remove this user from the project?",
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
DeleteUser({
|
RemoveUserFromProj({
|
||||||
usernameToDelete: props.username,
|
userToRemove: props.username,
|
||||||
|
projectName: props.projectName,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
41
frontend/src/Components/RemoveUserFromProj.tsx
Normal file
41
frontend/src/Components/RemoveUserFromProj.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { api, APIResponse } from "../API/API";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a user from a project
|
||||||
|
* @param {string} props.usernameToDelete - The username of user to remove
|
||||||
|
* @param {string} props.projectName - Project to remove user from
|
||||||
|
* @returns {void}
|
||||||
|
* @example
|
||||||
|
* const exampleUsername = "user";
|
||||||
|
* const exampleProjectName "project";
|
||||||
|
* RemoveUserFromProj({ userToRemove: exampleUsername, projectName: exampleProjectName });
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default function RemoveUserFromProj(props: {
|
||||||
|
userToRemove: string;
|
||||||
|
projectName: string;
|
||||||
|
}): void {
|
||||||
|
if (props.userToRemove === localStorage.getItem("username")) {
|
||||||
|
alert("Cannot remove yourself");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api
|
||||||
|
.removeUserFromProject(
|
||||||
|
props.userToRemove,
|
||||||
|
props.projectName,
|
||||||
|
localStorage.getItem("accessToken") ?? "",
|
||||||
|
)
|
||||||
|
.then((response: APIResponse<void>) => {
|
||||||
|
if (response.success) {
|
||||||
|
alert(`${props.userToRemove} has been removed!`);
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert(`${props.userToRemove} has not been removed due to an error`);
|
||||||
|
console.error(response.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
alert(`${props.userToRemove} has not been removed due to an error`);
|
||||||
|
console.error("An error occurred during deletion:", error);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue