2024-03-19 00:15:42 +01:00
|
|
|
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 {
|
|
|
|
let removed = false;
|
|
|
|
api
|
|
|
|
.removeUser(
|
|
|
|
props.usernameToDelete,
|
|
|
|
localStorage.getItem("accessToken") ?? "",
|
|
|
|
)
|
|
|
|
.then((response: APIResponse<User>) => {
|
|
|
|
if (response.success) {
|
2024-03-28 12:38:40 +01:00
|
|
|
alert("User has been deleted!");
|
|
|
|
location.reload();
|
2024-03-19 00:15:42 +01:00
|
|
|
removed = true;
|
|
|
|
} else {
|
2024-03-28 12:38:40 +01:00
|
|
|
alert("User has not been deleted");
|
2024-03-19 00:15:42 +01:00
|
|
|
console.error(response.message);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2024-03-28 12:38:40 +01:00
|
|
|
alert("User has not been deleted");
|
2024-03-19 00:15:42 +01:00
|
|
|
console.error("An error occurred during creation:", error);
|
|
|
|
});
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DeleteUser;
|