Add finalize report button
This commit is contained in:
parent
5ca52a9be4
commit
231ae733e7
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Button,
|
||||||
Container,
|
Container,
|
||||||
Heading,
|
Heading,
|
||||||
Table,
|
Table,
|
||||||
@ -11,6 +12,7 @@ import {
|
|||||||
Tr,
|
Tr,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useLoaderData } from "@remix-run/react";
|
import { useLoaderData } from "@remix-run/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export async function loader({ context }: { context: RequestContext }) {
|
export async function loader({ context }: { context: RequestContext }) {
|
||||||
const { current_user: user } = context.data;
|
const { current_user: user } = context.data;
|
||||||
@ -82,13 +84,27 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
)
|
)
|
||||||
memberMap[member].points -= 30;
|
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 () {
|
export default function () {
|
||||||
const data = useLoaderData<typeof loader>() as {
|
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();
|
const now = new Date();
|
||||||
let month = now.getUTCMonth();
|
let month = now.getUTCMonth();
|
||||||
let year = now.getUTCFullYear();
|
let year = now.getUTCFullYear();
|
||||||
@ -117,7 +133,7 @@ export default function () {
|
|||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{Object.entries(data).map(([key, value]) => (
|
{Object.entries(data.members).map(([key, value]) => (
|
||||||
<Tr>
|
<Tr>
|
||||||
<Td>{key}</Td>
|
<Td>{key}</Td>
|
||||||
<Td>{value.name}</Td>
|
<Td>{value.name}</Td>
|
||||||
@ -128,6 +144,7 @@ export default function () {
|
|||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
<Button disabled={!showFinalizeButton}>Finalize Report</Button>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user