Delete user component
This commit is contained in:
parent
e55b380bb4
commit
db4f869712
1 changed files with 34 additions and 0 deletions
34
frontend/src/Components/DeleteUser.tsx
Normal file
34
frontend/src/Components/DeleteUser.tsx
Normal file
|
@ -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<User>) => {
|
||||
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;
|
Loading…
Reference in a new issue