import { getMemberToken, getApiBaseUrl } from '../../_lib/api'; import { RsvpButton } from './RsvpButton'; import Link from 'next/link'; type RsvpStatus = 'GOING' | 'NOT_GOING' | 'MAYBE'; interface EventItem { id: string; title: string; description: string | null; location: string | null; startsAt: string; endsAt: string | null; rsvpCount: number; myRsvp: RsvpStatus | null; } async function fetchEvents(token: string): Promise { const res = await fetch(`${getApiBaseUrl()}/my/events`, { headers: { Authorization: `Bearer ${token}` }, cache: 'no-store', }).catch(() => null); if (!res || !res.ok) return []; return (await res.json()) as EventItem[]; } function formatEventDate(startsAt: string, endsAt: string | null): string { const start = new Date(startsAt); const dateStr = start.toLocaleDateString('en-IN', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' }); const timeStr = start.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit' }); if (!endsAt) return `${dateStr} · ${timeStr}`; const end = new Date(endsAt); const endTime = end.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit' }); return `${dateStr} · ${timeStr} – ${endTime}`; } const RSVP_BADGE: Record = { GOING: { label: 'Going', cls: 'bg-green-100 text-green-700' }, MAYBE: { label: 'Maybe', cls: 'bg-yellow-100 text-yellow-700' }, NOT_GOING: { label: 'Not going', cls: 'bg-gray-100 text-gray-500' }, }; export default async function EventsPage() { const token = await getMemberToken(); if (!token) return null; const events = await fetchEvents(token); const upcoming = events.filter((e) => new Date(e.startsAt) >= new Date()); const past = events.filter((e) => new Date(e.startsAt) < new Date()); return (

Events

← Dashboard
{events.length === 0 && (

No events scheduled.

Your chapter admin will post events here.

)} {upcoming.length > 0 && (

Upcoming

{upcoming.map((e) => (

{e.title}

{formatEventDate(e.startsAt, e.endsAt)}

{e.location && (

{e.location}

)}
{e.myRsvp && ( {RSVP_BADGE[e.myRsvp].label} )}
{e.description && (

{e.description}

)}
{e.rsvpCount} {e.rsvpCount === 1 ? 'response' : 'responses'}
))}
)} {past.length > 0 && (

Past

{past.map((e) => (

{e.title}

{formatEventDate(e.startsAt, e.endsAt)}

{e.myRsvp && ( {RSVP_BADGE[e.myRsvp].label} )}
))}
)}
); }