"use client"; /** * The forms for each homepage section and block, from one description per type (the backend's * zod schemas in src/site/sections.ts check what's saved; field errors come back by path). */ import type { Focus } from "@/site/types"; import { FramingContext, type Framing } from "./framing"; import { ImagePicker } from "./media"; import { Btn, Field, inputClass } from "./ui"; type Spec = | { key: string; kind: "text" | "textarea"; label: string; hint?: string; max?: number } | { key: string; kind: "number"; label: string; min: number; max: number } | { key: string; kind: "image"; label: string } | { key: string; kind: "images"; label: string; max: number } | { key: string; kind: "button"; label: string } | { key: string; kind: "group"; label: string; fields: Spec[] }; const heading: Spec = { key: "heading", kind: "text", label: "Heading", max: 120 }; const button: Spec = { key: "button", kind: "button", label: "Button" }; export const SECTION_FIELDS: Record = { hero: { name: "Top of the page (hero)", fields: [ { key: "headline", kind: "text", label: "Headline", max: 120 }, { key: "subline", kind: "textarea", label: "Under the headline", max: 300 }, { key: "images", kind: "images", label: "Photos (the first for Photo and Split; up to three for Collage)", max: 3 }, button, ] }, serviceTimes: { name: "Service times and location", fields: [heading, { key: "note", kind: "textarea", label: "A note for visitors", hint: "The times and address come from your church profile.", max: 300 }] }, welcome: { name: "Welcome", fields: [ heading, { key: "mission", kind: "text", label: "Mission (one line)", max: 200 }, { key: "body", kind: "textarea", label: "Introduction", hint: "Leave an empty line between paragraphs.", max: 4000 }, { key: "imageId", kind: "image", label: "Photo (Image and text layout)" }, { key: "pastor", kind: "group", label: "Pastor's photo and quote (With pastor layout)", fields: [ { key: "name", kind: "text", label: "Name", max: 120 }, { key: "role", kind: "text", label: "Role", max: 80 }, { key: "quote", kind: "textarea", label: "Quote", max: 400 }, { key: "photoId", kind: "image", label: "Photo" }, ] }, ] }, ministries: { name: "Ministries", fields: [heading, { key: "intro", kind: "textarea", label: "Introduction", max: 400 }] }, team: { name: "Team", fields: [heading, { key: "intro", kind: "textarea", label: "Introduction", max: 400 }] }, events: { name: "Upcoming events", fields: [heading, { key: "count", kind: "number", label: "How many to show", min: 2, max: 12 }] }, latestMessage: { name: "Latest message", fields: [heading] }, invitation: { name: "Invitation", fields: [heading, { key: "text", kind: "textarea", label: "Text", max: 400 }, button, { key: "imageId", kind: "image", label: "Background photo (Image background layout)" }] }, }; export const BLOCK_FIELDS: Record = { text: { name: "Text", fields: [heading, { key: "body", kind: "textarea", label: "Text", hint: "Leave an empty line between paragraphs.", max: 20000 }] }, "image-text": { name: "Image and text", fields: [heading, { key: "body", kind: "textarea", label: "Text", max: 4000 }, { key: "imageId", kind: "image", label: "Photo" }, button] }, quote: { name: "Quote", fields: [{ key: "quote", kind: "textarea", label: "Quote", max: 600 }, { key: "by", kind: "text", label: "Who said it", max: 120 }] }, cta: { name: "Call to action", fields: [heading, { key: "text", kind: "textarea", label: "Text", max: 400 }, button] }, }; type Data = Record; /** * A section's or block's fields. With `frame` (the top-level form of a section), its photos show in * the shape of their frame on the site and can be moved and zoomed (saved in `data.framing`). */ export function DataForm({ fields, value, onChange, errors, prefix = "", frame }: { fields: Spec[]; value: Data; onChange: (v: Data) => void; errors: Record; prefix?: string; frame?: Framing["frame"] }) { const set = (k: string, v: unknown) => onChange({ ...value, [k]: v }); const form = (
{fields.map((f) => { const err = errors[`${prefix}${f.key}`]; const v = value[f.key]; switch (f.kind) { case "text": return set(f.key, e.target.value || null)} />; case "textarea": return