Display status and buttons on event team cards

This commit is contained in:
Regalijan 2024-02-15 13:14:17 -05:00
parent 43b1f1d136
commit 002cc6bb10
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -1,8 +1,11 @@
import { import {
Box, Box,
Button,
Card, Card,
CardBody, CardBody,
CardFooter,
Container, Container,
Flex,
Heading, Heading,
Link, Link,
Stack, Stack,
@ -16,7 +19,7 @@ import { type ReactNode } from "react";
export async function loader({ context }: { context: RequestContext }) { export async function loader({ context }: { context: RequestContext }) {
const now = new Date(); const now = new Date();
const monthEventList = await context.env.D1.prepare( const monthEventList = await context.env.D1.prepare(
"SELECT created_by, day, month, type, year FROM events WHERE month = ? AND year = ?;", "SELECT approved, created_by, day, month, pending, type, year FROM events WHERE month = ? AND year = ?;",
) )
.bind(now.getUTCMonth() + 1, now.getUTCFullYear()) .bind(now.getUTCMonth() + 1, now.getUTCFullYear())
.all(); .all();
@ -26,14 +29,25 @@ export async function loader({ context }: { context: RequestContext }) {
status: 500, status: 500,
}); });
return monthEventList.results; return {
can_approve: Boolean(
[1 << 4, 1 << 12].find((p) => context.data.user.permissions & p),
),
events: monthEventList.results,
};
} }
export default function () { export default function () {
const data: { [k: string]: any }[] = useLoaderData<typeof loader>(); const {
can_approve,
events,
}: {
can_approve: boolean;
events: { [k: string]: any }[];
} = useLoaderData<typeof loader>();
const eventCards: ReactNode[] = []; const eventCards: ReactNode[] = [];
for (const event of data) { for (const event of events) {
eventCards.push( eventCards.push(
<Card w="100%"> <Card w="100%">
<CardBody> <CardBody>
@ -58,6 +72,20 @@ export default function () {
</Box> </Box>
</Stack> </Stack>
</CardBody> </CardBody>
<CardFooter>
<Flex gap="16px">
{can_approve && event.pending ? (
<>
<Button colorScheme="red">Deny</Button>
<Button colorScheme="blue">Approve</Button>
</>
) : null}
</Flex>
<Text alignSelf="center" fontSize="sm">
Status:{" "}
{event.pending ? "Pending" : event.approved ? "Approved" : "Denied"}
</Text>
</CardFooter>
</Card>, </Card>,
); );
} }