Add option for filing hiatuses

This commit is contained in:
Regalijan 2023-11-04 13:40:02 -04:00
parent daace88cf9
commit 4ddf797cc2
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
3 changed files with 30 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import {
Button, Button,
Checkbox, Checkbox,
CheckboxGroup, CheckboxGroup,
HStack,
Modal, Modal,
ModalBody, ModalBody,
ModalCloseButton, ModalCloseButton,
@ -9,6 +10,8 @@ import {
ModalFooter, ModalFooter,
ModalHeader, ModalHeader,
ModalOverlay, ModalOverlay,
Radio,
RadioGroup,
Text, Text,
Textarea, Textarea,
useToast, useToast,
@ -23,6 +26,7 @@ export default function (props: {
}) { }) {
const [departments, setDepartments] = useState([] as string[]); const [departments, setDepartments] = useState([] as string[]);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [isHiatus, setIsHiatus] = useState(false);
const toast = useToast(); const toast = useToast();
function reset() { function reset() {
@ -55,6 +59,7 @@ export default function (props: {
body: JSON.stringify({ body: JSON.stringify({
departments, departments,
end, end,
hiatus: departments.includes("DM") ? isHiatus : undefined,
reason, reason,
start, start,
}), }),
@ -122,6 +127,20 @@ export default function (props: {
))} ))}
</VStack> </VStack>
</CheckboxGroup> </CheckboxGroup>
<RadioGroup
onChange={(v) => setIsHiatus(JSON.parse(v))}
style={{
display: departments.includes("DM") ? undefined : "none",
}}
value={JSON.stringify(isHiatus)}
>
<br />
<br />
<HStack>
<Radio value="false">Inactivity</Radio>
<Radio value="true">Hiatus</Radio>
</HStack>
</RadioGroup>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button onClick={reset}>Cancel</Button> <Button onClick={reset}>Cancel</Button>

View File

@ -1,11 +1,13 @@
import validateInactivity from "./validate.js"; import validateInactivity from "./validate.js";
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { departments, end, reason, senderTokenId, start } = context.data.body; const { departments, end, hiatus, reason, senderTokenId, start } =
context.data.body;
const validationFailureResponse = validateInactivity( const validationFailureResponse = validateInactivity(
departments, departments,
end, end,
hiatus,
reason, reason,
start, start,
context.data.departments, context.data.departments,
@ -25,6 +27,7 @@ export async function onRequestPost(context: RequestContext) {
departments, departments,
end, end,
fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined, fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined,
hiatus,
open: true, open: true,
reason, reason,
start, start,

View File

@ -3,6 +3,7 @@ import { jsonError } from "../../common.js";
export default function ( export default function (
selectedDepartments: string[], selectedDepartments: string[],
end: any, end: any,
hiatus: any,
reason: any, reason: any,
start: any, start: any,
userDepartments?: string[], userDepartments?: string[],
@ -28,6 +29,12 @@ export default function (
const now = new Date(); const now = new Date();
const startDate = new Date(start); const startDate = new Date(start);
if (typeof hiatus !== "undefined" && typeof hiatus !== "boolean")
return jsonError("Invalid notice", 400);
if (!selectedDepartments.includes("DM") && hiatus)
return jsonError("Only discord mods can file hiatuses", 400);
if ( if (
isNaN(endDate.getFullYear()) || isNaN(endDate.getFullYear()) ||
isNaN(startDate.getFullYear()) || isNaN(startDate.getFullYear()) ||