Archived
Add coupon codes and staff pricing
Percentage, fixed-amount and comp codes, limited by event, ticket option or variant, dates, use counts, minimum quantity, and people, roles or an email domain. The discount is locked in on the registration (mirrored on Registration.discountTotal so every total sees it), shows on invoices, receipts, emails and the Yoco checkout, and is released on cancellation. Use limits are enforced under an advisory lock. Ticket options and variants can also carry a staff price that Staff and above get automatically. Adds a Supervisor > Coupon codes page, code fields on registration, My Events, manual registration, at the door and the kiosk, a Discounts report, and audit log entries. Also fixes Yoco line items and the free-registration check for lines spanning several price tranches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -497,6 +497,41 @@ export default function UserDashboardPage() {
|
||||
return false;
|
||||
}, [activeReg, activeEventHasForm]);
|
||||
|
||||
// Discount code on an existing registration
|
||||
const [codeInput, setCodeInput] = useState("");
|
||||
const [codeBusy, setCodeBusy] = useState(false);
|
||||
const [codeError, setCodeError] = useState<string | null>(null);
|
||||
|
||||
const applyCodeToActive = async () => {
|
||||
if (!token || !activeRegId || !codeInput.trim()) return;
|
||||
setCodeBusy(true);
|
||||
setCodeError(null);
|
||||
try {
|
||||
const res = await apiFetch<{ message?: string }>(`/api/registrations/${encodeURIComponent(activeRegId)}/coupon`, {
|
||||
method: 'POST',
|
||||
authToken: token,
|
||||
body: { code: codeInput.trim() },
|
||||
});
|
||||
const myRegs = await apiFetch<any[]>(`/api/registrations/myregistrations?showPast=${showPast ? '1' : '0'}`, { authToken: token });
|
||||
setRegistrations(myRegs);
|
||||
const updated = myRegs.find(r => r.id === activeRegId);
|
||||
const pays = await apiFetch<any[]>(`/api/payments/registration/${encodeURIComponent(activeRegId)}`, { authToken: token });
|
||||
const totalPaid = pays.reduce((s, p) => s + (p.amount || 0), 0);
|
||||
const totalDue = updated?.totalDueComputed ?? 0;
|
||||
setBilling(prev => ({ ...prev, [activeRegId]: { totalDue, totalPaid, outstanding: Math.max(0, totalDue - totalPaid), payments: pays } }));
|
||||
try {
|
||||
const myTicks = await apiFetch<any[]>("/api/tickets/mytickets", { authToken: token });
|
||||
setTickets(myTicks);
|
||||
} catch {}
|
||||
setCodeInput("");
|
||||
setInfo(res?.message || 'Code applied.');
|
||||
} catch (e: any) {
|
||||
setCodeError(e?.message || "Couldn't apply that code");
|
||||
} finally {
|
||||
setCodeBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Cancel registration state
|
||||
const [cancelLoading, setCancelLoading] = useState(false);
|
||||
const [showCancelConfirm, setShowCancelConfirm] = useState(false);
|
||||
@@ -1034,10 +1069,35 @@ export default function UserDashboardPage() {
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
const activeCoupon = (activeReg.couponRedemptions || [])[0];
|
||||
return (
|
||||
<div>
|
||||
{renderGroup('Early bird', earlyBirdRows)}
|
||||
{renderGroup('Standard price', standardRows)}
|
||||
{Number(activeReg.discountTotal || 0) > 0 && (
|
||||
<div className="text-sm text-green-700 mt-2">
|
||||
Discount code{activeCoupon?.coupon?.code ? <> <span className="font-mono font-semibold">{activeCoupon.coupon.code}</span></> : null} — −{formatRand(Number(activeReg.discountTotal))}
|
||||
</div>
|
||||
)}
|
||||
{canModifyActive && activeBill && activeBill.outstanding > 0 && !activeCoupon && (
|
||||
<div className="mt-3">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
value={codeInput}
|
||||
onChange={e => { setCodeInput(e.target.value.toUpperCase()); setCodeError(null); }}
|
||||
placeholder="Have a discount code?"
|
||||
className="flex-1 min-w-0 border rounded px-2 py-1 text-sm font-mono uppercase"
|
||||
aria-label="Discount code"
|
||||
/>
|
||||
<button
|
||||
onClick={applyCodeToActive}
|
||||
disabled={codeBusy || !codeInput.trim()}
|
||||
className="px-3 py-1 text-sm rounded border border-brand-600 text-brand-700 hover:bg-brand-50 disabled:opacity-50"
|
||||
>{codeBusy ? 'Applying…' : 'Apply'}</button>
|
||||
</div>
|
||||
{codeError && <p className="text-xs text-red-600 mt-1">{codeError}</p>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})() : (
|
||||
|
||||
Reference in New Issue
Block a user