Add events member data to me page
This commit is contained in:
parent
b070373231
commit
8df681e520
@ -11,6 +11,7 @@ import {
|
||||
ModalHeader,
|
||||
ModalOverlay,
|
||||
Table,
|
||||
TableCaption,
|
||||
TableContainer,
|
||||
Tbody,
|
||||
Td,
|
||||
@ -44,8 +45,39 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
);
|
||||
|
||||
const settledPromises = await Promise.allSettled(d1Promises);
|
||||
let etData: { [k: string]: any } | null = null;
|
||||
|
||||
if (currentUser.permissions & (1 << 3)) {
|
||||
etData = await context.env.D1.prepare(
|
||||
"SELECT name, points, roblox_id FROM et_members WHERE id = ?;",
|
||||
)
|
||||
.bind(currentUser.id)
|
||||
.first();
|
||||
|
||||
if (etData) {
|
||||
const now = new Date();
|
||||
const pointsData = await context.env.D1.prepare(
|
||||
"SELECT answered_at, approved, day, month, performed_at, reached_minimum_player_count, type, year FROM events WHERE created_by = ? AND month = ? AND year = ?;",
|
||||
)
|
||||
.bind(currentUser.id, now.getUTCMonth(), now.getUTCFullYear())
|
||||
.all();
|
||||
|
||||
for (const row of pointsData.results as Record<string, any>[]) {
|
||||
if (row.performed_at) etData.points += 10;
|
||||
if (row.type === "gamenight" && row.reached_minimum_player_count)
|
||||
etData.points += 10;
|
||||
if (
|
||||
row.type === "rotw" &&
|
||||
row.answered_at - row.performed_at >= 86400000
|
||||
)
|
||||
etData.points += 10;
|
||||
if (!row.performed_at && row.day < now.getUTCDate()) etData.points -= 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
etData,
|
||||
items: settledPromises.map((p) => {
|
||||
if (p.status === "fulfilled") return p.value.results;
|
||||
|
||||
@ -57,6 +89,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
|
||||
export default function () {
|
||||
const data: {
|
||||
etData: { [k: string]: any } | null;
|
||||
items: ({ [k: string]: any }[] | null)[];
|
||||
permissions: number;
|
||||
} = useLoaderData<typeof loader>();
|
||||
@ -237,6 +270,36 @@ export default function () {
|
||||
<Heading mb={8}>My Data</Heading>
|
||||
<br />
|
||||
<br />
|
||||
{data.permissions & (1 << 3) ? (
|
||||
<>
|
||||
<Heading size="lg">Events Team Info</Heading>
|
||||
<TableContainer mb="16px">
|
||||
<Table variant="simple">
|
||||
<TableCaption>
|
||||
Reach out to ETM if this info is incorrect
|
||||
</TableCaption>
|
||||
<Thead>
|
||||
<Tr>
|
||||
<Th>Name</Th>
|
||||
<Th>Points</Th>
|
||||
<Th>Roblox ID</Th>
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody>
|
||||
<Tr>{data.etData?.name}</Tr>
|
||||
<Tr>{data.etData?.points}</Tr>
|
||||
<Tr>
|
||||
<Link
|
||||
href={`https://www.roblox.com/users/${data.etData?.roblox_id}/profile`}
|
||||
>
|
||||
{data.etData?.roblox_id}
|
||||
</Link>
|
||||
</Tr>
|
||||
</Tbody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</>
|
||||
) : null}
|
||||
<Heading size="lg">Discord Appeals</Heading>
|
||||
<TableContainer mb="16px">
|
||||
<Table variant="simple">
|
||||
|
Loading…
x
Reference in New Issue
Block a user