# Add the "Feedback Survey" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/feedback-survey) to this Pantheon Content Publisher (P1) Next.js project. Agree/disagree rating scales, a 0–10 recommend question, open comments and an opt-in follow-up email, all native radios.

## Steps

1. Create `components/puck/feedback-survey-block.tsx` with the exact file contents below. If `components/puck/` doesn't exist, find the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`) and put it there.
2. In `puck.config.tsx`, import it: `import { feedbackSurveyBlock } from "./components/puck/feedback-survey-block";`
3. Register it under `components` as `FeedbackSurveyBlock: feedbackSurveyBlock`.
4. Add `"FeedbackSurveyBlock"` to the best-fitting entry in `categories` (this block's library category is "Forms"). Create a category only if none fits.
5. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
6. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- Do not add dependencies. The block is self-contained by design: one type-only import from `@puckeditor/core`, Tailwind v4 classes, no client JavaScript.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/feedback-survey-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";

/**
 * Feedback Survey — agree/disagree rating scales, a 0–10 "would you recommend" question,
 * open comments and an optional follow-up email, all as native radios. Posts to any form endpoint.
 * Register: `FeedbackSurveyBlock: feedbackSurveyBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

export type FeedbackSurveyProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  formAction: string;
  statements: { text: string; name: string }[];
  scaleLabels: string;
  recommendQuestion: string;
  recommendLow: string;
  recommendHigh: string;
  commentsLabel: string;
  allowFollowUp: boolean;
  anonymityNote: string;
  submitLabel: string;
};

const inputClass =
  "block min-h-11 w-full rounded-lg border-0 bg-white px-3.5 py-2.5 text-base text-neutral-950 shadow-xs ring-1 ring-neutral-300 ring-inset placeholder:text-neutral-500 focus:ring-2 focus:ring-indigo-600 focus:outline-none";
const labelClass = "block text-sm leading-6 font-medium text-neutral-900";
const checkClass = "size-5 rounded border-neutral-400 accent-indigo-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";
const optional = <span className="font-normal text-neutral-600">(optional)</span>;

const DEFAULT_SCALE = ["Strongly disagree", "Disagree", "Neutral", "Agree", "Strongly agree"];
const slug = (s: string) =>
  (s || "")
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, "_")
    .replace(/^_+|_+$/g, "")
    .slice(0, 40);

export const feedbackSurveyBlock: ComponentConfig<FeedbackSurveyProps> = {
  label: "Feedback Survey",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
    heading: { type: "text", label: "Heading" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    intro: { type: "textarea", label: "Intro" },
    formAction: {
      type: "text",
      label: "Form action URL",
      metadata: {
        help: "Where the form is sent with POST. Each statement sends its field name with a value from 1 (first scale label) upward; also recommend (0–10), comments, follow_up and email.",
      },
    },
    statements: {
      type: "array",
      label: "Rating statements",
      min: 0,
      max: 10,
      getItemSummary: (item) => item?.text || "Statement",
      defaultItemProps: { text: "New statement", name: "" },
      arrayFields: {
        text: { type: "textarea", label: "Statement", metadata: { help: "Write it so people can agree or disagree, such as \"Staff were helpful\"." } },
        name: { type: "text", label: "Field name", metadata: { help: "How the answer is labelled in your results, such as staff_helpful. Leave blank to make one from the statement." } },
      },
    },
    scaleLabels: {
      type: "textarea",
      label: "Scale labels",
      metadata: { help: "One per line, lowest first. Three to seven labels work best. Leave blank for Strongly disagree to Strongly agree." },
    },
    recommendQuestion: { type: "text", label: "0–10 question", metadata: { help: "Leave blank to hide the 0–10 scale." } },
    recommendLow: { type: "text", label: "Label for 0" },
    recommendHigh: { type: "text", label: "Label for 10" },
    commentsLabel: { type: "text", label: "Comments question", metadata: { help: "Leave blank to hide the comments box." } },
    allowFollowUp: {
      type: "radio",
      label: "Offer a follow-up",
      options: [
        { label: "Yes", value: true },
        { label: "No", value: false },
      ],
      metadata: { help: "Adds an optional \"contact me about my answers\" checkbox and email field." },
    },
    anonymityNote: { type: "textarea", label: "Privacy note", metadata: { help: "Shown at the top of the form. Leave blank to hide it." } },
    submitLabel: { type: "text", label: "Button text" },
  },
  defaultProps: {
    eyebrow: "Visitor survey · 3 minutes",
    heading: "How was your visit to the library?",
    headingLevel: "h2",
    intro: "Your answers shape our hours, programs and how we spend next year's budget. Every response is read by our branch managers.",
    formAction: "/survey/visit",
    statements: [
      { text: "I found what I came for.", name: "found_it" },
      { text: "Staff were friendly and helpful.", name: "staff_helpful" },
      { text: "The building felt clean and comfortable.", name: "clean_comfortable" },
      { text: "Our open hours work for my schedule.", name: "hours_fit" },
    ],
    scaleLabels: "",
    recommendQuestion: "How likely are you to recommend the library to a friend or neighbor?",
    recommendLow: "Not at all likely",
    recommendHigh: "Extremely likely",
    commentsLabel: "What's one thing we could do better?",
    allowFollowUp: true,
    anonymityNote: "This survey is anonymous unless you choose to leave your email at the end.",
    submitLabel: "Submit survey",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, formAction, statements, scaleLabels, recommendQuestion, recommendLow, recommendHigh, commentsLabel, allowFollowUp, anonymityNote, submitLabel }) => {
    const H = headingLevel || "h2";
    const uid = `fs-${id || "form"}`;
    const custom = (scaleLabels || "").split("\n").map((l) => l.trim()).filter(Boolean);
    const scale = custom.length >= 2 ? custom.slice(0, 7) : DEFAULT_SCALE;
    const items = (statements ?? []).filter((s) => s?.text?.trim());
    const cols: Record<number, string> = { 2: "sm:grid-cols-2", 3: "sm:grid-cols-3", 4: "sm:grid-cols-4", 5: "sm:grid-cols-5", 6: "sm:grid-cols-6", 7: "sm:grid-cols-7" };
    const scaleCols = cols[scale.length] || "sm:grid-cols-5";
    const lowHint = [recommendLow ? `0 means ${recommendLow.toLowerCase()}` : "", recommendHigh ? `10 means ${recommendHigh.toLowerCase()}` : ""].filter(Boolean).join(", ");

    return (
      <section className="bg-neutral-50 px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-3xl">
          {eyebrow || heading || intro ? (
            <div className="text-center">
              {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-700 uppercase">{eyebrow}</p> : null}
              {heading ? <H className={`text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl ${eyebrow ? "mt-3" : ""}`}>{heading}</H> : null}
              {intro ? <p className="mx-auto mt-4 max-w-2xl text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
            </div>
          ) : null}

          <form action={formAction || undefined} method="post" className={`rounded-2xl bg-white p-6 shadow-sm ring-1 ring-neutral-200 sm:p-10 ${eyebrow || heading || intro ? "mt-10" : ""}`}>
            <div className="flex flex-col gap-1 border-b border-neutral-200 pb-6 text-sm leading-6 text-neutral-600 sm:flex-row sm:justify-between sm:gap-6">
              <p>All questions are optional. Skip any you&rsquo;d rather not answer.</p>
              {anonymityNote ? <p className="text-pretty sm:max-w-xs sm:text-right">{anonymityNote}</p> : null}
            </div>

            {items.length ? (
              <ol role="list" className="divide-y divide-neutral-200">
                {items.map((st, i) => {
                  const name = st.name?.trim() ? slug(st.name) : slug(st.text) || `q${i + 1}`;
                  return (
                    <li key={`${name}-${i}`} className="py-8">
                      <fieldset>
                        <legend className="flex gap-3 text-base leading-7 font-semibold text-neutral-950">
                          <span aria-hidden="true" className="text-indigo-700 tabular-nums">
                            {i + 1}.
                          </span>
                          <span>{st.text}</span>
                        </legend>
                        <div className={`mt-4 grid grid-cols-1 gap-2 sm:gap-0 sm:overflow-hidden sm:rounded-xl sm:ring-1 sm:ring-neutral-300 ${scaleCols}`}>
                          {scale.map((label, j) => (
                            <label
                              key={`${label}-${j}`}
                              className="relative flex min-h-11 cursor-pointer items-center gap-3 rounded-lg px-4 py-2 text-sm text-neutral-800 ring-1 ring-neutral-300 transition select-none ring-inset hover:bg-neutral-50 has-checked:bg-indigo-50 has-checked:font-semibold has-checked:text-indigo-950 has-checked:ring-2 has-checked:ring-indigo-600 has-focus-visible:z-10 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600 sm:flex-col sm:justify-center sm:gap-2 sm:rounded-none sm:px-2 sm:py-4 sm:text-center sm:text-xs sm:leading-4 sm:ring-0 sm:not-first:border-l sm:not-first:border-neutral-300 sm:has-checked:ring-2"
                            >
                              <input type="radio" name={name} value={String(j + 1)} className="size-5 shrink-0 accent-indigo-600 focus-visible:outline-none" />
                              {label}
                            </label>
                          ))}
                        </div>
                      </fieldset>
                    </li>
                  );
                })}
              </ol>
            ) : null}

            {recommendQuestion ? (
              <fieldset className="border-t border-neutral-200 py-8" aria-describedby={lowHint ? `${uid}-nps-hint` : undefined}>
                <legend className="float-left w-full text-base leading-7 font-semibold text-neutral-950">{recommendQuestion}</legend>
                {lowHint ? (
                  <p id={`${uid}-nps-hint`} className="sr-only">
                    {lowHint}.
                  </p>
                ) : null}
                <div className="clear-both flex flex-wrap gap-2 pt-4">
                  {Array.from({ length: 11 }, (_, n) => (
                    <label
                      key={n}
                      className="relative flex size-11 cursor-pointer items-center justify-center rounded-lg bg-white text-sm font-semibold text-neutral-800 ring-1 ring-neutral-300 transition select-none ring-inset tabular-nums hover:ring-indigo-400 has-checked:bg-indigo-600 has-checked:text-white has-checked:ring-indigo-600 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-indigo-600 sm:w-12"
                    >
                      <input type="radio" name="recommend" value={String(n)} className="sr-only" />
                      {n}
                    </label>
                  ))}
                </div>
                {recommendLow || recommendHigh ? (
                  <div aria-hidden="true" className="mt-3 flex max-w-xl justify-between gap-4 text-xs leading-5 text-neutral-600">
                    <span>0 · {recommendLow}</span>
                    <span className="text-right">10 · {recommendHigh}</span>
                  </div>
                ) : null}
              </fieldset>
            ) : null}

            {commentsLabel ? (
              <div className="border-t border-neutral-200 py-8">
                <label htmlFor={`${uid}-comments`} className="block text-base leading-7 font-semibold text-neutral-950">
                  {commentsLabel} {optional}
                </label>
                <textarea id={`${uid}-comments`} name="comments" rows={4} className={`mt-3 ${inputClass}`} />
              </div>
            ) : null}

            {allowFollowUp !== false ? (
              <div className="group/follow border-t border-neutral-200 py-8">
                <div className="flex gap-3">
                  <div className="flex h-11 shrink-0 items-center">
                    <input id={`${uid}-follow`} name="follow_up" type="checkbox" value="yes" aria-controls={`${uid}-email-wrap`} className={checkClass} />
                  </div>
                  <label htmlFor={`${uid}-follow`} className="flex min-h-11 cursor-pointer flex-col justify-center text-sm leading-6">
                    <span className="font-medium text-neutral-900">You can contact me about my answers</span>
                    <span className="text-neutral-600">We&rsquo;ll only use your email to follow up on this survey.</span>
                  </label>
                </div>
                <div id={`${uid}-email-wrap`} className="mt-4 hidden max-w-md group-has-checked/follow:block">
                  <label htmlFor={`${uid}-email`} className={labelClass}>
                    Email {optional}
                  </label>
                  <input id={`${uid}-email`} name="email" type="email" autoComplete="email" inputMode="email" className={`mt-2 ${inputClass}`} />
                </div>
              </div>
            ) : null}

            <div className="border-t border-neutral-200 pt-8">
              <button
                type="submit"
                className="inline-flex min-h-12 w-full items-center justify-center rounded-lg bg-indigo-600 px-6 py-3 text-base font-semibold text-white shadow-xs transition hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:w-auto"
              >
                {submitLabel || "Submit survey"}
              </button>
            </div>
          </form>
        </div>
      </section>
    );
  },
};
```
