Archived
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:
@@ -10,35 +10,11 @@ import { CouponCodeField, AppliedCoupon } from "@/components/shared/CouponCodeFi
|
||||
import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload, consentDetailsMissing } from "@/components/shared/AttendeeNamesEditor";
|
||||
import { UserPlus, CreditCard } from "lucide-react";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { EarlyBirdTier, Event, EventOption, OptionVariant, Registration, RegistrationOption, User } from "@/types";
|
||||
import { optionUnitNow, variantUnitNow } from "@/lib/pricing";
|
||||
import type { Event, EventOption, Registration, RegistrationOption, User } from "@/types";
|
||||
|
||||
// ─── Pricing helpers ─────────────────────────────────────────────────────────
|
||||
|
||||
// The earliest-deadline 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];
|
||||
}
|
||||
|
||||
function effectiveOptionUnit(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;
|
||||
}
|
||||
|
||||
function effectiveVariantUnit(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;
|
||||
}
|
||||
|
||||
function fmtPrice(n: number) {
|
||||
return n === 0 ? "Free" : `R ${n.toFixed(2)}`;
|
||||
}
|
||||
@@ -52,8 +28,8 @@ function optionUnitPrice(opt: RegistrationOption): number {
|
||||
}
|
||||
const eo = opt.eventOption;
|
||||
if (!eo) return 0;
|
||||
if (opt.variant) return effectiveVariantUnit(eo, opt.variant);
|
||||
return effectiveOptionUnit(eo);
|
||||
if (opt.variant) return variantUnitNow(eo, opt.variant);
|
||||
return optionUnitNow(eo);
|
||||
}
|
||||
|
||||
// ─── Component ───────────────────────────────────────────────────────────────
|
||||
@@ -292,9 +268,9 @@ export default function ManualRegistrationPage() {
|
||||
const totalDue = useMemo(() => {
|
||||
return options.reduce((sum, o) => {
|
||||
if ((o.variants || []).length > 0) {
|
||||
return sum + (o.variants || []).reduce((vs, v) => vs + (quantities[`${o.id}::${v.id}`] || 0) * effectiveVariantUnit(o, v), 0);
|
||||
return sum + (o.variants || []).reduce((vs, v) => vs + (quantities[`${o.id}::${v.id}`] || 0) * variantUnitNow(o, v), 0);
|
||||
}
|
||||
return sum + (quantities[o.id] || 0) * effectiveOptionUnit(o);
|
||||
return sum + (quantities[o.id] || 0) * optionUnitNow(o);
|
||||
}, 0);
|
||||
}, [options, quantities]);
|
||||
|
||||
@@ -561,7 +537,7 @@ export default function ManualRegistrationPage() {
|
||||
{opt.name}{opt.isMainTicket ? <span className="ml-1.5 text-xs text-brand-600 font-normal">• Main</span> : null}
|
||||
</div>
|
||||
{(opt.variants || []).map((v) => {
|
||||
const unit = effectiveVariantUnit(opt, v);
|
||||
const unit = variantUnitNow(opt, v);
|
||||
const basePrice = v.price !== null && v.price !== undefined ? v.price : opt.price;
|
||||
const key = `${opt.id}::${v.id}`;
|
||||
return (
|
||||
@@ -588,7 +564,7 @@ export default function ManualRegistrationPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const unit = effectiveOptionUnit(opt);
|
||||
const unit = optionUnitNow(opt);
|
||||
return (
|
||||
<div key={opt.id} className="border rounded p-3">
|
||||
<div className="font-medium text-sm">{opt.name}</div>
|
||||
|
||||
Reference in New Issue
Block a user