Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add actual delete button to inactivity info modal
  • Loading branch information
regalijan committed Mar 16, 2025
1 parent 6730b87 commit 08b36c0
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions app/routes/inactivities.tsx
Expand Up @@ -7,6 +7,7 @@ import {
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Table,
Expand Down Expand Up @@ -69,19 +70,22 @@ export async function loader({ context }: { context: RequestContext }) {
results[i].user = JSON.parse(results[i].user as string);
}

return results.filter((row) => {
const decisionValues = Object.values(
row.decisions as { [k: string]: boolean },
);

return decisionValues.find((d) => d);
}) as unknown as {
decisions: { [k: string]: boolean };
end: string;
id: string;
start: string;
user: { email?: string; id: string; username: string };
}[];
return {
can_delete: currentUser.permissions & (1 << 0),
results: results.filter((row) => {
const decisionValues = Object.values(
row.decisions as { [k: string]: boolean },
);

return decisionValues.find((d) => d);
}) as unknown as {
decisions: { [k: string]: boolean };
end: string;
id: string;
start: string;
user: { email?: string; id: string; username: string };
}[],
};
}

export default function () {
Expand Down Expand Up @@ -115,6 +119,35 @@ export default function () {
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 (
<Container maxW="container.lg">
<Modal isOpen={isOpen} onClose={onClose}>
Expand Down Expand Up @@ -153,6 +186,11 @@ export default function () {
</ListItem>
</UnorderedList>
</ModalBody>
{data.can_delete ? (
<ModalFooter>
<Button colorScheme="red">Delete</Button>
</ModalFooter>
) : null}
</ModalContent>
</Modal>
<Heading pb="32px">Current Inactivity Notices</Heading>
Expand All @@ -171,7 +209,7 @@ export default function () {
</Tr>
</Thead>
<Tbody>
{data.map((row) => (
{data.results.map((row) => (
<Tr key={row.id}>
<Td>{row.user.username}</Td>
<Td>{row.user.id}</Td>
Expand Down

0 comments on commit 08b36c0

Please sign in to comment.