Skip to content
Permalink
Newer
Older
100644 127 lines (118 sloc) 3.57 KB
October 19, 2023 16:50
1
import {
2
Box,
3
Button,
4
Card,
5
CardBody,
6
CardFooter,
7
CardHeader,
8
Heading,
October 19, 2023 16:50
10
Stack,
11
StackDivider,
12
Text,
13
UnorderedList,
October 19, 2023 16:50
14
useToast,
October 19, 2023 16:50
15
} from "@chakra-ui/react";
October 19, 2023 16:50
16
import { useState } from "react";
October 19, 2023 16:50
17
October 19, 2023 16:50
18
export default function (props: InactivityNoticeProps) {
19
const toast = useToast();
October 19, 2023 16:50
20
const [loading, setLoading] = useState(false);
21
22
async function makeDecision(accepted: boolean) {
October 19, 2023 16:50
23
setLoading(true);
October 19, 2023 16:50
24
const decisionReq = await fetch(`/api/inactivity/${props.id}`, {
25
body: JSON.stringify({ accepted }),
26
headers: {
October 19, 2023 16:50
27
"content-type": "application/json",
October 19, 2023 16:50
29
method: "POST",
30
});
31
32
if (!decisionReq.ok) {
October 19, 2023 16:50
33
setLoading(false);
35
description: ((await decisionReq.json()) as { error: string }).error,
36
isClosable: true,
37
status: "error",
October 19, 2023 16:50
38
title: "Oops",
39
});
40
41
return;
42
}
43
44
toast({
45
description: `Inactivity notice ${accepted ? "accepted" : "denied"}.`,
46
isClosable: true,
47
status: "success",
October 19, 2023 16:50
48
title: "Success",
October 19, 2023 16:50
50
October 19, 2023 16:50
51
setLoading(false);
October 19, 2023 16:50
52
location.reload();
55
const Approved = () => (
October 19, 2023 16:50
56
<svg fill="currentColor" height="16" viewBox="0 0 16 16" width="16">
October 19, 2023 16:50
57
<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" />
October 19, 2023 16:50
58
</svg>
61
const Denied = () => (
October 19, 2023 16:50
62
<svg fill="currentColor" height="16" viewBox="0 0 16 16" width="16">
October 19, 2023 16:50
63
<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" />
October 19, 2023 16:50
64
</svg>
October 19, 2023 16:50
67
return (
68
<Card w="100%">
69
<CardHeader>
70
<Heading size="md">Inactivity Notice for {props.user.username}</Heading>
71
<Text fontSize="xs">ID: {props.user.id}</Text>
72
</CardHeader>
73
<CardBody>
74
<Stack divider={<StackDivider />}>
75
<Box>
76
<Heading size="xs">Reason for Inactivity</Heading>
77
<Text>{props.reason}</Text>
78
</Box>
79
<Box>
80
<Heading size="xs">Start Date</Heading>
81
<Text>{new Date(props.start).toLocaleDateString()}</Text>
82
</Box>
83
<Box>
84
<Heading size="xs">End Date</Heading>
85
<Text>{new Date(props.end).toLocaleDateString()}</Text>
86
</Box>
87
{props.decisions ? (
88
<Box>
89
<Heading size="xs">Decisions</Heading>
90
<UnorderedList>
91
{Object.entries(props.decisions).map(([dept, accepted]) => (
92
<ListItem>
October 19, 2023 16:50
93
<Stack alignItems="center" direction="row">
94
<Text>{dept}:&nbsp;</Text>
95
{accepted ? <Approved /> : <Denied />}
October 19, 2023 16:50
96
</Stack>
97
</ListItem>
98
))}
99
</UnorderedList>
100
</Box>
101
) : null}
October 19, 2023 16:50
102
</Stack>
103
</CardBody>
104
<CardFooter pb="4px">
105
<Box>
106
<Button
107
colorScheme="red"
108
onClick={async () => await makeDecision(false)}
October 19, 2023 16:50
109
isLoading={loading}
October 19, 2023 16:50
110
loadingText="Processing..."
111
>
112
Deny
113
</Button>
114
<Button
115
colorScheme="blue"
116
ml="8px"
117
onClick={async () => await makeDecision(true)}
October 19, 2023 16:50
118
isLoading={loading}
October 19, 2023 16:50
119
loadingText="Processing..."
October 19, 2023 16:50
121
Accept
122
</Button>
123
</Box>
124
</CardFooter>
125
</Card>
126
);
127
}