diff --git a/app/routes/book-event.tsx b/app/routes/book-event.tsx index 3bd7f41..828cdae 100644 --- a/app/routes/book-event.tsx +++ b/app/routes/book-event.tsx @@ -1,4 +1,8 @@ import { + Alert, + AlertDescription, + AlertIcon, + AlertTitle, Button, Container, Heading, @@ -28,11 +32,23 @@ export async function loader({ context }: { context: RequestContext }) { status: 403, }); - return null; + const now = new Date(); + const preBookedEvents = await context.data.prisma.event.count({ + where: { + created_by: context.data.current_user.id, + day: { + gte: now.getUTCDate(), + }, + month: now.getUTCMonth() + 1, + year: now.getUTCFullYear(), + }, + }); + + return preBookedEvents >= 3; } export default function () { - useLoaderData(); + const exceededMaxBookings = useLoaderData(); const toast = useToast(); const currentDate = new Date(); @@ -44,7 +60,7 @@ export default function () { const [eventType, setEventType] = useState(""); const [riddleAnswer, setRiddleAnswer] = useState(""); const [submitSuccess, setSubmitSuccess] = useState(false); - const [disableSubmit, setDisableSubmit] = useState(false); + const [disableSubmit, setDisableSubmit] = useState(exceededMaxBookings); useEffect(() => { setDatePickerMin(`${new Date().toISOString().split("T").at(0)}`); @@ -112,6 +128,14 @@ export default function () { /> ) : ( + + + Max pre-bookings exceeded! + + You cannot pre-book more than three events. Please wait until you + complete an event before trying again. + + Book an Event Event Type diff --git a/app/routes/events-team_.report.tsx b/app/routes/events-team_.report.tsx index a285fe4..cdc4437 100644 --- a/app/routes/events-team_.report.tsx +++ b/app/routes/events-team_.report.tsx @@ -136,11 +136,11 @@ export default function () { my="16px" onClick={async () => { await navigator.clipboard.writeText( - `local Report = { + `\`\`\`\nlocal Report = { ${Object.values(data.members) .map((v) => `[${v.roblox_id}] = ${v.points};`) .join("\n ")} -}`, +}\n\`\`\``, ); alert("Report copied."); diff --git a/functions/api/events-team/events/new.ts b/functions/api/events-team/events/new.ts index a5e689a..48b7b9c 100644 --- a/functions/api/events-team/events/new.ts +++ b/functions/api/events-team/events/new.ts @@ -21,8 +21,24 @@ export async function onRequestPost(context: RequestContext) { ) return jsonError("Invalid body", 400); + const { prisma } = context.data; + if ( - await context.data.prisma.event.findFirst({ + (await prisma.event.count({ + where: { + created_by: context.data.current_user.id, + day: { + gte: now.getUTCDate(), + }, + month: currentMonth, + year: currentYear, + }, + })) >= 3 + ) + return jsonError("Too many events scheduled", 403); + + if ( + await prisma.event.findFirst({ select: { id: true, }, @@ -51,7 +67,7 @@ export async function onRequestPost(context: RequestContext) { const weekRange = Math.floor(day / 7); - const existingEventInRange = await context.data.prisma.event.findFirst({ + const existingEventInRange = await prisma.event.findFirst({ select: { id: true, }, @@ -73,7 +89,7 @@ export async function onRequestPost(context: RequestContext) { const id = `${now.getTime()}${crypto.randomUUID().replaceAll("-", "")}`; - await context.data.prisma.event.create({ + await prisma.event.create({ data: { answer: context.data.body.answer || null, approved: type === "gamenight", diff --git a/functions/api/events-team/strikes/new.ts b/functions/api/events-team/strikes/new.ts index 417b661..dc98e8d 100644 --- a/functions/api/events-team/strikes/new.ts +++ b/functions/api/events-team/strikes/new.ts @@ -19,14 +19,13 @@ export async function onRequestPost(context: RequestContext) { ) return jsonError("Invalid user id", 400); - const now = Date.now(); const id = crypto.randomUUID().replaceAll("-", ""); const actingUser = context.data.current_user.id; await D1.batch([ D1.prepare( - "INSERT INTO et_strikes (created_at, created_by, id, reason, user) VALUES (?, ?, ?, ?, ?);", - ).bind(now, actingUser, id, reason, user), + "INSERT INTO et_strikes (created_by, id, reason, user) VALUES (?, ?, ?, ?);", + ).bind(actingUser, id, reason, user), D1.prepare( "UPDATE et_members SET points = points - 100 WHERE id = ?;", ).bind(user),