Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make site not brick itself when decisions object exists
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 2fc73a6 commit 5daf23d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
65 changes: 40 additions & 25 deletions components/InactivityNoticeCard.tsx
Expand Up @@ -12,27 +12,27 @@ import {
StackDivider,
Text,
UnorderedList,
useToast
useToast,
} from "@chakra-ui/react";

export default function(props: InactivityNoticeProps) {
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"
"content-type": "application/json",
},
method: "POST"
method: "POST",
});

if (!decisionReq.ok) {
toast({
description: (await decisionReq.json() as { error: string }).error,
description: ((await decisionReq.json()) as { error: string }).error,
isClosable: true,
status: "error",
title: "Oops"
title: "Oops",
});

return;
Expand All @@ -42,21 +42,23 @@ export default function(props: InactivityNoticeProps) {
description: `Inactivity notice ${accepted ? "accepted" : "denied"}.`,
isClosable: true,
status: "success",
title: "Success"
title: "Success",
});

location.reload();
}

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" />
</Icon>;
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" />
</Icon>
);

const Denied = () => <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 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z" />
</Icon>;
const Denied = () => (
<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 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z" />
</Icon>
);

return (
<Card w="100%">
Expand All @@ -78,20 +80,33 @@ export default function(props: InactivityNoticeProps) {
<Heading size="xs">End Date</Heading>
<Text>{new Date(props.end).toLocaleDateString()}</Text>
</Box>
{props.decisions ? <Box>
<Heading size="xs">Decisions</Heading>
<UnorderedList>
{props.decisions.map(decision => <ListItem>
{decision.accepted ? <Approved /> : <Denied />} {decision.department}
</ListItem>)}
</UnorderedList>
</Box> : null}
{props.decisions ? (
<Box>
<Heading size="xs">Decisions</Heading>
<UnorderedList>
{Object.entries(props.decisions).map(([dept, accepted]) => (
<ListItem>
{accepted ? <Approved /> : <Denied />} {dept}
</ListItem>
))}
</UnorderedList>
</Box>
) : null}
</Stack>
</CardBody>
<CardFooter pb="4px">
<Box>
<Button colorScheme="red" onClick={async () => await makeDecision(false)}>Deny</Button>
<Button colorScheme="blue" ml="8px" onClick={async () => await makeDecision(true)}>
<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
8 changes: 5 additions & 3 deletions index.d.ts
Expand Up @@ -45,9 +45,11 @@ declare global {
interface InactivityNoticeProps {
created_at: number;
decisions?: {
accepted: boolean;
department: string;
}[];
DM?: boolean;
ET?: boolean;
FM?: boolean;
WM?: boolean;
};
departments: string[];
end: string;
id: string;
Expand Down

0 comments on commit 5daf23d

Please sign in to comment.