From 6cb8833b1a43c9a134ac7a6f9aaf15c92b57cb93 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:49 -0400 Subject: [PATCH] Make submission method for inactivity notice decisions --- components/InactivityNoticeCard.tsx | 37 ++++++++++++++++++++++++++--- index.d.ts | 1 + 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/components/InactivityNoticeCard.tsx b/components/InactivityNoticeCard.tsx index 2302ffc..639ee37 100644 --- a/components/InactivityNoticeCard.tsx +++ b/components/InactivityNoticeCard.tsx @@ -11,10 +11,41 @@ import { Stack, StackDivider, Text, - UnorderedList + UnorderedList, + useToast } from "@chakra-ui/react"; export default function(props: InactivityNoticeProps) { + const toast = useToast(); + + async function makeDecision(accepted: boolean) { + const decisionReq = await fetch(`\`/api/inactivity/${props.id}`, { + body: JSON.stringify({ accepted }), + headers: { + "content-type": "application/json" + }, + method: "POST" + }); + + if (!decisionReq.ok) { + 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" + }); + } + const Approved = () => @@ -57,8 +88,8 @@ export default function(props: InactivityNoticeProps) { - - + diff --git a/index.d.ts b/index.d.ts index faba9cb..b1ac60e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -50,6 +50,7 @@ declare global { }[]; departments: string[]; end: string; + id: string; reason: string; start: string; user: {