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); props.port?.postMessage(`inactivity_${props.id}`); } const Approved = () => ( ); const Denied = () => ( ); return ( Inactivity Notice for {props.user.username} ID: {props.user.id} }> Reason for Inactivity {props.reason} Start Date {new Date(props.start).toLocaleDateString()} End Date {new Date(props.end).toLocaleDateString()} {typeof props.hiatus === "boolean" ? ( Notice Type {props.hiatus ? "Hiatus/Inactivity" : "Activity Decrease"} ) : null} {props.decisions ? ( Decisions {Object.entries(props.decisions).map(([dept, accepted]) => ( {dept}:  {accepted ? : } ))} ) : null} ); }