WIP 1.51.9: frontend on v2 for series, passes, bundles, coupons, campuses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 12:34:49 +02:00
co-authored by Claude Opus 5.5
parent d6082693c2
commit 733b23955b
18 changed files with 81 additions and 58 deletions
@@ -2,7 +2,8 @@
import React, { useEffect, useRef, useState } from "react";
import { TicketPercent, X } from "lucide-react";
import { apiFetch, ApiError } from "@/lib/api";
import { ApiError } from "@/lib/api";
import { apiV2Data } from "@/lib/apiV2";
export type BasketItem = { eventOptionId: string; variantId?: string | null; quantity: number };
@@ -16,7 +17,7 @@ export type AppliedCoupon = {
/**
* "Have a code?" field. Checks the code against the current basket with
* POST /api/coupons/validate and reports the result through `onChange` — the parent
* POST /api/v2/coupons/check and reports the result through `onChange` — the parent
* sends `applied.code` as `couponCode` when it registers. Re-checks automatically when
* the basket changes, since the discount (or whether the code applies at all) can change.
*
@@ -58,7 +59,9 @@ export function CouponCodeField({
try {
const body: Record<string, unknown> = { code: trimmed, eventId, options: items };
if (forUserId !== undefined) body.forUserId = forUserId;
const res = await apiFetch<AppliedCoupon & { valid: boolean }>("/api/coupons/validate", { method: "POST", authToken: token || undefined, body });
const res = await (apiV2Data("post", "/coupons/check", { authToken: token, body: body as never }) as Promise<(AppliedCoupon & { valid: true }) | { valid: false; message: string }>);
// A code that doesn't apply is an answer, not an error.
if (!res.valid) { onChange(null); setError(res.message); return; }
onChange({ code: res.code, summary: res.summary, discount: res.discount, subtotal: res.subtotal, total: res.total });
} catch (e) {
onChange(null);