import { Button, Checkbox, CheckboxGroup, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, Textarea, useToast, VStack, } from "@chakra-ui/react"; import { useState } from "react"; export default function (props: { departments: string[]; isOpen: boolean; onClose: () => void; }) { const [departments, setDepartments] = useState([] as string[]); function reset() { (document.getElementById("start") as HTMLInputElement).value = ""; (document.getElementById("end") as HTMLInputElement).value = ""; (document.getElementById("reason") as HTMLTextAreaElement).value = ""; props.onClose(); } async function submit() { const start = (document.getElementById("start") as HTMLInputElement).value; const end = (document.getElementById("start") as HTMLInputElement).value; const reason = (document.getElementById("reason") as HTMLTextAreaElement) .value; if (!departments.length) return alert("You need to select at least one department!"); const inactivityPost = await fetch("/api/inactivity/new", { body: JSON.stringify({ end, reason, start, }), headers: { "content-type": "application/json", }, method: "POST", }); if (!inactivityPost.ok) return useToast()({ description: ((await inactivityPost.json()) as { error: string }).error, duration: 10000, isClosable: true, status: "error", title: "Error", }); useToast()({ description: "Your inactivity notice has been created", duration: 10000, isClosable: true, status: "success", title: "Success", }); } return ( <> New Inactivity Notice Start Date

End Date

Reason