Add 70-person capacity limit for watchers with real-time availability checks. Update drink card pricing to €5 per person (was €5 base + €2 per guest). Add feature flag to bypass registration countdown. Show under-review notice for performer registrations. Update FAQ performance duration from 5-7 to 5 minutes.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { COUNTDOWN_ENABLED, REGISTRATION_OPENS_AT } from "./opening";
|
|
|
|
interface RegistrationOpenState {
|
|
isOpen: boolean;
|
|
days: number;
|
|
hours: number;
|
|
minutes: number;
|
|
seconds: number;
|
|
}
|
|
|
|
function compute(): RegistrationOpenState {
|
|
if (!COUNTDOWN_ENABLED) {
|
|
return { isOpen: true, days: 0, hours: 0, minutes: 0, seconds: 0 };
|
|
}
|
|
const diff = REGISTRATION_OPENS_AT.getTime() - Date.now();
|
|
if (diff <= 0) {
|
|
return { isOpen: true, days: 0, hours: 0, minutes: 0, seconds: 0 };
|
|
}
|
|
const totalSeconds = Math.floor(diff / 1000);
|
|
const days = Math.floor(totalSeconds / 86400);
|
|
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
const seconds = totalSeconds % 60;
|
|
return { isOpen: false, days, hours, minutes, seconds };
|
|
}
|
|
|
|
/**
|
|
* Returns live countdown state to {@link REGISTRATION_OPENS_AT}.
|
|
* Ticks every second; clears the interval once registration is open.
|
|
*/
|
|
export function useRegistrationOpen(): RegistrationOpenState {
|
|
const [state, setState] = useState<RegistrationOpenState>(compute);
|
|
|
|
useEffect(() => {
|
|
if (state.isOpen) return;
|
|
|
|
const id = setInterval(() => {
|
|
const next = compute();
|
|
setState(next);
|
|
if (next.isOpen) clearInterval(id);
|
|
}, 1000);
|
|
|
|
return () => clearInterval(id);
|
|
}, [state.isOpen]);
|
|
|
|
return state;
|
|
}
|