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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | 2x 25x 25x 25x 25x 25x 84x 25x 25x 25x 84x 85x 25x 25x | /**
* EventCard Component (Story 4.2 - Task 2b)
*
* Archive event card with session preview
* Supports grid and list view modes
* Styled to match session cards on homepage (dark theme)
*/
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/public/ui/card';
import { Badge } from '@/components/public/ui/badge';
import { SpeakerDisplay } from './Event/SpeakerDisplay';
import { SpeakerSelfNominatePanel } from '@/components/attendee/SpeakerSelfNominatePanel';
import { buildCdnImageUrl, buildCdnImageSrcSet } from '@/utils/cdnImage';
import { canOfferSelfNomination } from '@/utils/eventPublication';
import type { EventDetailUI, SessionUI } from '@/types/event.types';
type RegistrationStatus = 'REGISTERED' | 'CONFIRMED' | 'WAITLIST' | 'CANCELLED' | 'ATTENDED';
interface EventCardProps {
event: EventDetailUI;
viewMode: 'grid' | 'list';
linkPrefix?: string;
/** Optional registration status for this event (Story 10.10, AC5) */
myRegistrationStatus?: RegistrationStatus;
/**
* Story 7.2 "I Could Speak on That": show the attendee speaker self-nomination button on
* upcoming-event cards. The button is login-gated internally; the card additionally only
* renders it once the event's topic is set + published (the backend is authoritative).
*/
enableSelfNomination?: boolean;
}
const STATUS_CHIP_STYLES: Record<RegistrationStatus, string> = {
CONFIRMED: 'bg-green-400/20 text-green-400 border-green-400/30',
REGISTERED: 'bg-amber-400/20 text-amber-400 border-amber-400/30',
WAITLIST: 'bg-blue-400/20 text-blue-400 border-blue-400/30',
CANCELLED: 'bg-zinc-600/20 text-zinc-400 border-zinc-600/30',
ATTENDED: 'bg-purple-400/20 text-purple-400 border-purple-400/30',
};
export function EventCard({
event,
viewMode,
linkPrefix = '/archive/',
myRegistrationStatus,
enableSelfNomination = false,
}: EventCardProps) {
const { t } = useTranslation();
const { t: tEvents } = useTranslation('events');
// Story 7.2: surface the self-nomination button only while the self-nomination window is open
// — during the TOPIC publishing phase (topic published, speakers not yet). canOfferSelfNomination
// is the single source of truth (shared with the homepage hero + mirrored by the backend guard);
// the button itself is additionally login-gated.
const showSelfNominate = enableSelfNomination && canOfferSelfNomination(event);
const STRUCTURAL_TYPES = new Set(['moderation', 'break', 'lunch', 'aperitif']);
// Get non-structural sessions only (moderation/break/lunch don't belong on a card)
const sessions = (event.sessions || []).filter(
(s) => !STRUCTURAL_TYPES.has(s.sessionType ?? '')
) as SessionUI[];
// Show all sessions (no limit)
const displayedSessions = sessions;
// Format date (use Swiss German locale for Swiss company)
const formattedDate = new Date(event.date).toLocaleDateString('de-CH', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
const cardLink = (
<Link
to={`${linkPrefix}${event.eventCode}`}
className={`block ${viewMode === 'list' ? 'w-full' : ''}`}
data-testid="event-card"
>
<div
className={viewMode === 'grid' ? 'grid-card' : 'list-card'}
data-testid={`event-card-${event.eventCode}`}
data-view-mode={viewMode}
>
<Card className="group bg-zinc-700 border-zinc-600 hover:border-zinc-500 transition-colors h-full">
{/* Theme Image */}
{event.themeImageUrl && (
<div
className={`overflow-hidden ${viewMode === 'list' ? 'flex-shrink-0 w-48' : 'w-full h-48'}`}
>
{/* Resize + WebP via the CDN Lambda — cards display at ~192px tall and are
below the fold, so serve a small responsive image (lazy) instead of the
full-resolution origin. A raw AI-theme PNG here was 2.7 MB on the homepage
(Lighthouse 2026-06-02); buildCdnImageUrl drops it to a few tens of KB. */}
<img
src={
buildCdnImageUrl(event.themeImageUrl, { w: 768, fit: 'cover' }) ??
event.themeImageUrl
}
srcSet={
buildCdnImageSrcSet(event.themeImageUrl, [384, 768], { fit: 'cover' }) ??
undefined
}
sizes="(min-width: 1024px) 384px, (min-width: 768px) 50vw, 100vw"
alt={`${event.title} theme image`}
className="w-full h-full object-cover"
loading="lazy"
data-testid="event-card-image"
/>
</div>
)}
<CardHeader>
<div className="flex items-start justify-between gap-4 mb-2">
{/* Event Code (e.g., BATbern57) */}
<Badge
variant="outline"
className="bg-blue-400/10 text-blue-400 border-blue-400/20 font-mono"
>
{event.eventCode}
</Badge>
{/* Topic Badge */}
{event.topic && typeof event.topic === 'object' && (
<Badge className="bg-zinc-800 text-zinc-300" data-testid="event-card-topic">
{event.topic.name}
</Badge>
)}
{/* Registration Status Chip (Story 10.10, AC5) */}
{myRegistrationStatus && (
<Badge
variant="outline"
className={STATUS_CHIP_STYLES[myRegistrationStatus]}
data-testid="event-card-status-chip"
>
{tEvents(`eventCard.statusChip.${myRegistrationStatus.toLowerCase()}`)}
</Badge>
)}
</div>
{/* Event Title */}
<CardTitle className="font-light text-xl text-zinc-100" data-testid="event-card-title">
{event.title}
</CardTitle>
{/* Date and Venue */}
<div className="space-y-1 mt-2">
<p className="text-sm text-zinc-400" data-testid="event-card-date">
{formattedDate}
</p>
{event.venueName && <p className="text-sm text-zinc-400">{event.venueName}</p>}
</div>
</CardHeader>
<CardContent className="space-y-4">
{/* Session Preview - Show all sessions */}
{displayedSessions.length > 0 && (
<div className="space-y-3">
<div
className={`grid gap-4 ${viewMode === 'list' ? 'grid-cols-2' : 'grid-cols-1'}`}
>
{displayedSessions.map((session, index) => (
<div
key={session.sessionId || session.id || `session-${index}`}
className="border-t border-zinc-800 pt-3 first:border-t-0 first:pt-0"
>
{/* Session Title */}
<p className="text-sm font-medium text-zinc-200 mb-2">{session.title}</p>
{/* Speakers with companies */}
{session.speakers && session.speakers.length > 0 ? (
<div
className={`grid gap-6 ${viewMode === 'list' ? 'grid-cols-2' : 'grid-cols-1'}`}
>
{session.speakers.map((speaker, speakerIndex) => (
<SpeakerDisplay
key={speaker.username || `speaker-${index}-${speakerIndex}`}
speaker={speaker}
size="small"
showProfilePicture={true}
/>
))}
</div>
) : (
<p className="text-xs text-zinc-500">Keine Referenten</p>
)}
</div>
))}
</div>
</div>
)}
{/* View Details Link */}
<div className="pt-2 border-t border-zinc-800">
<span className="text-blue-400 hover:text-blue-300 text-sm font-medium transition-colors">
{t('archive.card.viewDetails')} →
</span>
</div>
</CardContent>
</Card>
</div>
</Link>
);
// Story 7.2: when self-nomination is enabled for this card, render the button below the
// card (outside the <Link>, so the button is not a nested interactive element). The panel
// is login-gated internally.
Iif (showSelfNominate) {
return (
<div className={`flex flex-col gap-2 ${viewMode === 'list' ? 'w-full' : ''}`}>
{cardLink}
<SpeakerSelfNominatePanel eventCode={event.eventCode} topicName={event.topic?.name} />
</div>
);
}
return cardLink;
}
|