{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lib-task-outcome",
  "title": "Task feedback",
  "description": "A record or request command's outcome: sending, an unconfirmed result with its retry, a refusal, or a confirmed receipt with a link to what it created. The caller supplies where the reconcile button points.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/lib-content",
    "@registrystack/lib-format",
    "@registrystack/lib-notice",
    "@registrystack/shell-error-panel",
    "@registrystack/ui-button"
  ],
  "files": [
    {
      "path": "lib/task-outcome.tsx",
      "content": "import { useEffect, useRef } from \"react\";\nimport { ArrowRight } from \"lucide-react\";\nimport { problemView } from \"@registrystack/app-runtime\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  ConfirmedReceipt,\n  useBlockContent,\n  useLocale,\n} from \"@/blocks/lib/content\";\nimport { fillNodes } from \"@/blocks/lib/format\";\nimport { Notice } from \"@/blocks/lib/notice\";\nimport { ErrorPanel } from \"@/blocks/shell/error-panel\";\n\n/** The outcome of a record or request command, as a page's own write tracks it. */\nexport interface TaskFeedbackState {\n  pending: boolean;\n  unknown: boolean;\n  error: Error | null;\n  /** This attempt's own identifier, shown as its support reference while unconfirmed. */\n  reference: string | null;\n  retry: () => Promise<unknown>;\n  result:\n    | {\n        outcome: \"confirmed\";\n        receipt: string;\n        resource?: { id: string; entity: string };\n      }\n    | { outcome: \"unknown\" }\n    | null;\n}\n\n/**\n * A command's outcome: sending, an unconfirmed result with its retry, a\n * refusal, or a confirmed receipt with a link to what it created. Every\n * write on a record or request page ends here. The caller supplies where\n * \"Check current records\" points and what opening a confirmed resource does.\n */\nexport function TaskFeedback({\n  task,\n  reconcileHref,\n  onConfirmed,\n  confirmedLabel,\n  recordWrite,\n  focusConfirmed,\n}: {\n  task: TaskFeedbackState;\n  /** Where \"Check current records\" points. */\n  reconcileHref: string;\n  onConfirmed?: (id: string) => void;\n  /** What the button that opens the confirmed resource says; \"Open request\" by default. */\n  confirmedLabel?: string;\n  /** The task writes records, so a conflict is with the values it sent. */\n  recordWrite?: boolean;\n  /** Moves focus to the confirmed notice's heading when the write is confirmed. */\n  focusConfirmed?: boolean;\n}) {\n  const c = useBlockContent();\n  const locale = useLocale();\n  const result = task.result;\n  const confirmedHeading = useRef<HTMLHeadingElement>(null);\n  const confirmed = result?.outcome === \"confirmed\";\n  useEffect(() => {\n    if (focusConfirmed && confirmed) confirmedHeading.current?.focus();\n  }, [focusConfirmed, confirmed]);\n  const problem = problemView(task.error);\n  if (task.pending) return <Notice>{c.saving}</Notice>;\n  if (task.unknown)\n    return (\n      <Notice tone=\"warning\" title={c.unknownTitle}>\n        <p>{c.unknownBody}</p>\n        {problem.status !== null && (\n          <p>\n            {c.retryRefused}\n            {problem.message !== null && ` ${problem.message}`}\n          </p>\n        )}\n        <p className=\"reference\">\n          {fillNodes(\n            c.labelled,\n            {\n              label: c.receipt,\n              value: <span className=\"font-mono\">{task.reference}</span>,\n            },\n            locale,\n          )}\n        </p>\n        <div className=\"actions\">\n          <Button onClick={() => void task.retry()}>{c.exactRetry}</Button>\n          <Button render={<a href={reconcileHref} />} variant=\"outline\">\n            {c.reconcile}\n          </Button>\n        </div>\n      </Notice>\n    );\n  // A refusal in the registry's words that names fields is already in the\n  // form's error summary, against those fields.\n  if (task.error && problem.worded && Object.keys(problem.fieldErrors).length)\n    return null;\n  if (task.error)\n    return <ErrorPanel error={task.error} recordWrite={recordWrite} />;\n  if (result?.outcome === \"confirmed\")\n    return (\n      <Notice tone=\"success\">\n        <h2 ref={confirmedHeading} tabIndex={focusConfirmed ? -1 : undefined}>\n          {c.confirmed}\n        </h2>\n        {onConfirmed && result.resource && (\n          <Button onClick={() => onConfirmed(result.resource!.id)}>\n            {confirmedLabel ?? c.openRequest}\n            <ArrowRight />\n          </Button>\n        )}\n        <ConfirmedReceipt receipt={result.receipt} />\n      </Notice>\n    );\n  return null;\n}\n",
      "type": "registry:lib",
      "target": "@lib/task-outcome.tsx"
    }
  ],
  "type": "registry:lib"
}