Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Generally fix up inactivity notices
  • Loading branch information
regalijan committed Nov 5, 2023
1 parent 908c8b7 commit e4a0bb4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
69 changes: 45 additions & 24 deletions components/NewInactivityNotice.tsx
Expand Up @@ -26,23 +26,22 @@ export default function (props: {
}) {
const [departments, setDepartments] = useState([] as string[]);
const [loading, setLoading] = useState(false);
const [start, setStart] = useState("");
const [end, setEnd] = useState("");
const [reason, setReason] = useState("");
const [isHiatus, setIsHiatus] = useState(false);
const toast = useToast();

function reset() {
(document.getElementById("start") as HTMLInputElement).value = "";
(document.getElementById("end") as HTMLInputElement).value = "";
(document.getElementById("reason") as HTMLTextAreaElement).value = "";
setEnd("");
setReason("");
setStart("");

props.onClose();
}

async function submit() {
setLoading(true);
const start = (document.getElementById("start") as HTMLInputElement).value;
const end = (document.getElementById("end") as HTMLInputElement).value;
const reason = (document.getElementById("reason") as HTMLTextAreaElement)
.value;

if (!departments.length) {
toast({
Expand All @@ -55,6 +54,17 @@ export default function (props: {
return;
}

if (!start || !end || !reason) {
toast({
description: "One or more fields are missing",
status: "error",
title: "Validation Error",
});

setLoading(false);
return;
}

const inactivityPost = await fetch("/api/inactivity/new", {
body: JSON.stringify({
departments,
Expand Down Expand Up @@ -90,7 +100,7 @@ export default function (props: {
title: "Success",
});

setLoading(true);
setLoading(false);
props.onClose();
}

Expand All @@ -103,16 +113,26 @@ export default function (props: {
<ModalCloseButton />
<ModalBody>
<Text>Start Date</Text>
<input id="start" type="date" />
<input
id="start"
onChange={(e) => setStart(e.target.value)}
type="date"
/>
<br />
<br />
<Text>End Date</Text>
<input id="end" type="date" />
<input
id="end"
onChange={(e) => setEnd(e.target.value)}
type="date"
/>
<br />
<br />
<Text>Reason</Text>
<Textarea
id="reason"
maxLength={500}
onChange={(e) => setReason(e.target.value)}
placeholder="Your reason for making this inactivity notice"
/>
<br />
Expand All @@ -127,20 +147,21 @@ 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>
{departments.includes("DM") ? (
<>
<br />
<br />
<RadioGroup
onChange={(v) => setIsHiatus(JSON.parse(v))}
value={JSON.stringify(isHiatus)}
>
<HStack>
<Radio value="false">Inactivity</Radio>
<Radio value="true">Hiatus</Radio>
</HStack>
</RadioGroup>
</>
) : null}
</ModalBody>
<ModalFooter>
<Button onClick={reset}>Cancel</Button>
Expand Down
4 changes: 2 additions & 2 deletions functions/api/inactivity/[id].ts
Expand Up @@ -67,7 +67,7 @@ export async function onRequestPost(context: RequestContext) {
if (Object.values(decisions).length === requestedNotice.departments.length) {
requestedNotice.open = false;

const approved = !Object.values(decisions).find((d) => !d);
const approved = !Object.values(decisions).filter((d) => !d).length;

await context.env.D1.prepare(
"UPDATE inactivity_notices SET approved = ?, open = 0 WHERE id = ?;",
Expand All @@ -81,7 +81,7 @@ export async function onRequestPost(context: RequestContext) {
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
accepted
? "Your inactivity request was approved."
: "Your inactivity request was denied, please reach to management if you require more details.",
: "Your inactivity request was denied, please reach out to management if you require more details.",
requestedNotice.fcm_token,
);
} else {
Expand Down

0 comments on commit e4a0bb4

Please sign in to comment.