From aec7a29d28270a3b7e44d68ead0e2f405c3e6083 Mon Sep 17 00:00:00 2001 From: Joshua Silva <72359611+joshuasilva414@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:33:35 -0500 Subject: [PATCH] Add event location (#124) * add event location * Prettier format --- .../src/app/api/admin/events/create/route.ts | 1 + .../components/events/admin/EventDetails.tsx | 5 ++++ .../components/events/admin/NewEventForm.tsx | 26 +++++++++++++++++-- .../components/events/shared/EventColumns.tsx | 5 ++++ apps/web/src/lib/types/events.ts | 2 +- apps/web/src/validators/event.ts | 1 + packages/db/functions/events.ts | 6 ++--- packages/db/schema.ts | 6 ++--- 8 files changed, 42 insertions(+), 10 deletions(-) diff --git a/apps/web/src/app/api/admin/events/create/route.ts b/apps/web/src/app/api/admin/events/create/route.ts index 6c345aab..14f2fab5 100644 --- a/apps/web/src/app/api/admin/events/create/route.ts +++ b/apps/web/src/app/api/admin/events/create/route.ts @@ -37,6 +37,7 @@ export async function POST(req: Request) { description: parsedBody.data.description, startTime: parsedBody.data.startTime, endTime: parsedBody.data.endTime, + location: parsedBody.data.location, type: parsedBody.data.type, host: parsedBody.data.host && parsedBody.data.host.length > 0 diff --git a/apps/web/src/components/events/admin/EventDetails.tsx b/apps/web/src/components/events/admin/EventDetails.tsx index 1bbeed20..a551b14a 100644 --- a/apps/web/src/components/events/admin/EventDetails.tsx +++ b/apps/web/src/components/events/admin/EventDetails.tsx @@ -52,6 +52,11 @@ export default function EventFull({ event }: { event: Event }) {

Hosted by {event.host}

+

+ Location:{" "} + {event.location} +

+

Description:

{event.description} diff --git a/apps/web/src/components/events/admin/NewEventForm.tsx b/apps/web/src/components/events/admin/NewEventForm.tsx index 290477ad..7f6aba47 100644 --- a/apps/web/src/components/events/admin/NewEventForm.tsx +++ b/apps/web/src/components/events/admin/NewEventForm.tsx @@ -48,6 +48,8 @@ export default function NewEventForm({ defaultDate }: NewEventFormProps) { type: "" as any, host: "", startTime: defaultDate, + points: 0, + location: "TBD", endTime: new Date(defaultDate.getTime() + ONE_HOUR_IN_MILLISECONDS), }, }); @@ -92,6 +94,7 @@ export default function NewEventForm({ defaultDate }: NewEventFormProps) { )} /> + )} /> + ( + + Location + + + + {/* + Keep title short and concise + */} + + + )} + />

Event Start { - const newDate = !!date + const newDate = date ? date.toDate(userLocalTimeZone) : null; field.onChange(newDate); diff --git a/apps/web/src/components/events/shared/EventColumns.tsx b/apps/web/src/components/events/shared/EventColumns.tsx index 48a3500b..7a9b5751 100644 --- a/apps/web/src/components/events/shared/EventColumns.tsx +++ b/apps/web/src/components/events/shared/EventColumns.tsx @@ -29,6 +29,11 @@ export const columns: ColumnDef[] = [ ), }, + { + accessorKey: "location", + header: "Location", + cell: ({ row }) => {row.original.location}, + }, { accessorKey: "startTime", header: "Start", diff --git a/apps/web/src/lib/types/events.ts b/apps/web/src/lib/types/events.ts index 010aa1a5..885e671e 100644 --- a/apps/web/src/lib/types/events.ts +++ b/apps/web/src/lib/types/events.ts @@ -8,7 +8,7 @@ export interface EventType extends InferSelectModel {} export type eventTableValidatorType = Pick< z.infer, - "title" | "startTime" | "endTime" | "id" | "type" + "title" | "location" | "startTime" | "endTime" | "id" | "type" >; export interface NewEventFormProps { diff --git a/apps/web/src/validators/event.ts b/apps/web/src/validators/event.ts index ce5dbc53..44e39023 100644 --- a/apps/web/src/validators/event.ts +++ b/apps/web/src/validators/event.ts @@ -7,6 +7,7 @@ import c from "config"; export const newEventFormSchema = createInsertSchema(events, { title: z.string().min(1), description: z.string().min(1), + location: z.string().min(1), startTime: z.date(), endTime: z.date(), host: z.string().optional(), diff --git a/packages/db/functions/events.ts b/packages/db/functions/events.ts index a1b571a9..908c2ac2 100644 --- a/packages/db/functions/events.ts +++ b/packages/db/functions/events.ts @@ -18,9 +18,9 @@ export function createNewEvent(event: eventInsertType) { export function getAllEvents(options?: getAllEventsOptions) { const orderByClause = options?.descending - ? [desc(events.startTime)] - : [asc(events.startTime)] - + ? [desc(events.startTime)] + : [asc(events.startTime)]; + return db.query.events.findMany({ orderBy: orderByClause, }); diff --git a/packages/db/schema.ts b/packages/db/schema.ts index 02f79c5c..c326c277 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -159,10 +159,8 @@ export const events = pgTable("events", { title: varchar("name", { length: 255 }).notNull(), startTime: timestamp("start_time").notNull(), endTime: timestamp("end_time").notNull(), - // checkinStartTime: timestamp("checkin_start_time").notNull(), - // checkinEndTime: timestamp("checkin_end_time").notNull(), - // location: varchar("location", { length: 255 }).notNull(), - // points: integer("points").notNull().default(0), + location: varchar("location", { length: 255 }).default("TBD"), + points: integer("points").notNull().default(0), description: text("description").notNull(), type: varchar("type", { length: 50 }).notNull(), host: varchar("host", { length: 255 }),