NGU-Web/src/lib/eventTypes.ts
Zaldimmar 5274e09571 Clean up code found in the audit
- Replace every em-dash in src and server/src with a colon, comma or hyphen
- Give every relative import its file extension (.jsx imports of .tsx fixed)
- Delete old-historyMock.ts, unused exports, unused CSS utilities, the
  unused @ alias and the fallback option nothing passed
- One copy each of initials, capitalize, byName and the server's marks()
- Move the organization, chapter and event hooks from src/data to src/lib
- Schema sync always throws on a mismatch (strict was never turned off)
- Replace the placeholder README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:02:03 -05:00

44 lines
2.1 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
EVENT TYPES
The client half of the CHECK on events.event_type. Order here is
display order: the filter chips read it straight off this array,
so moving a line moves a chip.
What this is not: event_scopes. A scope owns presentation:
Retreats.tsx keys its title, accent and background on the id, so
an unrecognised scope_id makes an event vanish with no error,
which is why that one is a real table with a real foreign key. A
type carries no presentation of its own and an unknown value
renders as its own name, so a CHECK is enough.
Adding a type is three edits: the CHECKs in a migration (on
events.event_type and front_page.countdown_event_type), the enums
in both descriptor halves (the event's type and the front page's
countdown type), and this list. Adding it here alone
means the site offers a filter the database will refuse to store.
═══════════════════════════════════════════════════════════════ */
import { capitalize } from './text.ts'
export type EventType = 'retreat' | 'class' | 'workshop' | 'meeting' | 'other'
export const EVENT_TYPES: { id: EventType; label: string; plural: string }[] = [
{ id: 'retreat', label: 'Retreat', plural: 'Retreats' },
{ id: 'class', label: 'Class', plural: 'Classes' },
{ id: 'workshop', label: 'Workshop', plural: 'Workshops' },
{ id: 'meeting', label: 'Meeting', plural: 'Meetings' },
{ id: 'other', label: 'Other', plural: 'Other' },
]
const BY_ID = new Map<string, { label: string; plural: string }>(
EVENT_TYPES.map((entry) => [entry.id as string, entry]),
)
/* A value the CHECK has gained since this file was written renders
as itself rather than vanishing, the same rule EventDetail's
ROLE_ORDER follows for billing roles. */
export const eventTypeLabel = (id?: string | null): string =>
(id ? BY_ID.get(id)?.label : null) ?? capitalize(id ?? '')