Make submission method for inactivity notice decisions

This commit is contained in:
regalijan 2023-10-19 16:50:49 -04:00
parent 1b89ffaebd
commit 6cb8833b1a
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
2 changed files with 35 additions and 3 deletions

View File

@ -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 = () => <Icon fill="currentColor" height="16" viewBox="0 0 16 16" width="16">
<path
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
@ -57,8 +88,8 @@ export default function(props: InactivityNoticeProps) {
</CardBody>
<CardFooter pb="4px">
<Box>
<Button colorScheme="red">Deny</Button>
<Button colorScheme="blue" ml="8px">
<Button colorScheme="red" onClick={async () => await makeDecision(false)}>Deny</Button>
<Button colorScheme="blue" ml="8px" onClick={async () => await makeDecision(true)}>
Accept
</Button>
</Box>

1
index.d.ts vendored
View File

@ -50,6 +50,7 @@ declare global {
}[];
departments: string[];
end: string;
id: string;
reason: string;
start: string;
user: {