Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add option for filing hiatuses
  • Loading branch information
regalijan committed Nov 4, 2023
1 parent daace88 commit 4ddf797
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions components/NewInactivityNotice.tsx
Expand Up @@ -2,13 +2,16 @@ import {
Button,
Checkbox,
CheckboxGroup,
HStack,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Radio,
RadioGroup,
Text,
Textarea,
useToast,
Expand All @@ -23,6 +26,7 @@ export default function (props: {
}) {
const [departments, setDepartments] = useState([] as string[]);
const [loading, setLoading] = useState(false);
const [isHiatus, setIsHiatus] = useState(false);
const toast = useToast();

function reset() {
Expand Down Expand Up @@ -55,6 +59,7 @@ export default function (props: {
body: JSON.stringify({
departments,
end,
hiatus: departments.includes("DM") ? isHiatus : undefined,
reason,
start,
}),
Expand Down Expand Up @@ -122,6 +127,20 @@ export default function (props: {
))}
</VStack>
</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>
<ModalFooter>
<Button onClick={reset}>Cancel</Button>
Expand Down
5 changes: 4 additions & 1 deletion functions/api/inactivity/new.ts
@@ -1,11 +1,13 @@
import validateInactivity from "./validate.js";

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(
departments,
end,
hiatus,
reason,
start,
context.data.departments,
Expand All @@ -25,6 +27,7 @@ export async function onRequestPost(context: RequestContext) {
departments,
end,
fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined,
hiatus,
open: true,
reason,
start,
Expand Down
7 changes: 7 additions & 0 deletions functions/api/inactivity/validate.ts
Expand Up @@ -3,6 +3,7 @@ import { jsonError } from "../../common.js";
export default function (
selectedDepartments: string[],
end: any,
hiatus: any,
reason: any,
start: any,
userDepartments?: string[],
Expand All @@ -28,6 +29,12 @@ export default function (
const now = new Date();
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 (
isNaN(endDate.getFullYear()) ||
isNaN(startDate.getFullYear()) ||
Expand Down

0 comments on commit 4ddf797

Please sign in to comment.