From 2337c8c6533082342575f8e95115d871a7c4277b Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:39 -0400 Subject: [PATCH] Add submission to inactivity notice modal --- components/NewInactivityNotice.tsx | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/components/NewInactivityNotice.tsx b/components/NewInactivityNotice.tsx index df0b53c..93a206a 100644 --- a/components/NewInactivityNotice.tsx +++ b/components/NewInactivityNotice.tsx @@ -1,14 +1,17 @@ import { + Button, Checkbox, CheckboxGroup, Modal, ModalBody, ModalCloseButton, ModalContent, + ModalFooter, ModalHeader, ModalOverlay, Text, Textarea, + useToast, VStack, } from "@chakra-ui/react"; import { useState } from "react"; @@ -32,6 +35,38 @@ export default function (props: { 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 ( @@ -67,6 +102,16 @@ export default function (props: { + + + +