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:
@@ -5,10 +5,11 @@ import { Navbar } from "@/components/layout/Navbar";
|
||||
import { Footer } from "@/components/layout/Footer";
|
||||
import { EventCard } from "@/components/events/EventCard";
|
||||
import { ApiImage } from "@/components/shared/ApiImage";
|
||||
import { apiFetch, apiFetchListForPrerender, ApiError } from "@/lib/api";
|
||||
import { apiFetchListForPrerender, ApiError } from "@/lib/api";
|
||||
import { mapsSearchUrl } from "@/lib/maps";
|
||||
import { CalendarX, MapPin, Mail, Phone, User, ArrowLeft } from "lucide-react";
|
||||
import type { Campus } from "@/hooks/useCampuses";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
@@ -16,7 +17,7 @@ type Event = React.ComponentProps<typeof EventCard>["event"] & { cashupStatus?:
|
||||
|
||||
async function loadCampus(slug: string): Promise<Campus | null> {
|
||||
try {
|
||||
return await apiFetch<Campus>(`/api/campuses/by-slug/${encodeURIComponent(slug)}`, { nextOptions: { next: { revalidate } } });
|
||||
return await (apiV2Data("get", "/campuses/by-slug/{slug}", { params: { slug }, nextOptions: { next: { revalidate } } }) as Promise<Campus>);
|
||||
} catch (e) {
|
||||
// 404: no such campus, archived, or campuses are off.
|
||||
if (e instanceof ApiError && e.status === 404) return null;
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { apiFetch, fetchManagedEvents } from "@/lib/api";
|
||||
import { fetchManagedEvents } from "@/lib/api";
|
||||
import { useDismissingState } from "@/hooks/useDismissingState";
|
||||
import { Gift, Plus, X, Trash2, Pencil, Power, CalendarClock } from "lucide-react";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { BackLink } from "@/components/shared/BackLink";
|
||||
import type { BundleGroupPricing, BundleKind, EventBundle } from "@/types";
|
||||
import { EventPicker, defaultEventId } from "@/components/shared/EventPicker";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type OptionLite = { id: string; name: string; price: number; variants?: { id: string; name: string; price?: number | null }[] };
|
||||
type EventLite = { id: string; title: string; startDate: string; endDate?: string; eventOptions: OptionLite[] };
|
||||
@@ -118,7 +119,7 @@ export default function BundlesPage() {
|
||||
if (!token || !eventId) { setBundles([]); return; }
|
||||
setFetching(true);
|
||||
try {
|
||||
setBundles(await apiFetch<EventBundle[]>(`/api/bundles/event/${eventId}`, { authToken: token }) || []);
|
||||
setBundles(await (apiV2Data("get", "/events/{id}/bundles", { params: { id: eventId }, authToken: token }) as Promise<EventBundle[]>));
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Failed to load bundles");
|
||||
} finally {
|
||||
@@ -130,7 +131,7 @@ export default function BundlesPage() {
|
||||
|
||||
const toggleActive = async (b: EventBundle) => {
|
||||
try {
|
||||
await apiFetch(`/api/bundles/${b.id}`, { method: "PUT", authToken: token!, body: { isActive: !b.isActive } });
|
||||
await apiV2Data("patch", "/bundles/{id}", { params: { id: b.id }, authToken: token, body: { isActive: !b.isActive } });
|
||||
setInfo(`${b.name} turned ${b.isActive ? "off" : "on"}.`);
|
||||
load();
|
||||
} catch (e) {
|
||||
@@ -141,7 +142,7 @@ export default function BundlesPage() {
|
||||
const remove = async (b: EventBundle) => {
|
||||
if (!window.confirm(`Delete "${b.name}"?`)) return;
|
||||
try {
|
||||
const res = await apiFetch<{ message: string }>(`/api/bundles/${b.id}`, { method: "DELETE", authToken: token! });
|
||||
const res = await (apiV2Data("delete", "/bundles/{id}", { params: { id: b.id }, authToken: token }) as Promise<{ message: string }>);
|
||||
setInfo(res?.message || "Bundle deleted");
|
||||
load();
|
||||
} catch (e) {
|
||||
@@ -357,10 +358,10 @@ function BundleModal({ token, event, bundleId, initial, onClose, onSaved }: {
|
||||
isActive: d.isActive,
|
||||
};
|
||||
if (bundleId) {
|
||||
await apiFetch(`/api/bundles/${bundleId}`, { method: "PUT", authToken: token, body });
|
||||
await apiV2Data("patch", "/bundles/{id}", { params: { id: bundleId }, authToken: token, body: body as never });
|
||||
onSaved(`${body.name} saved.`);
|
||||
} else {
|
||||
await apiFetch(`/api/bundles/event/${event.id}`, { method: "POST", authToken: token, body });
|
||||
await apiV2Data("post", "/events/{id}/bundles", { params: { id: event.id }, authToken: token, body: body as never });
|
||||
onSaved(`${body.name} created.`);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useDismissingState } from "@/hooks/useDismissingState";
|
||||
import { TicketPercent, Plus, X, Search, Pencil, Power, Users, CalendarClock, ListChecks } from "lucide-react";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { BackLink } from "@/components/shared/BackLink";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type CouponType = "percent" | "fixed" | "comp";
|
||||
type Role = "user" | "staff" | "supervisor" | "admin";
|
||||
@@ -163,7 +164,7 @@ export default function CouponsPage() {
|
||||
setFetching(true);
|
||||
try {
|
||||
const [c, ev] = await Promise.all([
|
||||
apiFetch<Coupon[]>("/api/coupons", { authToken: token }),
|
||||
(apiV2Data("get", "/coupons", { authToken: token }) as Promise<Coupon[]>),
|
||||
fetchManagedEvents<EventLite>(token, { past: true }),
|
||||
]);
|
||||
setCoupons(c || []);
|
||||
@@ -191,7 +192,7 @@ export default function CouponsPage() {
|
||||
|
||||
const toggleActive = async (c: Coupon) => {
|
||||
try {
|
||||
await apiFetch(`/api/coupons/${c.id}`, { method: "PUT", authToken: token!, body: { active: !c.active } });
|
||||
await apiV2Data("patch", "/coupons/{id}", { params: { id: c.id }, authToken: token, body: { active: !c.active } });
|
||||
setInfo(`${c.code} turned ${c.active ? "off" : "on"}.`);
|
||||
load();
|
||||
} catch (e) {
|
||||
@@ -201,7 +202,7 @@ export default function CouponsPage() {
|
||||
|
||||
const openUses = async (c: Coupon) => {
|
||||
try {
|
||||
const full = await apiFetch<Coupon & { redemptions: Redemption[] }>(`/api/coupons/${c.id}`, { authToken: token! });
|
||||
const full = await (apiV2Data("get", "/coupons/{id}", { params: { id: c.id }, authToken: token }) as Promise<Coupon & { redemptions: Redemption[] }>);
|
||||
setViewing({ coupon: c, redemptions: full.redemptions || [] });
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Failed to load uses");
|
||||
@@ -473,10 +474,10 @@ function CouponModal({ token, events, couponId, initial, onClose, onSaved }: {
|
||||
try {
|
||||
const body = bodyFromDraft(d);
|
||||
if (couponId) {
|
||||
await apiFetch(`/api/coupons/${couponId}`, { method: "PUT", authToken: token, body });
|
||||
await apiV2Data("patch", "/coupons/{id}", { params: { id: couponId }, authToken: token, body: body as never });
|
||||
onSaved(`${body.code.toUpperCase()} saved.`);
|
||||
} else {
|
||||
await apiFetch(`/api/coupons`, { method: "POST", authToken: token, body });
|
||||
await apiV2Data("post", "/coupons", { authToken: token, body: body as never });
|
||||
onSaved(`${body.code.toUpperCase()} created.`);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
} from "@/components/events/ScheduleEditor";
|
||||
import { toSessionDraft, scheduleSummary } from "@/lib/sessions";
|
||||
import { fetchApiFile, openBlob } from "@/lib/export";
|
||||
import { apiV2 } from "@/lib/apiV2";
|
||||
import { apiV2, apiV2Data } from "@/lib/apiV2";
|
||||
import { createTicketOption, updateTicketOption, listSections, createSection, updateSection, deleteSection, listAttachments, uploadAttachment, deleteAttachment, uploadImage } from "@/lib/eventSetup";
|
||||
|
||||
// ─── helpers ────────────────────────────────────────────────────────────────
|
||||
@@ -959,7 +959,7 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
const [seriesList, setSeriesList] = useState<EventSeries[]>([]);
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
apiFetch<EventSeries[]>("/api/series", { authToken: token }).then(l => setSeriesList(Array.isArray(l) ? l : [])).catch(() => {});
|
||||
(apiV2Data("get", "/series", { authToken: token }) as Promise<EventSeries[]>).then(l => setSeriesList(l)).catch(() => {});
|
||||
}, [token]);
|
||||
|
||||
// ── multi-day schedule + attendance settings ──
|
||||
|
||||
@@ -5,12 +5,12 @@ import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Layers, ExternalLink, Users, BarChart3 } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import { BackLink } from "@/components/shared/BackLink";
|
||||
import { CampusBadge } from "@/components/shared/CampusFilter";
|
||||
import { SeasonPassesPanel } from "@/components/series/SeasonPassesPanel";
|
||||
import type { EventSeries } from "@/types";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type Draft = { id?: string; name: string; slug: string; description: string; picture: string };
|
||||
const blank: Draft = { name: "", slug: "", description: "", picture: "" };
|
||||
@@ -69,7 +69,7 @@ export default function SeriesPage() {
|
||||
const load = useCallback(async () => {
|
||||
if (!token) return;
|
||||
try {
|
||||
setList(await apiFetch<EventSeries[]>("/api/series", { authToken: token }));
|
||||
setList(await (apiV2Data("get", "/series", { authToken: token }) as Promise<EventSeries[]>));
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Couldn't load the series");
|
||||
}
|
||||
@@ -81,7 +81,8 @@ export default function SeriesPage() {
|
||||
setSaving(true); setError(null); setNotice(null);
|
||||
try {
|
||||
const body = { name: draft.name, slug: draft.slug || undefined, description: draft.description, picture: draft.picture };
|
||||
await apiFetch(draft.id ? `/api/series/${draft.id}` : "/api/series", { method: draft.id ? "PUT" : "POST", authToken: token || undefined, body });
|
||||
if (draft.id) await apiV2Data("patch", "/series/{id}", { params: { id: draft.id }, authToken: token, body: body as never });
|
||||
else await apiV2Data("post", "/series", { authToken: token, body: body as never });
|
||||
setNotice(draft.id ? "Series saved." : `"${draft.name.trim()}" created — choose it in the event editor to add events.`);
|
||||
setDraft(null);
|
||||
await load();
|
||||
@@ -96,7 +97,7 @@ export default function SeriesPage() {
|
||||
if (!window.confirm(`Delete "${s.name}"? Its ${s.eventCount} event${s.eventCount === 1 ? "" : "s"} stay, just without a series, and ${s.followers} follower${s.followers === 1 ? "" : "s"} won't hear about new ones.`)) return;
|
||||
setError(null); setNotice(null);
|
||||
try {
|
||||
await apiFetch(`/api/series/${s.id}`, { method: "DELETE", authToken: token || undefined });
|
||||
await apiV2Data("delete", "/series/{id}", { params: { id: s.id }, authToken: token });
|
||||
setNotice(`"${s.name}" deleted.`);
|
||||
await load();
|
||||
} catch (e) {
|
||||
|
||||
@@ -9,10 +9,11 @@ import { CampusBadge } from "@/components/shared/CampusFilter";
|
||||
import { FollowSeriesButton } from "@/components/events/FollowSeriesButton";
|
||||
import { SeasonPassOffers } from "@/components/series/SeasonPassOffers";
|
||||
import { Suspense } from "react";
|
||||
import { apiFetch, apiFetchListForPrerender, ApiError } from "@/lib/api";
|
||||
import { apiFetchListForPrerender, ApiError } from "@/lib/api";
|
||||
import { formatDateTimeRange } from "@/lib/date";
|
||||
import { ArrowLeft, CalendarX, Layers } from "lucide-react";
|
||||
import type { Event as FullEvent, SeasonPassView } from "@/types";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
@@ -22,7 +23,7 @@ type Series = { id: string; name: string; slug: string; description: string | nu
|
||||
|
||||
async function loadSeries(slug: string): Promise<Series | null> {
|
||||
try {
|
||||
return await apiFetch<Series>(`/api/series/by-slug/${encodeURIComponent(slug)}`, { nextOptions: { next: { revalidate } } });
|
||||
return await (apiV2Data("get", "/series/by-slug/{slug}", { params: { slug }, nextOptions: { next: { revalidate } } }) as Promise<Series>);
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.status === 404) return null;
|
||||
throw e;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { appUrl } from "@/lib/siteConfig";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
|
||||
type Event = { id: string; updatedAt?: string; startDate: string };
|
||||
|
||||
@@ -26,7 +27,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
// Campus pages, while campuses are on (the list is empty otherwise).
|
||||
let campuses: { slug: string }[] = [];
|
||||
try {
|
||||
campuses = (await apiFetch<{ campuses: { slug: string }[] }>("/api/campuses", { nextOptions: { next: { revalidate } } })).campuses || [];
|
||||
campuses = (await (apiV2Data("get", "/campuses", { nextOptions: { next: { revalidate } } }) as Promise<{ campuses: { slug: string }[] }>)).campuses || [];
|
||||
} catch {
|
||||
// Same as events above.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user