diff --git a/app/routes/inactivities.tsx b/app/routes/inactivities.tsx index dc4ade6..a8f70d2 100644 --- a/app/routes/inactivities.tsx +++ b/app/routes/inactivities.tsx @@ -7,6 +7,7 @@ import { ModalBody, ModalCloseButton, ModalContent, + ModalFooter, ModalHeader, ModalOverlay, Table, @@ -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 () { @@ -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 ( @@ -153,6 +186,11 @@ export default function () { + {data.can_delete ? ( + + + + ) : null} Current Inactivity Notices @@ -171,7 +209,7 @@ export default function () { - {data.map((row) => ( + {data.results.map((row) => ( {row.user.username} {row.user.id}