Pages list and Tiptap editor (ported from babyboo) with image upload on save, the FORM event picker, field errors at their fields, delete confirmation, unsaved-edits guard and a draft preview. The public page /p/<company>/<slug> renders on the server with metadata, sanitize-html, the company's logo and accent, and the sign-up form with UTM tags. Companies get branding; the event lead detail shows the web page and campaign. Labels in English and Chinese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
38 lines
2.1 KiB
TypeScript
38 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { AlertCircle, CheckCircle2 } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { VisitorState } from "@/app/components/registration/VisitorCard";
|
|
import { RegistrationForm } from "@/app/components/registration/RegistrationForm";
|
|
import { publicCall, type RegistrationBody, type RegistrationInfo } from "@/app/lib/services/publicRegistration";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
const UTM = ["utm_source", "utm_medium", "utm_campaign"] as const;
|
|
|
|
/** The page address's UTM tags, as the submit body names them. */
|
|
export function utmTags(search: string): { utmSource?: string; utmMedium?: string; utmCampaign?: string } {
|
|
const q = new URLSearchParams(search);
|
|
const [utmSource, utmMedium, utmCampaign] = UTM.map((k) => q.get(k)?.slice(0, 100) || undefined);
|
|
return { utmSource, utmMedium, utmCampaign };
|
|
}
|
|
|
|
// A landing page's FORM block: the QR sign-up form, posting to the page's block, with the visitor's UTM tags.
|
|
export function LandingForm({ companyCode, slug, index, info, preview }: { companyCode: string; slug: string; index: number; info?: RegistrationInfo; preview?: boolean }) {
|
|
const t = useT();
|
|
const [phase, setPhase] = useState<"form" | "done" | "closed">(info ? "form" : "closed");
|
|
|
|
if (preview) return <VisitorState icon={AlertCircle} heading={t("PagesFormPreview")} role="status" />;
|
|
if (phase === "closed" || !info) return <VisitorState icon={AlertCircle} heading={t("PagesFormClosed")} role="status" />;
|
|
if (phase === "done") {
|
|
return <VisitorState icon={CheckCircle2} heading={t("RegThanks", { event: info.eventName })} role="status"
|
|
action={<Button className="h-11" onClick={() => setPhase("form")}>{t("RegAnother")}</Button>} />;
|
|
}
|
|
const submit = (body: RegistrationBody) =>
|
|
publicCall(`/api/public/pages/${encodeURIComponent(companyCode)}/${encodeURIComponent(slug)}/form/${index}`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ ...body, ...utmTags(window.location.search) }),
|
|
});
|
|
return <RegistrationForm info={info} submit={submit} onDone={() => setPhase("done")} onInactive={() => setPhase("closed")} />;
|
|
}
|