-
Notifications
You must be signed in to change notification settings - Fork 1
/
BanUser.tsx
47 lines (40 loc) · 1.24 KB
/
BanUser.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Button, Input } from "antd";
import styles from "./BanUser.module.scss";
import { useState } from "react";
import { useMutation } from "react-query";
import { banUser } from "../../../../Services/user";
import { NotificationUtil } from "../../../../Library/utils/notification";
import { handleAxiosError } from "../../../../Library/utils/handleError";
function BanUser() {
const [username, setUsername] = useState("");
const banUserMutation = useMutation(banUser, {
onSuccess: async () => {
NotificationUtil.success(
`You successfully banned the user with username ${username}.`
);
},
onError: (error) => {
handleAxiosError(error);
},
});
const handleClick = () => {
banUserMutation.mutate(username);
};
return (
<div className={styles.container}>
<h1 className={styles.header}>Ban User</h1>
<div className={styles.form}>
<Input
placeholder="Username"
value={username}
className={styles.input}
onChange={(event) => setUsername(event.target.value)}
/>
<Button type="primary" className={styles.button} onClick={handleClick}>
Ban User
</Button>
</div>
</div>
);
}
export default BanUser;