Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make submission method for inactivity notice decisions
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 1b89ffa commit 6cb8833
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
37 changes: 34 additions & 3 deletions components/InactivityNoticeCard.tsx
Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Expand Up @@ -50,6 +50,7 @@ declare global {
}[];
departments: string[];
end: string;
id: string;
reason: string;
start: string;
user: {
Expand Down

0 comments on commit 6cb8833

Please sign in to comment.