Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 1x 1x 2x 2x 2x 2x 2x 3x 2x 1x 1x | /**
* UpcomingEventsSection Component
*
* Displays upcoming events (beyond the current hero event) as a card grid
* on the HomePage. Rendered above the testimonials section.
* Hidden when no additional upcoming events exist.
*/
import { useTranslation } from 'react-i18next';
import { useEvents } from '@/hooks/useEvents';
import { useMyRegistration } from '@/hooks/useMyRegistration';
import { EventCard } from '@/components/public/EventCard';
import { isPublishedPhase } from '@/utils/eventPublication';
import type { EventDetailUI } from '@/types/event.types';
interface UpcomingEventsSectionProps {
currentEventCode: string | undefined;
}
/**
* EventCardWithStatus — per-card wrapper that calls useMyRegistration individually.
* Avoids calling hooks in a loop (rules of hooks) by extracting into a component.
* Story 10.10, AC5 / T10.5.
*/
function UpcomingEventCardWithStatus({ event }: { event: EventDetailUI }) {
const { data: myReg } = useMyRegistration(event.eventCode);
return (
<EventCard
key={event.eventCode}
event={event}
viewMode="grid"
linkPrefix="/events/"
myRegistrationStatus={myReg?.status}
// Story 7.2 "I Could Speak on That": attendees can self-nominate from upcoming-event cards.
enableSelfNomination
/>
);
}
export function UpcomingEventsSection({ currentEventCode }: UpcomingEventsSectionProps) {
const { t } = useTranslation('events');
const { data, isLoading } = useEvents({ page: 1, limit: 5 }, undefined, {
expand: ['topics', 'sessions', 'speakers'],
});
Iif (isLoading) return null;
const now = new Date();
const upcomingEvents = (data?.data ?? [])
.filter(
(e) =>
e.eventCode !== currentEventCode &&
new Date(e.date) > now &&
// Only surface events the organizer has actively published. The generic
// GET /events list returns every event regardless of publication, so an
// unpublished CREATED event (currentPublishedPhase NONE/null) would otherwise
// leak onto the public homepage (mirrors the backend /events/current gate).
// currentPublishedPhase rides in the list payload at runtime but isn't on the
// narrower list-item type — read it through EventDetailUI (the cast used below too).
isPublishedPhase((e as EventDetailUI).currentPublishedPhase)
)
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
.slice(0, 4);
if (upcomingEvents.length === 0) return null;
return (
<div className="mt-16">
<h2 className="text-2xl font-light text-zinc-100 mb-6">{t('public.upcomingEvents.title')}</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{upcomingEvents.map((event) => (
<UpcomingEventCardWithStatus
key={event.eventCode}
event={{ ...event, sessions: event.sessions ?? undefined } as EventDetailUI}
/>
))}
</div>
</div>
);
}
|