Type the at-the-door page and share pricing helpers

Each door panel and modal gets typed props; unused setError/setInfo/
onCreated props are dropped. The current early-bird price helpers move
to src/lib/pricing.ts (shared with manual registration), dead fallbacks
for a legacy registration 'options' field are removed, and the refund
history now shows a refund's reason (stored in its status field) instead
of a 'reason' field that never exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 11:10:01 +02:00
co-authored by Claude Opus 5.5
parent 5ee1880339
commit 8360a78026
4 changed files with 232 additions and 209 deletions
+28 -1
View File
@@ -1,4 +1,4 @@
import type { RegistrationOption } from "@/types";
import type { EarlyBirdTier, EventOption, OptionVariant, RegistrationOption } from "@/types";
// Effective unit price for a registration option. Uses priceSnapshot when available
// (authoritative backend price, variant-aware). Falls back to a deadline-only early-bird
@@ -30,3 +30,30 @@ export function registrationOptionUnitPrice(opt: RegistrationOption, referenceTi
const price = Number(applicable[0].price);
return (price >= 0) ? price : base;
}
// The earliest-deadline early-bird tier that's still open, or undefined when none are.
function currentTier(tiers: EarlyBirdTier[]): EarlyBirdTier | undefined {
const now = new Date();
return tiers
.map((t) => ({ ...t, deadlineAt: new Date(t.deadline) }))
.filter((t) => now < t.deadlineAt)
.sort((a, b) => a.deadlineAt.getTime() - b.deadlineAt.getTime() || (a.order || 0) - (b.order || 0) || a.price - b.price)[0];
}
// What an event option costs right now: its current early-bird price, else its base price.
export function optionUnitNow(opt: EventOption): number {
const base = opt.price || 0;
const tiers = (Array.isArray(opt.earlyBirdTiers) ? opt.earlyBirdTiers : []).filter((t) => !t.variantId);
if (tiers.length === 0) return base;
return currentTier(tiers)?.price ?? base;
}
// Same for a variant: its own tiers if it has any, otherwise the option's.
export function variantUnitNow(opt: EventOption, variant: OptionVariant): number {
const base = variant.price !== null && variant.price !== undefined ? variant.price : opt.price || 0;
const allTiers = Array.isArray(opt.earlyBirdTiers) ? opt.earlyBirdTiers : [];
const variantTiers = allTiers.filter((t) => t.variantId === variant.id);
const tiers = variantTiers.length > 0 ? variantTiers : allTiers.filter((t) => !t.variantId);
if (tiers.length === 0) return base;
return currentTier(tiers)?.price ?? base;
}