Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { ApiError } from "@/app/lib/clientApi";
|
|
import { ErrorState } from "@/app/components/ui/states";
|
|
import { RequireModule } from "@/app/lib/RequireModule";
|
|
import { PageHeader } from "@/app/components/ui/page-header";
|
|
import { EventForm } from "@/app/components/events/EventForm";
|
|
import { saveAdminEvent } from "@/app/lib/services/adminEvents";
|
|
import type { AdminEventPayload } from "@/app/lib/types";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
function NewEventPageContent() {
|
|
const t = useT();
|
|
const router = useRouter();
|
|
|
|
async function handleSubmit(payload: AdminEventPayload) {
|
|
try {
|
|
const created = await saveAdminEvent(payload);
|
|
if (created.uuid) {
|
|
router.push(`/events/${created.uuid}?created=1`);
|
|
}
|
|
} catch (err) {
|
|
if (err instanceof ApiError) {
|
|
const data = err.data as { code?: string; details?: { eventUuid?: string } } | undefined;
|
|
if (data?.code === "TEAM_NOT_SAVED" && data.details?.eventUuid) {
|
|
router.push(`/events/${data.details.eventUuid}?teamNotSaved=1`);
|
|
return;
|
|
}
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<PageHeader title={t("EvtNewEvent")} />
|
|
<EventForm onSubmit={handleSubmit} submitLabel={t("Create")} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function NewEventPage() {
|
|
return (
|
|
<RequireModule pathname="/events">
|
|
<NewEventPageContent />
|
|
</RequireModule>
|
|
);
|
|
}
|