Add actual delete button to inactivity info modal
This commit is contained in:
parent
6730b876bf
commit
08b36c04b8
@ -7,6 +7,7 @@ import {
|
|||||||
ModalBody,
|
ModalBody,
|
||||||
ModalCloseButton,
|
ModalCloseButton,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
|
ModalFooter,
|
||||||
ModalHeader,
|
ModalHeader,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
Table,
|
Table,
|
||||||
@ -69,19 +70,22 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
results[i].user = JSON.parse(results[i].user as string);
|
results[i].user = JSON.parse(results[i].user as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
return results.filter((row) => {
|
return {
|
||||||
const decisionValues = Object.values(
|
can_delete: currentUser.permissions & (1 << 0),
|
||||||
row.decisions as { [k: string]: boolean },
|
results: results.filter((row) => {
|
||||||
);
|
const decisionValues = Object.values(
|
||||||
|
row.decisions as { [k: string]: boolean },
|
||||||
|
);
|
||||||
|
|
||||||
return decisionValues.find((d) => d);
|
return decisionValues.find((d) => d);
|
||||||
}) as unknown as {
|
}) as unknown as {
|
||||||
decisions: { [k: string]: boolean };
|
decisions: { [k: string]: boolean };
|
||||||
end: string;
|
end: string;
|
||||||
id: string;
|
id: string;
|
||||||
start: string;
|
start: string;
|
||||||
user: { email?: string; id: string; username: string };
|
user: { email?: string; id: string; username: string };
|
||||||
}[];
|
}[],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
@ -115,6 +119,35 @@ export default function () {
|
|||||||
onOpen();
|
onOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteInactivity(id: string) {
|
||||||
|
const response = await fetch(`/api/inactivity/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
onClose();
|
||||||
|
setInactivity({});
|
||||||
|
toast({
|
||||||
|
status: "success",
|
||||||
|
title: "Notice Deleted",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let msg = "Unknown error";
|
||||||
|
|
||||||
|
try {
|
||||||
|
msg = ((await response.json()) as { error: string }).error;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
description: msg,
|
||||||
|
status: "error",
|
||||||
|
title: "Failed to Delete",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxW="container.lg">
|
<Container maxW="container.lg">
|
||||||
<Modal isOpen={isOpen} onClose={onClose}>
|
<Modal isOpen={isOpen} onClose={onClose}>
|
||||||
@ -153,6 +186,11 @@ export default function () {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
</UnorderedList>
|
</UnorderedList>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
{data.can_delete ? (
|
||||||
|
<ModalFooter>
|
||||||
|
<Button colorScheme="red">Delete</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
) : null}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
<Heading pb="32px">Current Inactivity Notices</Heading>
|
<Heading pb="32px">Current Inactivity Notices</Heading>
|
||||||
@ -171,7 +209,7 @@ export default function () {
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{data.map((row) => (
|
{data.results.map((row) => (
|
||||||
<Tr key={row.id}>
|
<Tr key={row.id}>
|
||||||
<Td>{row.user.username}</Td>
|
<Td>{row.user.username}</Td>
|
||||||
<Td>{row.user.id}</Td>
|
<Td>{row.user.id}</Td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user