More events team nonsense
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
||||
import { useLoaderData } from "@remix-run/react";
|
||||
import { useState } from "react";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
import { EtMember } from "../../generated/prisma/client.js";
|
||||
|
||||
export const links: LinksFunction = () => {
|
||||
return [
|
||||
@@ -56,18 +57,31 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
const eventsData = await context.env.D1.prepare(
|
||||
"SELECT answer, approved, created_by, day, details, id, month, pending, performed_at, reached_minimum_player_count, type, year FROM events WHERE month = ? AND year = ? ORDER BY day;",
|
||||
)
|
||||
.bind(now.getUTCMonth() + 1, now.getUTCFullYear())
|
||||
.all();
|
||||
const eventsData = await context.data.prisma.event.findMany({
|
||||
orderBy: {
|
||||
day: "asc",
|
||||
},
|
||||
select: {
|
||||
answer: true,
|
||||
approved: true,
|
||||
created_by: true,
|
||||
day: true,
|
||||
details: true,
|
||||
id: true,
|
||||
month: true,
|
||||
pending: true,
|
||||
performed_at: true,
|
||||
reached_minimum_player_count: true,
|
||||
type: true,
|
||||
year: true,
|
||||
},
|
||||
where: {
|
||||
month: now.getUTCMonth() + 1,
|
||||
year: now.getUTCFullYear(),
|
||||
},
|
||||
});
|
||||
|
||||
if (eventsData.error)
|
||||
throw new Response(null, {
|
||||
status: 500,
|
||||
});
|
||||
|
||||
const calendarData = eventsData.results.map((e) => {
|
||||
const calendarData = eventsData.map((e) => {
|
||||
return {
|
||||
id: e.id,
|
||||
title: (e.type as string).toUpperCase(),
|
||||
@@ -78,19 +92,17 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
};
|
||||
});
|
||||
|
||||
const memberData = await context.env.D1.prepare(
|
||||
"SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ? AND year = ?);",
|
||||
)
|
||||
.bind(now.getUTCMonth() + 1, now.getUTCFullYear())
|
||||
.all();
|
||||
const memberData = await context.data.prisma.$queryRaw<
|
||||
EtMember[]
|
||||
>`SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ${now.getUTCMonth() + 1} AND year = ${now.getUTCFullYear()});`;
|
||||
|
||||
return {
|
||||
calendarData,
|
||||
canManage: Boolean(
|
||||
[1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p),
|
||||
),
|
||||
eventList: eventsData.results,
|
||||
memberData: memberData.results,
|
||||
eventList: eventsData,
|
||||
memberData,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,15 +123,7 @@ export default function () {
|
||||
<ModalBody>
|
||||
<Heading size="md">Host</Heading>
|
||||
<Text>
|
||||
{
|
||||
(
|
||||
data.memberData.find(
|
||||
(m) => m.id === eventData.created_by,
|
||||
) as {
|
||||
[k: string]: any;
|
||||
}
|
||||
)?.name
|
||||
}
|
||||
{data.memberData.find((m) => m.id === eventData.created_by)?.name}
|
||||
</Text>
|
||||
<br />
|
||||
<Heading size="md">Event Type</Heading>
|
||||
|
||||
Reference in New Issue
Block a user