Newer
Older
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { IAccountStanding } from "@sc07-canvas/lib/src/net";
import { useCallback, useEffect, useState } from "react";
import network from "../../lib/network";
import {
Button,
Modal,
ModalBody,
ModalContent,
ModalFooter,
ModalHeader,
} from "@nextui-org/react";
export const AccountStanding = () => {
const [standingInfo, setStandingInfo] = useState(false);
const [standing, setStanding] = useState<IAccountStanding | undefined>(
network.getState("standing")?.[0]
);
const handleStanding = useCallback(
(standing: IAccountStanding) => {
setStanding(standing);
},
[setStanding]
);
useEffect(() => {
network.on("standing", handleStanding);
return () => {
network.off("standing", handleStanding);
};
}, []);
return (
<>
{standing?.banned && (
<div className="bg-red-500 bg-opacity-85 border-red-700 border-1 rounded-md p-1 flex items-center gap-2">
You are banned
<br />
<Button size="sm" onPress={() => setStandingInfo(true)}>
Details
</Button>
</div>
)}
<Modal isOpen={standingInfo} onClose={() => setStandingInfo(false)}>
<ModalContent>
{(onClose) => (
<>
<ModalHeader>Account Standing</ModalHeader>
<ModalBody>
{standing?.banned ? (
<>
You are banned until {standing.until}
<br />
{standing.reason ? (
<>Public reason given: {standing.reason}</>
) : (
<>No reason given</>
)}
</>
) : (
<>Your account is in good standing</>
)}
</ModalBody>
<ModalFooter>
<Button onPress={onClose}>Close</Button>
</ModalFooter>
</>
)}
</ModalContent>
</Modal>
</>
);
};