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:
@@ -3,6 +3,7 @@
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { TwoFactorChallenge, isTwoFactorChallenge } from "@/lib/auth";
|
||||
import { CouponCodeField, AppliedCoupon } from "@/components/shared/CouponCodeField";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
type EarlyBirdTier = { deadline: string; price: number; order?: number; variantId?: string | null };
|
||||
@@ -134,6 +135,7 @@ export default function SelfServicePage() {
|
||||
const [setupLoading, setSetupLoading] = useState(false);
|
||||
const [setupError, setSetupError] = useState<string | null>(null);
|
||||
const [supervisorToken, setSupervisorToken] = useState<string | null>(null);
|
||||
const [kioskCoupon, setKioskCoupon] = useState<AppliedCoupon | null>(null);
|
||||
// Set while a supervisor with two-factor on still has to enter their code.
|
||||
const [setupChallenge, setSetupChallenge] = useState<TwoFactorChallenge | null>(null);
|
||||
const [setupCode, setSetupCode] = useState("");
|
||||
@@ -408,6 +410,7 @@ export default function SelfServicePage() {
|
||||
// activation email/WhatsApp at them afterward.
|
||||
skipActivationNotice: !createAccount,
|
||||
notificationPreference: notificationPref,
|
||||
...(kioskCoupon ? { couponCode: kioskCoupon.code } : {}),
|
||||
};
|
||||
if (createAccount && visitorPassword) {
|
||||
payload.user.password = visitorPassword;
|
||||
@@ -421,7 +424,7 @@ export default function SelfServicePage() {
|
||||
|
||||
setCurrentRegistrationId(result?.id || null);
|
||||
setCurrentUserId(result?.userId || null);
|
||||
setRegistrationIsFree(result?.status === "paid" || total === 0);
|
||||
setRegistrationIsFree(result?.status === "paid" || (result?.totalDueComputed ?? total) === 0);
|
||||
setConfirmationName(visitorName.trim());
|
||||
|
||||
// If event has a required form and there are main tickets, show form step
|
||||
@@ -522,6 +525,7 @@ export default function SelfServicePage() {
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
setKioskCoupon(null);
|
||||
setVisitorName("");
|
||||
setVisitorEmail("");
|
||||
setVisitorPhone("");
|
||||
@@ -989,9 +993,27 @@ export default function SelfServicePage() {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{total > 0 && selectedEventId && (
|
||||
<div className="mt-4">
|
||||
<CouponCodeField
|
||||
eventId={selectedEventId}
|
||||
basket={Object.entries(quantities).map(([key, quantity]) => {
|
||||
const [eventOptionId, variantId] = key.split("::");
|
||||
return { eventOptionId, quantity, variantId: variantId || null };
|
||||
})}
|
||||
token={supervisorToken}
|
||||
forUserId={matchedAccount?.id ?? null}
|
||||
applied={kioskCoupon}
|
||||
onChange={setKioskCoupon}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{total > 0 && (
|
||||
<div className="mt-3 text-right text-base font-semibold text-gray-800">
|
||||
Total: {fmtCurrency(total)}
|
||||
{kioskCoupon && kioskCoupon.discount > 0 && (
|
||||
<span className="mr-2 text-sm font-normal text-gray-500 line-through">{fmtCurrency(kioskCoupon.subtotal)}</span>
|
||||
)}
|
||||
Total: {fmtCurrency(kioskCoupon ? kioskCoupon.total : total)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user