tech-debt: Events module: one home for event code, one upcoming rule, one category list
Back to our planType
tech-debt
Summary
Give everything about events one home in the code, so each rule (what counts as "upcoming", the list of categories) is written once, tested once and used everywhere. Phase 2 (filters, cancelled events, official meetings) is then built in that home.
Problem
Event code is spread over 6 folders: app/(frontend)/events, the events sitemap route, collections/Events, components/EventCard, components/EventsFeed, components/SidebarEvents, heros/EventHero, utilities/eventCategories.ts and the event half of utilities/feeds.ts. The shared paging pieces of feeds.ts (FeedPage, parsePageNumber) move to src/platform/lib/, since platform/ imports no module.
- The "upcoming" rule (date on or after today in the site timezone) is written in 3 files:
utilities/feeds.ts,events/[slug]/page.tsx,posts/[slug]/page.tsx. - Category labels are typed twice: in the collection's select options and in
utilities/eventCategories.ts. - The "next 3 upcoming events" query is copied in two pages.
- The event data shape (
EventCardData) is defined by a UI component and imported by the data layer. components/EventsFeedimports a page's server action fromapp/.
Proposed fix
Create src/modules/events/:
domain/:EventCategory(one list with labels, used by the collection, the UI and later the filters),isUpcoming(date, today), theEventSummaryandEventDetailtypes. Pure TypeScript, unit-tested.data/(server-only):findEventPage(scope, page),findUpcomingEvents({ limit, excludeId }),findEventBySlug(slug, { draft }),listEventSlugs(). They map Payload documents to the module's types.cms/: the Events collection config and its revalidation hook (moved, behavior unchanged).ui/:EventCard,EventsFeed,SidebarEvents,EventHero.actions.ts: the "Load more" server action.index.ts(client-safe types and UI) andserver.ts(queries and actions) as the only entry points.
Event pages under app/ become thin: call @/modules/events/server, render module parts. The posts page gets upcoming events from the same entry point (until the news module exists).
Acceptance criteria
- Not done: No event logic remains outside
src/modules/eventsexcept the thin route files. - Not done:
isUpcomingand the category list each exist exactly once, with unit tests (including the timezone boundary at midnight in America/Chicago). - Not done: Data functions return module types; no
ascasts on Payload results. - Not done:
/events,/events/<slug>,/events/list/<scope>/<page>, the events sitemap and "Load more" behave exactly as before (checked locally, both themes, mobile and desktop). - Not done: Boundary lint reports no violations for the events module.
Depends on
#129 (tests) and #130 (boundary rules); #120 (Next 16) recommended first. Step 6 of #127.
Area
frontend, cms
Priority
high
Generated by Claude Code, opens in a new tab