Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add finalize report button
  • Loading branch information
regalijan committed Nov 7, 2024
1 parent 5ca52a9 commit 231ae73
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/routes/events-team_.report.tsx
@@ -1,4 +1,5 @@
import {
Button,
Container,
Heading,
Table,
Expand All @@ -11,6 +12,7 @@ import {
Tr,
} from "@chakra-ui/react";
import { useLoaderData } from "@remix-run/react";
import { useState } from "react";

export async function loader({ context }: { context: RequestContext }) {
const { current_user: user } = context.data;
Expand Down Expand Up @@ -82,13 +84,27 @@ export async function loader({ context }: { context: RequestContext }) {
)
memberMap[member].points -= 30;

return memberMap;
const date = new Date();
const reportFinalizationKey = await context.env.DATA.get(
`reportfinalized_${date.getUTCFullYear()}-${date.getUTCMonth() + 1}`,
);

return {
can_finalize: typeof reportFinalizationKey !== "undefined",
members: memberMap,
};
}

export default function () {
const data = useLoaderData<typeof loader>() as {
[k: string]: { name: string; points: number; roblox_id?: number };
can_finalize: boolean;
members: {
[k: string]: { name: string; points: number; roblox_id?: number };
};
};
const [showFinalizeButton, setShowFinalizeButton] = useState(
data.can_finalize,
);
const now = new Date();
let month = now.getUTCMonth();
let year = now.getUTCFullYear();
Expand Down Expand Up @@ -117,7 +133,7 @@ export default function () {
</Tr>
</Thead>
<Tbody>
{Object.entries(data).map(([key, value]) => (
{Object.entries(data.members).map(([key, value]) => (
<Tr>
<Td>{key}</Td>
<Td>{value.name}</Td>
Expand All @@ -128,6 +144,7 @@ export default function () {
</Tbody>
</Table>
</TableContainer>
<Button disabled={!showFinalizeButton}>Finalize Report</Button>
</Container>
);
}

0 comments on commit 231ae73

Please sign in to comment.