import {
Box,
Button,
Card,
CardBody,
CardFooter,
CardHeader,
Heading,
ListItem,
Stack,
StackDivider,
Text,
UnorderedList,
useToast,
} from "@chakra-ui/react";
import { useState } from "react";
export default function (
props: InactivityNoticeProps & { port?: MessagePort },
) {
const toast = useToast();
const [loading, setLoading] = useState(false);
async function makeDecision(accepted: boolean) {
setLoading(true);
const decisionReq = await fetch(`/api/inactivity/${props.id}`, {
body: JSON.stringify({ accepted }),
headers: {
"content-type": "application/json",
},
method: "POST",
});
if (!decisionReq.ok) {
setLoading(false);
toast({
description: ((await decisionReq.json()) as { error: string }).error,
isClosable: true,
status: "error",
title: "Oops",
});
return;
}
toast({
description: `Inactivity notice ${accepted ? "accepted" : "denied"}.`,
isClosable: true,
status: "success",
title: "Success",
});
setLoading(false);
}
const Approved = () => (
);
const Denied = () => (
);
const Pending = () => (
);
return (
Inactivity Notice for {props.user.username}
ID: {props.user.id}
}>
Reason for Inactivity
{props.reason}
Start Date
{new Date(props.start).toLocaleDateString(undefined, {
timeZone: "utc",
})}
End Date
{new Date(props.end).toLocaleDateString(undefined, {
timeZone: "utc",
})}
{typeof props.hiatus === "boolean" ? (
Notice Type
{props.hiatus ? "Hiatus/Inactivity" : "Activity Decrease"}
) : null}
Decisions
{props.departments.map((d) => {
const dept = d as "ET" | "DM" | "FM" | "WM";
return (
{d}:
{typeof props.decisions[dept] === "boolean" ? (
props.decisions[dept] ? (
) : (
)
) : (
)}
);
})}
);
}