Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add submission to inactivity notice modal
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent aaf37eb commit 2337c8c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions 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";
Expand All @@ -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 (
Expand Down Expand Up @@ -67,6 +102,16 @@ export default function (props: {
</VStack>
</CheckboxGroup>
</ModalBody>
<ModalFooter>
<Button onClick={reset}>Cancel</Button>
<Button
colorScheme="blue"
ml="8px"
onClick={async () => await submit()}
>
Submit
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
Expand Down

0 comments on commit 2337c8c

Please sign in to comment.