Archived
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:
@@ -2,14 +2,14 @@
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Gift } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import type { BundleItem, BundleQuote, PublicBundle } from "@/types";
|
||||
import type { BasketItem } from "@/components/shared/CouponCodeField";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
const fmt = (n: number) => `R${n.toFixed(2)}`;
|
||||
|
||||
/**
|
||||
* The bundle deals a basket gets, from POST /api/bundles/quote (the server prices the
|
||||
* The bundle deals a basket gets, from POST /api/v2/bundles/quote (the server prices the
|
||||
* basket the same way registration will). Null while there's nothing to show. Pass
|
||||
* `enabled={false}` when the event has no bundles to skip the request.
|
||||
*
|
||||
@@ -35,7 +35,7 @@ export function useBundleQuote({ eventId, basket, token, forUserId, enabled = tr
|
||||
try {
|
||||
const body: Record<string, unknown> = { eventId, options };
|
||||
if (forUserId !== undefined) body.forUserId = forUserId;
|
||||
const res = await apiFetch<BundleQuote>("/api/bundles/quote", { method: "POST", authToken: token || undefined, body });
|
||||
const res = await (apiV2Data("post", "/bundles/quote", { authToken: token, body: body as never }) as Promise<BundleQuote>);
|
||||
if (!cancelled) setQuote(res.bundleDiscount > 0 ? res : null);
|
||||
} catch {
|
||||
if (!cancelled) setQuote(null);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { Users } from "lucide-react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useMyCampuses } from "@/hooks/useCampuses";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
/**
|
||||
* "Everyone at campus X" for the email/WhatsApp broadcast composers: adds the people whose
|
||||
@@ -27,7 +27,7 @@ export function CampusAudiencePicker({ selectedIds, onChange }: { selectedIds: s
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
try {
|
||||
const res = await apiFetch<{ campus: { name: string }; users: { id: string }[] }>(`/api/campuses/${campusId}/audience${registrants ? "?registrants=true" : ""}`, { authToken: token });
|
||||
const res = await (apiV2Data("get", "/campuses/{id}/audience", { params: { id: campusId }, query: { registrants: registrants ? "true" : "false" }, authToken: token }) as Promise<{ campus: { name: string }; users: { id: string }[] }>);
|
||||
const ids = res.users.map(u => u.id);
|
||||
const merged = Array.from(new Set([...selectedIds, ...ids]));
|
||||
onChange(merged);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user