Archived
Setting events up on API v2, pg-boss 11 (1.51.7)
- v2: /events/manage, create, PATCH, deactivate, copy-from, notify-recipients. - src/services/events.ts (from eventController.js, with the schedule helpers); v1 uses it. - fetchManagedEvents() for every picker; the event wizard writes through v2. - pg-boss 11 in its own schema (pgboss_v11); old pgboss schema left in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
@@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useSta
|
||||
import { createPortal } from "react-dom";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { apiFetch, API_BASE } from "@/lib/api";
|
||||
import { apiFetch, API_BASE, fetchManagedEvents } from "@/lib/api";
|
||||
import { ApiImage } from "@/components/shared/ApiImage";
|
||||
import { useDismissingState } from "@/hooks/useDismissingState";
|
||||
import { useSiteSettings } from "@/contexts/SiteSettingsContext";
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from "@/components/events/ScheduleEditor";
|
||||
import { toSessionDraft, scheduleSummary } from "@/lib/sessions";
|
||||
import { fetchApiFile, openBlob } from "@/lib/export";
|
||||
import { apiV2 } from "@/lib/apiV2";
|
||||
|
||||
// ─── helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -776,8 +777,8 @@ function NotifyRecipientsManager({ eventId, creator, initialRecipients }: { even
|
||||
(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await apiFetch<NotifyUser[]>(`/api/events/${eventId}/notify-recipients`, { authToken: token || undefined });
|
||||
if (!cancelled) setSelected(Array.isArray(res) ? res : []);
|
||||
const { data: res } = await apiV2("get", "/events/{id}/notify-recipients", { params: { id: eventId }, authToken: token });
|
||||
if (!cancelled) setSelected(res);
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(errorMessage(e) || "Failed to load notification recipients");
|
||||
} finally {
|
||||
@@ -794,10 +795,7 @@ function NotifyRecipientsManager({ eventId, creator, initialRecipients }: { even
|
||||
setSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
await apiFetch(`/api/events/${eventId}/notify-recipients`, {
|
||||
method: "PUT", authToken: token || undefined,
|
||||
body: { userIds: next.map(u => u.id) },
|
||||
});
|
||||
await apiV2("put", "/events/{id}/notify-recipients", { params: { id: eventId }, authToken: token, body: { userIds: next.map(u => u.id) } });
|
||||
} catch (e) {
|
||||
setSelected(prev);
|
||||
setError(errorMessage(e) || "Failed to save notification recipients");
|
||||
@@ -1182,8 +1180,8 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
// Contact-only events have no ticket options to save — but a form (if any) still needs
|
||||
// saving in edit mode; for create mode the form is already included in the POST body.
|
||||
if (mode === "edit") {
|
||||
await apiFetch(`/api/events/${eventId}`, {
|
||||
method: "PUT", authToken: token || undefined,
|
||||
await apiV2("patch", "/events/{id}", {
|
||||
params: { id: eventId }, authToken: token,
|
||||
body: { form: { isRequired: !!formDef.isRequired, fields: formDef.fields.filter(f => f.label?.trim()).map((f, i) => ({ type: f.type, label: f.label, isRequired: !!f.isRequired, order: i, helpText: f.helpText || null, options: f.type === "multiple_choice" ? cleanChoices(f.options) : undefined })) } }
|
||||
});
|
||||
}
|
||||
@@ -1233,8 +1231,8 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
}
|
||||
|
||||
// Handle form save (edit only)
|
||||
await apiFetch(`/api/events/${eventId}`, {
|
||||
method: "PUT", authToken: token || undefined,
|
||||
await apiV2("patch", "/events/{id}", {
|
||||
params: { id: eventId }, authToken: token,
|
||||
body: { form: { isRequired: !!formDef.isRequired, fields: formDef.fields.filter(f => f.label?.trim()).map((f, i) => ({ type: f.type, label: f.label, isRequired: !!f.isRequired, order: i, helpText: f.helpText || null, options: f.type === "multiple_choice" ? cleanChoices(f.options) : undefined })) } }
|
||||
});
|
||||
} else {
|
||||
@@ -1412,24 +1410,24 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
if (mode === "edit") {
|
||||
body.isActive = draft.isActive;
|
||||
if (!ev) throw new Error("No event loaded to save");
|
||||
const saved = await apiFetch<Event & { sessionChanges?: { moved: number; cancelled: number } | null }>(`/api/events/${ev.id}`, { method: "PUT", authToken: token || undefined, body });
|
||||
const { data: saved } = await apiV2("patch", "/events/{id}", { params: { id: ev.id }, authToken: token, body });
|
||||
await saveOptions(ev.id);
|
||||
// Form is saved inside saveOptions for edit mode; avoid double call
|
||||
await saveFeedback(ev.id);
|
||||
const ch = saved?.sessionChanges;
|
||||
if (ch && (ch.moved > 0 || ch.cancelled > 0)) notice = { eventId: ev.id, moved: ch.moved, cancelled: ch.cancelled };
|
||||
const ch = saved.sessionChanges;
|
||||
if (ch && ((ch.moved ?? 0) > 0 || (ch.cancelled ?? 0) > 0)) notice = { eventId: ev.id, moved: ch.moved ?? 0, cancelled: ch.cancelled ?? 0 };
|
||||
} else {
|
||||
if (formDef.isRequired || formDef.fields.length > 0) {
|
||||
body.form = { isRequired: !!formDef.isRequired, fields: formDef.fields.filter(f => f.label?.trim()).map((f, i) => ({ type: f.type, label: f.label, isRequired: !!f.isRequired, order: i, helpText: f.helpText || null, options: f.type === "multiple_choice" ? cleanChoices(f.options) : undefined })) };
|
||||
}
|
||||
if (cloning) body.clonedFromId = source!.id;
|
||||
const created = await apiFetch<Event>("/api/events", { method: "POST", authToken: token || undefined, body });
|
||||
const { data: created } = await apiV2("post", "/events", { authToken: token, body: body as typeof body & { title: string; startDate: string; endDate: string } });
|
||||
if (created?.id) {
|
||||
await saveOptions(created.id);
|
||||
await saveFeedback(created.id);
|
||||
// Groups (and planned costs, for admins) aren't in this form; the server copies them.
|
||||
if (cloning) {
|
||||
await apiFetch(`/api/events/${created.id}/copy-from`, { method: "POST", authToken: token || undefined, body: { fromEventId: source!.id } });
|
||||
await apiV2("post", "/events/{id}/copy-from", { params: { id: created.id }, authToken: token, body: { fromEventId: source!.id } });
|
||||
}
|
||||
// Fetch event to get final option IDs for sections
|
||||
const fullEvent = await apiFetch<Event>(`/api/events/${created.id}`).catch(() => null);
|
||||
@@ -1443,10 +1441,7 @@ function EventModal({ mode, event: ev, source, onClose, onSuccess }: EventModalP
|
||||
}
|
||||
// Save staged notify recipients
|
||||
if (notifyRecipientDrafts.length > 0) {
|
||||
await apiFetch(`/api/events/${created.id}/notify-recipients`, {
|
||||
method: "PUT", authToken: token || undefined,
|
||||
body: { userIds: notifyRecipientDrafts.map(u => u.id) },
|
||||
}).catch(() => {});
|
||||
await apiV2("put", "/events/{id}/notify-recipients", { params: { id: created.id }, authToken: token, body: { userIds: notifyRecipientDrafts.map(u => u.id) } }).catch(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2061,7 +2056,7 @@ export default function ManageEventsPage() {
|
||||
if (!token) return;
|
||||
setLoadingEvents(true);
|
||||
try {
|
||||
const evs = await apiFetch<Event[]>("/api/events/all?includePast=true&includeInactive=true", { authToken: token });
|
||||
const evs = await fetchManagedEvents<Event>(token, { past: true, inactive: true });
|
||||
setEvents(Array.isArray(evs) ? evs.sort((a, b) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime()) : []);
|
||||
} catch (e) {
|
||||
setError(errorMessage(e) || "Failed to load events");
|
||||
|
||||
Reference in New Issue
Block a user