{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "approvals-queue",
  "title": "Approvals queue",
  "description": "Approval inbox for time off, refunds, discounts and schedule changes with approve, reject with a required reason, j/k/a/r keyboard navigation, a done tab and undo.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/avatar.json",
    "https://goodui.dev/r/button.json",
    "https://goodui.dev/r/kbd.json"
  ],
  "files": [
    {
      "path": "registry/blocks/tables/approvals-queue.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CalendarClock, Check, CircleDollarSign, Inbox, Percent, Undo2, X, type LucideIcon } from \"lucide-react\"\nimport { Avatar } from \"@/components/goodui/avatar\"\nimport { Button } from \"@/components/goodui/button\"\nimport { Kbd } from \"@/components/goodui/kbd\"\nimport { cn } from \"@/lib/utils\"\n\n/* ---------- Demo data ---------- */\n\ntype Kind = \"timeoff\" | \"refund\" | \"discount\" | \"schedule\"\ntype Request = { id: string; kind: Kind; who: string; title: string; detail: string; amount?: string; when: string; urgent?: boolean; status: \"pending\" | \"approved\" | \"rejected\"; reason?: string }\n\nconst KIND: Record<Kind, { label: string; icon: LucideIcon; cls: string }> = {\n  timeoff: { label: \"Time off\", icon: CalendarClock, cls: \"bg-sky-500/12 text-sky-700 dark:text-sky-300\" },\n  refund: { label: \"Refund\", icon: CircleDollarSign, cls: \"bg-rose-500/12 text-rose-700 dark:text-rose-300\" },\n  discount: { label: \"Discount\", icon: Percent, cls: \"bg-amber-500/12 text-amber-800 dark:text-amber-300\" },\n  schedule: { label: \"Schedule change\", icon: CalendarClock, cls: \"bg-violet-500/12 text-violet-700 dark:text-violet-300\" },\n}\n\nconst REQUESTS: Request[] = [\n  { id: \"r1\", kind: \"refund\", who: \"Priya Shah\", title: \"Refund Aisha Khan in full\", detail: \"Color came out uneven, she's a 5-year client. Offered a redo but she'd rather have the money back.\", amount: \"$185.00\", when: \"12 min ago\", urgent: true, status: \"pending\" },\n  { id: \"r2\", kind: \"timeoff\", who: \"Omar Haddad\", title: \"Nov 14–16 off\", detail: \"Brother's wedding in Austin. Diego can cover Saturday, Friday needs a walk-in only sign.\", when: \"1 hour ago\", status: \"pending\" },\n  { id: \"r3\", kind: \"discount\", who: \"Lena Park\", title: \"20% off for the Pilates Loft team\", detail: \"They're sending 8 people for gel manicures on Nov 9. Normal group discount is 10%.\", amount: \"−$96.00\", when: \"2 hours ago\", status: \"pending\" },\n  { id: \"r4\", kind: \"schedule\", who: \"Jonas Weber\", title: \"Switch to Tue–Sat from December\", detail: \"Wants Mondays off to study. Monday is our quietest day, Saturday coverage improves.\", when: \"Yesterday\", status: \"pending\" },\n  { id: \"r5\", kind: \"refund\", who: \"Diego Ramos\", title: \"Partial refund for Noah Fischer\", detail: \"Waited 35 minutes past his slot. Suggesting 30% back as goodwill.\", amount: \"$13.50\", when: \"Yesterday\", status: \"pending\" },\n  { id: \"r6\", kind: \"timeoff\", who: \"Maya Okafor\", title: \"Dec 23–27 off\", detail: \"Holiday travel. Booked out until the 22nd, no clients affected.\", when: \"2 days ago\", status: \"pending\" },\n]\n\nconst ring = \"outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-1 focus-visible:ring-offset-background\"\n\n/* ---------- Block ---------- */\n\nexport default function ApprovalsQueue() {\n  const [items, setItems] = React.useState(REQUESTS)\n  const [cursor, setCursor] = React.useState(0)\n  const [rejecting, setRejecting] = React.useState<string | null>(null)\n  const [reason, setReason] = React.useState(\"\")\n  const [reasonErr, setReasonErr] = React.useState(false)\n  const [tab, setTab] = React.useState<\"pending\" | \"done\">(\"pending\")\n  const [announce, setAnnounce] = React.useState(\"\")\n  const listRef = React.useRef<HTMLUListElement>(null)\n  const reasonRef = React.useRef<HTMLTextAreaElement>(null)\n\n  const pending = items.filter((i) => i.status === \"pending\")\n  const done = items.filter((i) => i.status !== \"pending\")\n  const shown = tab === \"pending\" ? pending : done\n  const current = shown[Math.min(cursor, Math.max(0, shown.length - 1))]\n\n  React.useEffect(() => {\n    if (cursor > shown.length - 1) setCursor(Math.max(0, shown.length - 1))\n  }, [shown.length, cursor])\n\n  const decide = (id: string, status: \"approved\" | \"rejected\", why?: string) => {\n    const r = items.find((i) => i.id === id)\n    setItems((l) => l.map((i) => (i.id === id ? { ...i, status, reason: why } : i)))\n    setRejecting(null)\n    setReason(\"\")\n    setAnnounce(`${status === \"approved\" ? \"Approved\" : \"Rejected\"}: ${r?.title ?? \"\"}`)\n  }\n  const undo = (id: string) => {\n    setItems((l) => l.map((i) => (i.id === id ? { ...i, status: \"pending\", reason: undefined } : i)))\n    setAnnounce(\"Moved back to pending.\")\n  }\n  const startReject = (id: string) => {\n    setRejecting(id)\n    setReason(\"\")\n    setReasonErr(false)\n    requestAnimationFrame(() => reasonRef.current?.focus())\n  }\n  const confirmReject = (id: string) => {\n    if (reason.trim().length < 3) {\n      setReasonErr(true)\n      reasonRef.current?.focus()\n      return\n    }\n    decide(id, \"rejected\", reason.trim())\n  }\n\n  // j / k move, a approves, r rejects, Enter opens the focused card, Esc cancels a rejection.\n  const onKey = (e: React.KeyboardEvent) => {\n    const tag = (e.target as HTMLElement).tagName\n    if (tag === \"TEXTAREA\" || tag === \"INPUT\") {\n      if (e.key === \"Escape\") setRejecting(null)\n      return\n    }\n    if (e.key === \"j\" || e.key === \"ArrowDown\") {\n      e.preventDefault()\n      setCursor((c) => Math.min(shown.length - 1, c + 1))\n    } else if (e.key === \"k\" || e.key === \"ArrowUp\") {\n      e.preventDefault()\n      setCursor((c) => Math.max(0, c - 1))\n    } else if (e.key === \"a\" && current && tab === \"pending\") {\n      decide(current.id, \"approved\")\n    } else if (e.key === \"r\" && current && tab === \"pending\") {\n      startReject(current.id)\n    } else if (e.key === \"Escape\") {\n      setRejecting(null)\n    }\n  }\n  React.useEffect(() => {\n    const el = listRef.current?.querySelector<HTMLElement>(`[data-idx=\"${cursor}\"]`)\n    if (el && listRef.current?.contains(document.activeElement)) el.focus()\n  }, [cursor])\n\n  return (\n    <div className=\"p-4 md:p-6\">\n      <div className=\"mx-auto flex max-w-3xl flex-col gap-4\">\n        <div className=\"flex flex-wrap items-end justify-between gap-3\">\n          <div>\n            <h2 className=\"text-xl font-semibold tracking-tight\">Approvals</h2>\n            <p className=\"text-sm text-muted-foreground\">\n              {pending.length} waiting for you · {pending.filter((p) => p.urgent).length} urgent\n            </p>\n          </div>\n          <div className=\"hidden items-center gap-2 text-[11px] text-muted-foreground sm:flex\">\n            <Kbd keys=\"j\" size=\"xs\" /> <Kbd keys=\"k\" size=\"xs\" /> move\n            <Kbd keys=\"a\" size=\"xs\" className=\"ml-2\" /> approve\n            <Kbd keys=\"r\" size=\"xs\" className=\"ml-2\" /> reject\n          </div>\n        </div>\n\n        <div role=\"tablist\" aria-label=\"Queue\" className=\"flex gap-1 border-b\">\n          {(\n            [\n              [\"pending\", `Pending · ${pending.length}`],\n              [\"done\", `Done · ${done.length}`],\n            ] as const\n          ).map(([k, label]) => (\n            <button key={k} type=\"button\" role=\"tab\" aria-selected={tab === k} onClick={() => { setTab(k); setCursor(0) }} className={cn(\"-mb-px border-b-2 px-3 py-2 text-sm font-medium transition-colors\", tab === k ? \"border-foreground text-foreground\" : \"border-transparent text-foreground/70 hover:text-foreground\", ring)}>\n              {label}\n            </button>\n          ))}\n        </div>\n\n        <p className=\"sr-only\" aria-live=\"polite\">\n          {announce}\n        </p>\n\n        {shown.length === 0 ? (\n          <div className=\"flex flex-col items-center gap-2 rounded-2xl border border-dashed py-14 text-center\">\n            <span className=\"flex size-12 items-center justify-center rounded-full bg-emerald-500/12 text-emerald-700 dark:text-emerald-300\">\n              <Inbox className=\"size-6\" aria-hidden=\"true\" />\n            </span>\n            <p className=\"text-sm font-medium\">{tab === \"pending\" ? \"Inbox zero. Nice.\" : \"Nothing decided yet.\"}</p>\n            <p className=\"text-xs text-muted-foreground\">{tab === \"pending\" ? \"New requests from your team will show up here.\" : \"Approve or reject something and it lands here.\"}</p>\n          </div>\n        ) : (\n          <ul ref={listRef} onKeyDown={onKey} className=\"flex flex-col gap-2\" aria-label={tab === \"pending\" ? \"Pending requests\" : \"Decided requests\"}>\n            {shown.map((r, i) => {\n              const k = KIND[r.kind]\n              const active = i === cursor\n              const isRejecting = rejecting === r.id\n              return (\n                <li\n                  key={r.id}\n                  data-idx={i}\n                  tabIndex={active ? 0 : -1}\n                  onFocus={() => setCursor(i)}\n                  onClick={() => setCursor(i)}\n                  className={cn(\"rounded-2xl border bg-card p-4 transition-[box-shadow,border-color]\", active && \"border-primary/50 shadow-[0_0_0_3px_color-mix(in_oklab,var(--primary)_12%,transparent)]\", r.status !== \"pending\" && \"opacity-90\", ring)}\n                >\n                  <div className=\"flex gap-3\">\n                    <Avatar name={r.who} size=\"md\" />\n                    <div className=\"min-w-0 flex-1\">\n                      <div className=\"flex flex-wrap items-center gap-x-2 gap-y-1\">\n                        <span className=\"text-sm font-semibold\">{r.who}</span>\n                        <span className={cn(\"inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] font-medium\", k.cls)}>\n                          <k.icon className=\"size-3\" aria-hidden=\"true\" />\n                          {k.label}\n                        </span>\n                        {r.urgent && r.status === \"pending\" && <span className=\"rounded-md bg-rose-600 px-1.5 py-0.5 text-[10px] font-bold tracking-wide text-white uppercase\">Urgent</span>}\n                        <span className=\"ml-auto text-[11px] text-muted-foreground\">{r.when}</span>\n                      </div>\n                      <p className=\"mt-1 text-sm font-medium\">\n                        {r.title}\n                        {r.amount && <span className=\"ml-2 font-semibold tabular-nums\">{r.amount}</span>}\n                      </p>\n                      <p className=\"mt-0.5 text-[13px] text-muted-foreground\">{r.detail}</p>\n\n                      {r.status === \"pending\" && !isRejecting && (\n                        <div className=\"mt-3 flex flex-wrap gap-2\">\n                          <Button size=\"sm\" tone=\"success\" iconLeft={<Check />} onClick={() => decide(r.id, \"approved\")}>\n                            Approve\n                          </Button>\n                          <Button size=\"sm\" variant=\"outline\" tone=\"neutral\" iconLeft={<X />} onClick={() => startReject(r.id)}>\n                            Reject\n                          </Button>\n                        </div>\n                      )}\n                      {isRejecting && (\n                        <div className=\"mt-3 rounded-xl border bg-background p-3 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1\">\n                          <label htmlFor={`reason-${r.id}`} className=\"text-xs font-medium\">\n                            Tell {r.who.split(\" \")[0]} why\n                          </label>\n                          <textarea\n                            id={`reason-${r.id}`}\n                            ref={reasonRef}\n                            value={reason}\n                            onChange={(e) => {\n                              setReason(e.target.value)\n                              setReasonErr(false)\n                            }}\n                            onKeyDown={(e) => {\n                              if (e.key === \"Enter\" && (e.metaKey || e.ctrlKey)) confirmReject(r.id)\n                            }}\n                            rows={2}\n                            aria-invalid={reasonErr}\n                            aria-describedby={reasonErr ? `reason-err-${r.id}` : undefined}\n                            placeholder=\"e.g. Let's offer a free redo first\"\n                            className={cn(\"mt-1.5 w-full resize-none rounded-lg border bg-background px-3 py-2 text-sm\", reasonErr && \"border-rose-500\", ring)}\n                          />\n                          {reasonErr && (\n                            <p id={`reason-err-${r.id}`} className=\"text-xs text-rose-700 dark:text-rose-300\">\n                              A reason is required so the team learns from it.\n                            </p>\n                          )}\n                          <div className=\"mt-2 flex flex-wrap items-center gap-2\">\n                            <Button size=\"sm\" tone=\"danger\" iconLeft={<X />} onClick={() => confirmReject(r.id)}>\n                              Reject with reason\n                            </Button>\n                            <Button size=\"sm\" variant=\"ghost\" tone=\"neutral\" onClick={() => setRejecting(null)}>\n                              Cancel\n                            </Button>\n                            <span className=\"ml-auto hidden text-[11px] text-muted-foreground sm:inline\">\n                              <Kbd keys={[\"mod\", \"enter\"]} size=\"xs\" /> to send\n                            </span>\n                          </div>\n                        </div>\n                      )}\n                      {r.status !== \"pending\" && (\n                        <div className=\"mt-3 flex flex-wrap items-center gap-2 text-xs\">\n                          <span className={cn(\"inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium\", r.status === \"approved\" ? \"bg-emerald-500/12 text-emerald-700 dark:text-emerald-300\" : \"bg-rose-500/12 text-rose-700 dark:text-rose-300\")}>\n                            {r.status === \"approved\" ? <Check className=\"size-3\" aria-hidden=\"true\" /> : <X className=\"size-3\" aria-hidden=\"true\" />}\n                            {r.status === \"approved\" ? \"Approved\" : \"Rejected\"}\n                          </span>\n                          {r.reason && <span className=\"text-muted-foreground\">“{r.reason}”</span>}\n                          <Button size=\"xs\" variant=\"ghost\" tone=\"neutral\" iconLeft={<Undo2 />} onClick={() => undo(r.id)} className=\"ml-auto\">\n                            Undo\n                          </Button>\n                        </div>\n                      )}\n                    </div>\n                  </div>\n                </li>\n              )\n            })}\n          </ul>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/approvals-queue.tsx"
    }
  ],
  "categories": [
    "tables"
  ],
  "type": "registry:block"
}
