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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | 1x 1x 1x 1x 43x 43x 43x 43x 43x 43x 43x 36x 36x 43x 43x 36x 33x 33x 32x 32x 32x 32x 28x 2x 2x 32x 43x 36x 43x 43x 6x 6x 6x 17x 17x 17x 17x 17x 17x 17x 17x 6x 6x 6x 6x 43x 6x 1x | /**
* HeroSection Component
* From BATbern-public with React Router integration
* Full-screen hero with Unicorn.studio interactive background
*/
import { useEffect, useState, lazy, Suspense, ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { Button } from '@/components/public/ui/button';
import { useTranslation } from 'react-i18next';
// Lazy: the registration wizard is a heavy MUI form rendered only after the user expands
// the inline "Register" panel. Lazy-loading it keeps @mui/material out of the eager public
// homepage bundle — it arrives only when someone actually starts registering.
const RegistrationWizard = lazy(() =>
import('@/components/public/Registration/RegistrationWizard').then((m) => ({
default: m.RegistrationWizard,
}))
);
import { AttendeeUnregisterPanel } from '@/components/public/Registration/AttendeeUnregisterPanel';
import { BATbernLoader } from '@/components/shared/BATbernLoader';
import { EventEditionLabel } from '@/components/shared/EventEditionLabel/EventEditionLabel';
import { CheckCircle2, Mail } from 'lucide-react';
import { useMyRegistration } from '@/hooks/useMyRegistration';
import { buildCdnImageUrl, buildCdnImageSrcSet } from '@/utils/cdnImage';
interface HeroSectionProps {
title: string;
date?: string;
location?: string;
ctaText?: string;
ctaLink: string;
/** Optional event code for inline registration (Story 4.1.5) */
eventCode?: string;
/** Optional theme image URL - takes precedence over unicorn.studio background */
themeImageUrl?: string;
unicornProjectId?: string;
countdownTimer?: ReactNode;
/** AC8 (Story 10.11): Remaining spots — passed through to RegistrationWizard */
spotsRemaining?: number | null;
/** Hide the register CTA entirely (POST_EVENT, ARCHIVE, COMING_SOON) */
hideRegisterCta?: boolean;
}
export const HeroSection = ({
title,
date,
location,
ctaText,
ctaLink,
eventCode,
themeImageUrl,
unicornProjectId = 'jfzsiwProJi81qvb7uKX',
countdownTimer,
spotsRemaining,
hideRegisterCta = false,
}: HeroSectionProps) => {
const { t } = useTranslation(['common', 'registration']);
const [isRegistrationExpanded, setIsRegistrationExpanded] = useState(false);
const [isUnregisterExpanded, setIsUnregisterExpanded] = useState(false);
const [pendingRegistration, setPendingRegistration] = useState<{
email: string;
eventCode: string;
expiresAt: number;
} | null>(null);
// API-based registration check for authenticated users (no sessionStorage required)
const { data: myRegistration } = useMyRegistration(eventCode);
const isAlreadyRegistered = myRegistration != null && myRegistration.status !== 'CANCELLED';
// Check for pending registration in sessionStorage
useEffect(() => {
const stored = sessionStorage.getItem('pendingRegistration');
Iif (stored && eventCode) {
try {
const data = JSON.parse(stored);
// Check if registration is for this event and not expired
if (data.eventCode === eventCode && Date.now() < data.expiresAt) {
setPendingRegistration(data);
} else if (Date.now() >= data.expiresAt) {
// Clean up expired registration
sessionStorage.removeItem('pendingRegistration');
}
} catch (err) {
console.error('Failed to parse pending registration:', err);
sessionStorage.removeItem('pendingRegistration');
}
}
}, [eventCode]);
// Format date for display
const formattedDate = date
? new Date(date).toLocaleDateString('de-CH', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
})
: null;
// Extend Window interface for UnicornStudio
interface WindowWithUnicorn extends Window {
UnicornStudio?: {
isInitialized: boolean;
init: () => void;
};
}
// Load Unicorn.studio script only when no theme image is provided
useEffect(() => {
if (themeImageUrl) return; // Skip unicorn.studio if we have a theme image
const win = window as WindowWithUnicorn;
if (!win.UnicornStudio) {
win.UnicornStudio = { isInitialized: false, init: () => {} };
const script = document.createElement('script');
script.src =
'https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js@v1.4.34/dist/unicornStudio.umd.js';
script.onload = function () {
if (win.UnicornStudio && !win.UnicornStudio.isInitialized) {
win.UnicornStudio.init();
win.UnicornStudio.isInitialized = true;
}
};
(document.head || document.body).appendChild(script);
}
}, [themeImageUrl]);
// Scroll-tracking for the unregister drawer (mirrors registration)
useEffect(() => {
Eif (!isUnregisterExpanded) return;
let animationFrame: number;
let startTime: number | null = null;
const animationDuration = 1500;
const trackBottom = (timestamp: number) => {
if (!startTime) startTime = timestamp;
const elapsed = timestamp - startTime;
const section = document.getElementById('registration-wizard-section');
if (section && elapsed < animationDuration) {
const rect = section.getBoundingClientRect();
window.scrollTo({
top: window.pageYOffset + rect.bottom - window.innerHeight,
behavior: 'instant',
});
animationFrame = requestAnimationFrame(trackBottom);
}
};
animationFrame = requestAnimationFrame(trackBottom);
return () => {
if (animationFrame) cancelAnimationFrame(animationFrame);
};
}, [isUnregisterExpanded]);
// Continuously track wizard bottom during animation
useEffect(() => {
if (!isRegistrationExpanded) return;
let animationFrame: number;
let startTime: number | null = null;
const animationDuration = 1500; // 1.5 seconds
const trackWizardBottom = (timestamp: number) => {
if (!startTime) startTime = timestamp;
const elapsed = timestamp - startTime;
const wizardSection = document.getElementById('registration-wizard-section');
Eif (wizardSection && elapsed < animationDuration) {
const rect = wizardSection.getBoundingClientRect();
// Scroll so bottom of wizard aligns with bottom of viewport
const scrollTarget = window.pageYOffset + rect.bottom - window.innerHeight;
window.scrollTo({ top: scrollTarget, behavior: 'instant' });
animationFrame = requestAnimationFrame(trackWizardBottom);
}
};
animationFrame = requestAnimationFrame(trackWizardBottom);
return () => {
Eif (animationFrame) {
cancelAnimationFrame(animationFrame);
}
};
}, [isRegistrationExpanded]);
return (
<>
<section
className={`relative w-full overflow-hidden transition-all duration-500 ease-in-out min-h-screen`}
>
{/* Background - Theme Image or Unicorn.studio Interactive Background */}
<div className="absolute inset-0 z-0 w-full h-full" aria-hidden="true">
{themeImageUrl ? (
<img
src={buildCdnImageUrl(themeImageUrl, { w: 1920, fit: 'cover' }) ?? themeImageUrl}
srcSet={buildCdnImageSrcSet(themeImageUrl, [768, 1280, 1920], { fit: 'cover' })}
sizes="100vw"
alt=""
className="w-full h-full object-cover"
width={1920}
height={1080}
fetchPriority="high"
style={{ aspectRatio: '16/9' }}
/>
) : (
<div data-us-project={unicornProjectId} style={{ width: '100%', height: '100%' }} />
)}
</div>
{/* Content */}
<div className={`relative z-10 w-full flex items-end pb-16 md:pb-20 lg:pb-24 min-h-screen`}>
<div className="container mx-auto px-4">
<div className="max-w-4xl">
<BATbernLoader size={288} speed="slow" className="mb-6" />
{/* Edition kicker above the title (feedback #15) */}
{eventCode && (
<EventEditionLabel
eventCode={eventCode}
className="block text-lg md:text-xl font-semibold uppercase tracking-wide text-foreground/70 mb-2"
data-testid="event-hero-edition"
/>
)}
<h1
className="text-4xl sm:text-5xl md:text-6xl lg:text-7xl xl:text-8xl font-bold text-foreground leading-tight mb-6"
data-testid="event-hero-title"
>
{title}
</h1>
{/* Date and Location Subtitle */}
{(formattedDate || location) && (
<div className="flex flex-wrap items-center gap-4 md:gap-6 text-foreground/90 mb-8">
{formattedDate && (
<div className="flex items-center gap-2">
<svg
className="w-5 h-5 md:w-6 md:h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
<span className="text-base md:text-lg lg:text-xl font-medium">
{formattedDate}
</span>
</div>
)}
{location && (
<div className="flex items-center gap-2">
<svg
className="w-5 h-5 md:w-6 md:h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"
/>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"
/>
</svg>
<span className="text-base md:text-lg lg:text-xl font-medium">
{location}
</span>
</div>
)}
</div>
)}
<div className="flex flex-col sm:flex-row items-start sm:items-center gap-4">
{!hideRegisterCta &&
(pendingRegistration ? (
// Show "already registered" message (sessionStorage — just registered this session)
<div className="bg-green-900/20 border border-green-800 rounded-lg p-4 max-w-md">
<div className="flex items-start gap-3">
<CheckCircle2 className="h-5 w-5 text-green-400 flex-shrink-0 mt-0.5" />
<div>
<p className="text-green-400 font-medium mb-1">
{t('registration.alreadyRegistered.title')}
</p>
<p className="text-sm text-zinc-300 mb-2">
{t('registration.alreadyRegistered.pending')}{' '}
<span className="font-mono text-green-400">
{pendingRegistration.email}
</span>
</p>
<div className="flex items-center gap-2 text-xs text-zinc-400">
<Mail className="h-3 w-3" />
<span>{t('registration.alreadyRegistered.checkEmail')}</span>
</div>
</div>
</div>
</div>
) : isAlreadyRegistered ? (
// Show "already registered" for authenticated users with an active registration
<div className="bg-green-900/20 border border-green-800 rounded-lg p-4 max-w-md">
<div className="flex items-start gap-3">
<CheckCircle2 className="h-5 w-5 text-green-400 flex-shrink-0 mt-0.5" />
<div>
<p className="text-green-400 font-medium mb-1">
{t('registration.alreadyRegistered.title')}
</p>
<p className="text-sm text-zinc-300 mb-2">
{t(
`registration:registrationStatusBanner.${(myRegistration!.status ?? 'REGISTERED').toLowerCase() as 'confirmed' | 'registered' | 'waitlist'}`
)}
</p>
<Button
variant="ghost"
size="sm"
onClick={() => setIsUnregisterExpanded(true)}
disabled={isUnregisterExpanded}
className="text-xs text-red-400 hover:text-red-300 px-0 h-auto"
data-testid="hero-unregister-btn"
>
{t('registration:unregister.button')}
</Button>
</div>
</div>
</div>
) : eventCode ? (
// Inline registration mode: expand wizard below
<Button
size="lg"
className="text-base md:text-lg"
onClick={() => setIsRegistrationExpanded(true)}
disabled={isRegistrationExpanded}
>
{ctaText || t('public.register')}
</Button>
) : (
// Fallback to link mode (when eventCode not provided)
<Button size="lg" className="text-base md:text-lg" asChild>
<Link to={ctaLink}>{ctaText || t('public.register')}</Link>
</Button>
))}
{countdownTimer && <div className="ml-0 sm:ml-4">{countdownTimer}</div>}
</div>
</div>
</div>
</div>
</section>
{/* Inline Registration (Story 4.1.5) - Grows from bottom */}
{isRegistrationExpanded && eventCode && (
<section
id="registration-wizard-section"
className="relative z-20 overflow-hidden"
style={{
animation: 'slideUp 1.5s ease-out forwards',
}}
>
<div className="container mx-auto px-4 py-16">
<Suspense fallback={<BATbernLoader size={64} />}>
<RegistrationWizard
eventCode={eventCode}
inline={true}
onCancel={() => setIsRegistrationExpanded(false)}
spotsRemaining={spotsRemaining}
/>
</Suspense>
</div>
</section>
)}
{/* Inline Unregister Drawer - same slide-up pattern */}
{isUnregisterExpanded && eventCode && myRegistration && (
<section
id="registration-wizard-section"
className="relative z-20 overflow-hidden"
style={{
animation: 'slideUp 1.5s ease-out forwards',
}}
>
<div className="container mx-auto px-4 py-16">
<AttendeeUnregisterPanel
eventCode={eventCode}
registration={myRegistration}
onCancel={() => setIsUnregisterExpanded(false)}
inline={true}
/>
</div>
</section>
)}
</>
);
};
|