Recorded demo
Source
/* Approval with run history — free block published by UI Stacks (public page source).
Kept verbatim: the author publishes this block free, in full, at https://uistacks.dev/blocks/approval-with-history
See replica/README.md for provenance. */
"use client";
import { useId, useRef, useState } from "react";
import { Check, FileText, Image as ImageIcon, Mail, MessageCircleQuestion, ReceiptText, RotateCcw, X } from "lucide-react";
import { ApprovalRequest, type ApprovalStatus } from "../components/approval-request";
import { Timeline, type TimelineEvent } from "../components/timeline";
import { Avatar } from "../components/avatar";
import { Badge } from "../components/badge";
import { Button } from "../components/button";
/* ── Sample data: replace with your own ─────────────────────── */
const YOU = { name: "Olivia Bennett", src: "/avatars/olivia-bennett.png" };
const REQUEST = {
run: "Run 524",
agent: "Claude",
app: "Shopify",
title: "Refund $240 to order #4182",
description: "The holiday box arrived cold and the customer sent photos. Claude matched them to the order and checked the refund policy.",
warning: "Refunds go back to the card and can't be pulled back.",
expiry: "Expires in 52 min",
details: [
{ label: "Order", value: "#4182 · Holiday box" },
{ label: "Customer", value: "Emma Collins" },
{ label: "Amount", value: "$240.00" },
{ label: "Back to", value: "Visa •••• 7310" },
],
};
const s16 = { size: 16, strokeWidth: 1.5 } as const;
/** What the agent did before it stopped to ask, oldest first. */
const STEPS: TimelineEvent[] = [
{ id: "email", day: "Today", time: "9:41 AM", icon: <Mail {...s16} />, title: "Read Emma Collins's email", body: "“My holiday box arrived cold and the cups were crushed.” Three photos attached." },
{ id: "photos", day: "Today", time: "9:42 AM", icon: <ImageIcon {...s16} />, title: "Matched the photos to order #4182", body: "Holiday box, delivered Nov 10 by UPS. Paid $240.00 with Visa •••• 7310." },
{ id: "policy", day: "Today", time: "9:43 AM", icon: <FileText {...s16} />, title: "Checked the refund policy", body: "Damaged deliveries get a full refund. Anything over $200 needs a manager." },
{ id: "draft", day: "Today", time: "9:44 AM", icon: <ReceiptText {...s16} />, title: "Drafted a full refund of $240.00" },
{ id: "ask", day: "Today", time: "9:44 AM", icon: <MessageCircleQuestion {...s16} />, tone: "select", title: "Asked you to approve" },
];
/** The step that lands at the end of the run once you decide. */
const decidedStep = (approved: boolean): TimelineEvent => ({
id: "decided",
day: "Today",
time: "Now",
tone: approved ? "success" : "neutral",
icon: approved ? <Check {...s16} /> : <X {...s16} />,
title: (
<span className="inline-flex flex-wrap items-center gap-x-2 gap-y-1">
<Avatar name={YOU.name} src={YOU.src} size="xs" />
{approved ? "You approved it. Claude sent the refund and emailed Emma." : "You declined. Claude kept the draft and paused the run."}
</span>
),
});
/* ── Brand mark (trademark belongs to its owner) ────────────── */
function ShopifyMark() {
return (
<svg viewBox="0 0 256 292" aria-hidden className="size-5">
<path d="M223.774 57.34c-.201-1.46-1.48-2.268-2.537-2.357-1.055-.088-23.383-1.743-23.383-1.743s-15.507-15.395-17.209-17.099c-1.703-1.703-5.029-1.185-6.32-.805-.19.056-3.388 1.043-8.678 2.68-5.18-14.906-14.322-28.604-30.405-28.604-.444 0-.901.018-1.358.044C129.31 3.407 123.644.779 118.75.779c-37.465 0-55.364 46.835-60.976 70.635-14.558 4.511-24.9 7.718-26.221 8.133-8.126 2.549-8.383 2.805-9.45 10.462C21.3 95.806.038 260.235.038 260.235l165.678 31.042 89.77-19.42S223.973 58.8 223.775 57.34zM156.49 40.848l-14.019 4.339c.005-.988.01-1.96.01-3.023 0-9.264-1.286-16.723-3.349-22.636 8.287 1.04 13.806 10.469 17.358 21.32zm-27.638-19.483c2.304 5.773 3.802 14.058 3.802 25.238 0 .572-.005 1.095-.01 1.624-9.117 2.824-19.024 5.89-28.953 8.966 5.575-21.516 16.025-31.908 25.161-35.828zm-11.131-10.537c1.617 0 3.246.549 4.805 1.622-12.007 5.65-24.877 19.88-30.312 48.297l-22.886 7.088C75.694 46.16 90.81 10.828 117.72 10.828z" fill="#95BF46" />
<path d="M221.237 54.983c-1.055-.088-23.383-1.743-23.383-1.743s-15.507-15.395-17.209-17.099c-.637-.634-1.496-.959-2.394-1.099l-12.527 256.233 89.762-19.418S223.972 58.8 223.774 57.34c-.201-1.46-1.48-2.268-2.537-2.357" fill="#5E8E3E" />
<path d="M135.242 104.585l-11.069 32.926s-9.698-5.176-21.586-5.176c-17.428 0-18.305 10.937-18.305 13.693 0 15.038 39.2 20.8 39.2 56.024 0 27.713-17.577 45.558-41.277 45.558-28.44 0-42.984-17.7-42.984-17.7l7.615-25.16s14.95 12.835 27.565 12.835c8.243 0 11.596-6.49 11.596-11.232 0-19.616-32.16-20.491-32.16-52.724 0-27.129 19.472-53.382 58.778-53.382 15.145 0 22.627 4.338 22.627 4.338" fill="#FFF" />
</svg>
);
}
/* ── The block ──────────────────────────────────────────────── */
const BADGE: Record<ApprovalStatus, { label: string; tone: "warning" | "success" | "neutral" }> = {
pending: { label: "Waiting on you", tone: "warning" },
approved: { label: "Approved", tone: "success" },
always: { label: "Approved", tone: "success" },
denied: { label: "Declined", tone: "neutral" },
};
/** An agent's request to act, next to the steps it took before asking. Deciding adds the outcome to the run. */
export default function ApprovalWithHistoryBlock({ className = "" }: { className?: string }) {
const [status, setStatus] = useState<ApprovalStatus>("pending");
const [said, setSaid] = useState("");
const titleId = useId();
const undoRef = useRef<HTMLButtonElement>(null);
const decided = status !== "pending";
const events = decided ? [...STEPS, decidedStep(status !== "denied")] : STEPS;
const badge = BADGE[status];
const decide = (next: ApprovalStatus) => {
setStatus(next);
setSaid(next === "denied" ? "Declined. Claude kept the draft and paused the run." : "Approved. Claude sent the $240.00 refund.");
// The decision buttons unmount; keep focus on the block's next control.
requestAnimationFrame(() => undoRef.current?.focus());
};
return (
<section aria-labelledby={titleId} className={"@container w-full min-w-0 " + className}>
<div className="flex flex-col gap-4">
<header className="flex flex-wrap items-start justify-between gap-x-4 gap-y-2 px-1">
<div className="min-w-0">
<h2 id={titleId} className="text-[15px] font-medium leading-5 text-fg">
Approval needed
</h2>
<p className="mt-0.5 text-[13px] leading-5 text-fg-muted">
{REQUEST.run} · {REQUEST.agent} in {REQUEST.app} · started 9:41 AM
</p>
</div>
<div className="flex items-center gap-2">
<Badge tone={badge.tone} dot>
{badge.label}
</Badge>
{decided && (
<Button ref={undoRef} variant="secondary" size="sm" leadingIcon={<RotateCcw size={16} strokeWidth={1.5} />} onClick={() => {
setStatus("pending");
setSaid("Decision undone. The request is waiting on you again.");
}}>
Undo
</Button>
)}
</div>
</header>
<div className="grid grid-cols-1 items-start gap-4 @min-[720px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
<ApprovalRequest
overline={`${REQUEST.agent} · ${REQUEST.app}`}
title={REQUEST.title}
description={REQUEST.description}
warning={REQUEST.warning}
risk="high"
expiry={REQUEST.expiry}
icon={<ShopifyMark />}
details={REQUEST.details}
status={status}
onApprove={(scope) => decide(scope === "always" ? "always" : "approved")}
onDeny={() => decide("denied")}
className="max-w-none!"
/>
<section aria-labelledby={titleId + "-run"} className="rounded-[20px] bg-surface p-5 shadow-[var(--shadow-card)]">
<h3 id={titleId + "-run"} className="text-[15px] font-medium leading-5 text-fg">
Before it asked
</h3>
<p className="mb-4 mt-0.5 text-[13px] leading-5 text-fg-muted">
{events.length} steps · {decided ? "your decision is the last one" : "the run is paused on you"}
</p>
<Timeline events={events} aria-label={`${REQUEST.run} steps`} />
</section>
</div>
</div>
<span role="status" aria-live="polite" className="sr-only">
{said}
</span>
</section>
);
}
Usage
Add the TSX to your React project and install the required dependencies. Styles use Tailwind CSS and theme tokens。
Package dependencies · lucide-react、react
Shared source · approval-request.tsx、avatar.tsx、badge.tsx、button.tsx、timeline.tsx