Permalink
Newer
100644
153 lines (133 sloc)
3.99 KB
14
} from "@chakra-ui/react";
15
16
export default function (props: { isOpen: boolean; onClose: () => void }) {
18
if (!props.isOpen) return;
19
20
const evidenceElement = document.getElementById(
22
) as HTMLInputElement;
23
24
if (!evidenceElement.files && e.clipboardData?.files) {
25
evidenceElement.files = e.clipboardData.files;
26
return;
27
}
28
29
if (!evidenceElement.files || !e.clipboardData?.files.length) return;
30
31
if (typeof window["DataTransfer"] === "undefined")
32
return alert("Your browser is too old to paste images in.");
33
34
const dataTransfer = new DataTransfer();
35
36
for (const file of evidenceElement.files) dataTransfer.items.add(file);
37
38
dataTransfer.items.add(e.clipboardData.files[0]);
39
40
evidenceElement.files = dataTransfer.files;
47
(
48
document.getElementById("punishment") as unknown as HTMLSelectElement
49
).selectedIndex = -1;
50
(document.getElementById("user") as HTMLInputElement).value = "";
55
async function submit() {
56
const form = new FormData();
57
const { files } = document.getElementById("evidence") as HTMLInputElement;
58
const punishment = (
59
document.getElementById("punishment") as unknown as HTMLSelectElement
60
).item(0)?.value as string;
61
const { value: user } = document.getElementById("user") as HTMLInputElement;
62
63
form.append("user", user);
64
form.append("punishment", punishment);
65
66
if (files) {
67
for (let i = 0; i < files.length; i++)
68
form.append(`file${i}`, files[i], files[i].name);
69
}
70
71
const postReq = await fetch("/api/infractions/new", {
72
body: form,
73
method: "POST",
74
});
75
76
if (postReq.ok) {
77
useToast()({
78
description: "Infraction created",
79
duration: 5000,
80
isClosable: true,
81
status: "success",
82
title: "Success",
83
});
84
85
props.onClose();
86
87
return;
88
}
89
90
useToast()({
91
description: `Failed to create infraction (${
92
((await postReq.json()) as { error: string }).error
93
})`,
94
duration: 5000,
95
isClosable: true,
96
status: "error",
97
title: "Error",
98
});
99
}
102
<Modal
103
closeOnEsc={false}
104
closeOnOverlayClick={false}
105
isCentered
106
isOpen={props.isOpen}
107
onClose={props.onClose}
108
>
109
<ModalOverlay />
110
<ModalContent>
111
<ModalHeader>New Infraction</ModalHeader>
112
<ModalCloseButton />
113
<ModalBody>
114
<Text>User ID</Text>
115
<Input id="user" placeholder="1234567890987654321" />
116
<br />
117
<br />
118
<Text>Punishment</Text>
119
<Select id="punishment" placeholder="Select punishment">
120
<option value="verbal">Verbal Warning</option>
121
<option value="warn">Warning</option>
122
<option value="mute">Mute</option>
123
<option value="ban_temp">Temporary Ban</option>
124
<option value="ban_perm">Permanent Ban</option>
125
<option value="ban_unappealable">Unappealable Permanent Ban</option>
126
</Select>
127
<br />
128
<br />
129
<Text>Evidence</Text>
142
<Button
143
colorScheme="blue"
144
ml="8px"
145
onClick={async () => await submit()}
146
>
147
Submit
148
</Button>
149
</ModalFooter>