# Add the "Volunteer Shifts" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/volunteer-shifts) to this Pantheon Content Publisher (P1) Next.js project. Upcoming volunteer shift schedule with date, time, site, role, spots left and sign-up links, plus a group note.

## Steps

1. Create `components/puck/volunteer-shifts-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 { volunteerShiftsBlock } from "./components/puck/volunteer-shifts-block";`
3. Register it under `components` as `VolunteerShiftsBlock: volunteerShiftsBlock`.
4. Add `"VolunteerShiftsBlock"` to the best-fitting entry in `categories` (this block's library category is "Nonprofit"). 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/volunteer-shifts-block.tsx`

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

/**
 * Volunteer Shifts — an upcoming shift schedule (date, time, site, role, spots left) with a
 * sign-up link per shift. A real table on wide screens, stacked cards on phones; full
 * shifts are marked and lose their link. Ends with a note for group volunteering.
 * Register: `VolunteerShiftsBlock: volunteerShiftsBlock` in puck.config.tsx.
 */

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

export type VolunteerShiftsProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  caption: string;
  shifts: { date: string; time: string; site: string; role: string; spots: string; href: string }[];
  signUpLabel: string;
  fullLabel: string;
  fewLeftAt: string;
  groupHeading: string;
  groupText: string;
  groupLabel: string;
  groupHref: string;
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };

const toInt = (v?: string) => {
  const n = parseInt(String(v ?? "").replace(/[^0-9-]/g, ""), 10);
  return Number.isFinite(n) ? n : null;
};

const parseDate = (d: string) => {
  const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(d || "");
  if (!m) return null;
  const date = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));
  return Number.isNaN(date.getTime()) ? null : date;
};

const fmt = (date: Date, opts: Intl.DateTimeFormatOptions) => date.toLocaleDateString("en-US", { ...opts, timeZone: "UTC" });

const arrow = "M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z";

export const volunteerShiftsBlock: ComponentConfig<VolunteerShiftsProps> = {
  label: "Volunteer Shifts",
  fields: {
    heading: { type: "textarea", 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" },
    caption: { type: "text", label: "Table caption", metadata: { help: "Read to screen reader users, like Upcoming shifts, October. Shown small above the schedule." } },
    shifts: {
      type: "array",
      label: "Shifts",
      min: 0,
      max: 30,
      getItemSummary: (item) => [item?.date, item?.role].filter(Boolean).join(" · ") || "Shift",
      defaultItemProps: { date: "2026-10-20", time: "9:00 a.m.–12:00 p.m.", site: "Main warehouse", role: "Sorting", spots: "10", href: "/volunteer/signup" },
      arrayFields: {
        date: { type: "text", label: "Date", metadata: { help: "Use YYYY-MM-DD, like 2026-10-20. Shown with the weekday." } },
        time: { type: "text", label: "Time", metadata: { help: "Like 9:00 a.m.–12:00 p.m." } },
        site: { type: "text", label: "Site" },
        role: { type: "text", label: "Role" },
        spots: { type: "text", label: "Spots left", metadata: { help: "A number. 0 marks the shift full. Bind to a data source to keep it live." } },
        href: { type: "text", label: "Sign-up link" },
      },
      metadata: { help: "List shifts in date order. Remove past shifts, or bind this list to your scheduling tool." },
    },
    signUpLabel: { type: "text", label: "Sign-up link text", metadata: { help: "Like Sign up. The shift's role and date are added for screen readers." } },
    fullLabel: { type: "text", label: "Full shift text", metadata: { help: "Shown instead of the link when no spots are left." } },
    fewLeftAt: { type: "text", label: "Few-spots threshold", metadata: { help: "Highlight shifts with this many spots or fewer, like 3. Leave blank to turn off." } },
    groupHeading: { type: "text", label: "Group note heading", metadata: { help: "Leave blank and clear the text to hide the group note." } },
    groupText: { type: "textarea", label: "Group note text" },
    groupLabel: { type: "text", label: "Group link text" },
    groupHref: { type: "text", label: "Group link" },
  },
  defaultProps: {
    heading: "Pick a shift",
    headingLevel: "h2",
    intro: "No experience needed. Wear closed-toe shoes, and we'll handle the rest: gloves, aprons, training and snacks. Volunteers must be 14 or older; under-16s come with an adult.",
    caption: "Upcoming volunteer shifts",
    shifts: [
      { date: "2026-10-13", time: "9:00 a.m.–12:00 p.m.", site: "Larkspur distribution center", role: "Food sorting", spots: "8", href: "/volunteer/signup?shift=1013-sort" },
      { date: "2026-10-14", time: "4:00–6:30 p.m.", site: "Eastside mobile pantry", role: "Client greeter", spots: "2", href: "/volunteer/signup?shift=1014-greet" },
      { date: "2026-10-16", time: "1:00–4:00 p.m.", site: "Larkspur distribution center", role: "Senior box packing", spots: "0", href: "/volunteer/signup?shift=1016-pack" },
      { date: "2026-10-17", time: "8:30–11:30 a.m.", site: "Westgate community garden", role: "Harvest and gleaning", spots: "12", href: "/volunteer/signup?shift=1017-glean" },
      { date: "2026-10-20", time: "9:00 a.m.–12:00 p.m.", site: "Larkspur distribution center", role: "Food sorting", spots: "15", href: "/volunteer/signup?shift=1020-sort" },
    ],
    signUpLabel: "Sign up",
    fullLabel: "Full",
    fewLeftAt: "3",
    groupHeading: "Bringing a group of 6 or more?",
    groupText: "We host company, school and congregation teams on weekday mornings. Book two weeks ahead and we'll reserve a private shift.",
    groupLabel: "Request a group shift",
    groupHref: "/volunteer/groups",
  },
  render: ({ id, heading, headingLevel, intro, caption, shifts, signUpLabel, fullLabel, fewLeftAt, groupHeading, groupText, groupLabel, groupHref }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] ?? "h3";
    const signUp = signUpLabel || "Sign up";
    const full = fullLabel || "Full";
    const threshold = toInt(fewLeftAt);
    const uid = id || "shifts";

    const rows = (shifts ?? [])
      .filter((s) => s?.date || s?.role)
      .map((s) => {
        const date = parseDate(s.date);
        const spots = toInt(s.spots);
        return {
          ...s,
          iso: date ? s.date : undefined,
          weekday: date ? fmt(date, { weekday: "short" }) : "",
          day: date ? fmt(date, { month: "short", day: "numeric" }) : s.date || "",
          long: date ? fmt(date, { weekday: "long", month: "long", day: "numeric" }) : s.date || "",
          spots,
          isFull: spots !== null && spots <= 0,
          isFew: spots !== null && spots > 0 && threshold !== null && spots <= threshold,
        };
      });

    const Spots = ({ r }: { r: (typeof rows)[number] }) =>
      r.isFull ? (
        <span className="inline-flex items-center gap-1.5 text-sm font-semibold text-neutral-600">
          <span aria-hidden="true" className="size-2 rounded-full bg-neutral-400" />
          {full}
        </span>
      ) : r.spots !== null ? (
        <span className={`inline-flex items-center gap-1.5 text-sm tabular-nums ${r.isFew ? "font-semibold text-indigo-800" : "text-neutral-700"}`}>
          <span aria-hidden="true" className={`size-2 rounded-full ${r.isFew ? "bg-indigo-600" : "bg-indigo-300"}`} />
          {r.spots} {r.spots === 1 ? "spot" : "spots"}
          {r.isFew ? <span className="text-xs font-semibold tracking-wide uppercase">· filling</span> : null}
        </span>
      ) : (
        <span className="text-sm text-neutral-600">—</span>
      );

    const Action = ({ r, block }: { r: (typeof rows)[number]; block?: boolean }) =>
      r.isFull ? (
        <span className={`inline-flex min-h-11 items-center justify-center rounded-lg bg-neutral-100 px-4 text-sm font-semibold text-neutral-600 ${block ? "w-full" : ""}`}>
          {full}
          <span className="sr-only">: no spots left</span>
        </span>
      ) : (
        <a
          href={r.href || "#"}
          className={`group inline-flex min-h-11 items-center justify-center gap-2 rounded-lg bg-indigo-600 px-4 text-sm font-semibold whitespace-nowrap text-white transition hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 ${block ? "w-full" : ""}`}
        >
          {signUp}
          <span className="sr-only">
            : {r.role}, {r.long}
          </span>
          <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 transition group-hover:translate-x-0.5">
            <path fillRule="evenodd" d={arrow} clipRule="evenodd" />
          </svg>
        </a>
      );

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

          {rows.length ? (
            <div className="mt-12 lg:mt-14">
              <table className="hidden w-full text-left md:table">
                {caption ? <caption className="pb-4 text-left text-sm font-semibold text-neutral-950">{caption}</caption> : null}
                <thead>
                  <tr className="border-b border-neutral-300 text-xs font-semibold tracking-wide text-neutral-600 uppercase">
                    <th scope="col" className="py-3 pr-4">Date</th>
                    <th scope="col" className="px-4 py-3">Time</th>
                    <th scope="col" className="px-4 py-3">Role</th>
                    <th scope="col" className="px-4 py-3">Site</th>
                    <th scope="col" className="px-4 py-3">Spots left</th>
                    <th scope="col" className="py-3 pl-4 text-right">
                      <span className="sr-only">Sign up</span>
                    </th>
                  </tr>
                </thead>
                <tbody className="divide-y divide-neutral-200">
                  {rows.map((r, i) => (
                    <tr key={`${r.date}-${r.role}-${i}`} className={r.isFull ? "text-neutral-600" : "text-neutral-950"}>
                      <th scope="row" className="py-4 pr-4 align-middle font-normal">
                        <time dateTime={r.iso} className="flex items-baseline gap-2">
                          {r.weekday ? <span className="w-9 text-xs font-semibold tracking-wide text-indigo-700 uppercase">{r.weekday}</span> : null}
                          <span className="font-semibold whitespace-nowrap tabular-nums">{r.day}</span>
                        </time>
                      </th>
                      <td className="px-4 py-4 text-sm whitespace-nowrap tabular-nums">{r.time}</td>
                      <td className="px-4 py-4 text-sm font-semibold">{r.role}</td>
                      <td className="px-4 py-4 text-sm text-neutral-600">{r.site}</td>
                      <td className="px-4 py-4">
                        <Spots r={r} />
                      </td>
                      <td className="py-3 pl-4 text-right">
                        <Action r={r} />
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>

              <div className="md:hidden">
                {caption ? (
                  <p id={`${uid}-caption`} className="text-sm font-semibold text-neutral-950">
                    {caption}
                  </p>
                ) : null}
                <ul role="list" aria-labelledby={caption ? `${uid}-caption` : undefined} className={`grid grid-cols-1 gap-3 ${caption ? "mt-4" : ""}`}>
                  {rows.map((r, i) => (
                    <li key={`${r.date}-${r.role}-${i}`} className={`rounded-xl p-4 ring-1 ring-inset ${r.isFull ? "bg-neutral-50 ring-neutral-200" : "bg-white ring-neutral-300"}`}>
                      <div className="flex items-start gap-4">
                        <time dateTime={r.iso} className="flex w-14 shrink-0 flex-col items-center rounded-lg bg-indigo-50 py-2 text-center">
                          {r.weekday ? <span className="text-xs font-semibold tracking-wide text-indigo-700 uppercase">{r.weekday}</span> : null}
                          <span className="text-sm font-semibold text-neutral-950 tabular-nums">{r.day}</span>
                        </time>
                        <div className="min-w-0 flex-1">
                          {r.role ? <p className="font-semibold text-neutral-950">{r.role}</p> : null}
                          <dl className="mt-1 space-y-0.5 text-sm text-neutral-600">
                            {r.time ? (
                              <div>
                                <dt className="sr-only">Time</dt>
                                <dd className="tabular-nums">{r.time}</dd>
                              </div>
                            ) : null}
                            {r.site ? (
                              <div>
                                <dt className="sr-only">Site</dt>
                                <dd>{r.site}</dd>
                              </div>
                            ) : null}
                            <div className="pt-1">
                              <dt className="sr-only">Spots left</dt>
                              <dd>
                                <Spots r={r} />
                              </dd>
                            </div>
                          </dl>
                        </div>
                      </div>
                      <div className="mt-4">
                        <Action r={r} block />
                      </div>
                    </li>
                  ))}
                </ul>
              </div>
            </div>
          ) : null}

          {groupHeading || groupText ? (
            <aside aria-labelledby={groupHeading ? `${uid}-group` : undefined} className="mt-12 flex flex-col gap-5 rounded-2xl bg-neutral-50 p-6 ring-1 ring-neutral-200 sm:flex-row sm:items-center sm:justify-between sm:gap-8 sm:p-8">
              <div className="flex items-start gap-4">
                <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" className="size-8 shrink-0 text-indigo-700">
                  <path d="M18 18.72a9.094 9.094 0 0 0 3.741-.479 3 3 0 0 0-4.682-2.72m.94 3.198.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0 1 12 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 0 1 6 18.719m12 0a5.971 5.971 0 0 0-.941-3.197m0 0A5.995 5.995 0 0 0 12 12.75a5.995 5.995 0 0 0-5.058 2.772m0 0a3 3 0 0 0-4.681 2.72 8.986 8.986 0 0 0 3.74.477m.94-3.197a5.971 5.971 0 0 0-.94 3.197M15 6.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm6 3a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Zm-13.5 0a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Z" />
                </svg>
                <div>
                  {groupHeading ? (
                    <Sub id={`${uid}-group`} className="text-base font-semibold text-neutral-950">
                      {groupHeading}
                    </Sub>
                  ) : null}
                  {groupText ? <p className="mt-1 text-sm leading-6 text-pretty text-neutral-600">{groupText}</p> : null}
                </div>
              </div>
              {groupLabel ? (
                <a
                  href={groupHref || "#"}
                  className="inline-flex min-h-11 shrink-0 items-center justify-center rounded-lg bg-white px-4 text-sm font-semibold text-neutral-950 ring-1 ring-neutral-300 transition ring-inset hover:ring-indigo-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                >
                  {groupLabel}
                </a>
              ) : null}
            </aside>
          ) : null}
        </div>
      </section>
    );
  },
};
```
