Approvals inbox
A list of the requests that wait for a person, which updates while it is open.
The approver's work queue inside your own product. Use it when approvers should not have to open the LumoAuth portal. Approve a request in the preview: it leaves the list.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/approvals-inbox.json
npx shadcn@latest add https://examples.lumoauth.dev/r/approvals-inbox.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/approvals-inbox.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/approvals-inbox.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge buttonInstall the packages.
npm install lucide-reactAdd the pattern Approval request, which this one uses.
Copy the code into your project.
components/approvals-inbox.tsx'use client';import * as React from 'react';import { Bot, Inbox } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { ApprovalRequest, type ApprovalRequestData } from '@/components/approval-request';import { cn } from '@/lib/utils';type Filter = 'all' | 'urgent';export interface ApprovalsInboxProps {/** The pending requests, newest first. */requests: ApprovalRequestData[];onApprove?: (id: string, note: string) => void | Promise<void>;onDeny?: (id: string, note: string) => void | Promise<void>;/** Shown while the first page loads. */loading?: boolean;/** Shown in place of the list when it could not be loaded. */error?: string;className?: string;}const URGENT = new Set(['high', 'critical']);function timeLeft(expiresAt: string | null | undefined, now: number | null) {if (!expiresAt || now === null) return null;const left = Math.max(0, Math.round((new Date(expiresAt).getTime() - now) / 60_000));return left === 0 ? 'expires now' : `${left} min left`;}export function ApprovalsInbox({ requests, onApprove, onDeny, loading, error, className }: ApprovalsInboxProps) {const [filter, setFilter] = React.useState<Filter>('all');const [selected, setSelected] = React.useState<string | null>(null);// The clock is read after the first render, so that a server can render the list.const [now, setNow] = React.useState<number | null>(null);React.useEffect(() => {setNow(Date.now());const timer = setInterval(() => setNow(Date.now()), 30_000);return () => clearInterval(timer);}, []);const shown = requests.filter((r) => filter === 'all' || URGENT.has(String(r.impact ?? '').toLowerCase()));// Keep a valid selection when the list changes under the reader.const current = shown.find((r) => r.id === selected) ?? shown[0] ?? null;const urgent = requests.filter((r) => URGENT.has(String(r.impact ?? '').toLowerCase())).length;return (<section className={cn('w-full max-w-4xl rounded-xl border bg-card text-card-foreground shadow-sm', className)} aria-label="Approvals"><header className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3"><h2 className="flex items-center gap-2 text-sm font-semibold"><Inbox className="size-4" aria-hidden="true" />Approvals<Badge variant="secondary" className="tabular-nums">{requests.length}</Badge></h2><div className="flex gap-1" role="group" aria-label="Filter"><Button size="sm" variant={filter === 'all' ? 'secondary' : 'ghost'} onClick={() => setFilter('all')}>All</Button><Button size="sm" variant={filter === 'urgent' ? 'secondary' : 'ghost'} onClick={() => setFilter('urgent')}>High impact{urgent > 0 ? ` (${urgent})` : ''}</Button></div></header>{error ? (<p className="p-6 text-sm text-destructive" role="alert">{error}</p>) : loading ? (<p className="p-6 text-sm text-muted-foreground">Loading the requests…</p>) : shown.length === 0 ? (<div className="grid justify-items-center gap-1 px-6 py-12 text-center"><Inbox className="size-6 text-muted-foreground" aria-hidden="true" /><p className="text-sm font-medium">Nothing waits for you</p><p className="text-sm text-muted-foreground">{filter === 'all' ? 'A new request appears here as soon as an agent asks.' : 'No request with a high impact is open.'}</p></div>) : (<div className="grid md:grid-cols-[minmax(0,17rem)_1fr]"><ul className="max-h-[32rem] overflow-y-auto border-b md:border-r md:border-b-0" aria-label="Pending requests">{shown.map((r) => {const active = r.id === current?.id;return (<li key={r.id}><buttontype="button"aria-current={active}onClick={() => setSelected(r.id)}className={cn('grid w-full gap-1 border-b px-4 py-3 text-left text-sm outline-none last:border-b-0 hover:bg-accent/60 focus-visible:bg-accent',active && 'bg-accent',)}><span className="flex items-center justify-between gap-2"><span className="flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground"><Bot className="size-3.5 shrink-0" aria-hidden="true" /><span className="truncate">{r.agentName}</span></span>{URGENT.has(String(r.impact ?? '').toLowerCase()) && (<span className="size-2 shrink-0 rounded-full bg-orange-500" title={`${r.impact} impact`} />)}</span><span className="line-clamp-2 font-medium">{r.summary}</span>{timeLeft(r.expiresAt, now) && (<span className="text-xs text-muted-foreground tabular-nums">{timeLeft(r.expiresAt, now)}</span>)}</button></li>);})}</ul><div className="p-4">{current && (<ApprovalRequestkey={current.id}request={current}onApprove={onApprove}onDeny={onDeny}className="max-w-none border-0 py-2 shadow-none ring-0"/>)}</div></div>)}</section>);}Change the import paths if your project keeps its components in another place.
Usage
Give the inbox the pending requests and two callbacks. It keeps the selection and the filter itself.
'use client';
import { ApprovalsInbox } from '@/components/approvals-inbox';
import { fromJitRequest } from '@/components/approval-request';
// `rows` are the rows of GET /jit/pending for the signed-in approver, from your API route.
export function Inbox({ rows, reload }: { rows: Array<Record<string, unknown>>; reload: () => Promise<void> }) {
const decide = (decision: 'approve' | 'deny') => async (id: string, note: string) => {
await fetch(`/api/approvals/${id}/${decision}`, { method: 'POST', body: JSON.stringify({ note }) });
await reload();
};
return <ApprovalsInbox requests={rows.map(fromJitRequest)} onApprove={decide('approve')} onDeny={decide('deny')} />;
}
Load the rows again after each decision. To show a new request at once, receive the jit.approval_required webhook in your backend and push it to the browser. Your API route makes the call to LumoAuth. Never call LumoAuth from the browser with a secret.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| The queue | GET /jit/pending, or lumo.jit.listPendingRequests() |
| A decision | POST /jit/approve/{id}, POST /jit/deny/{id} |
| A request as it arrives | The webhook jit.approval_required |
| A request that another approver decided | The webhooks jit.request.approved and jit.request.denied |
States
- Empty. Nothing waits for this person.
- Error. The list could not be loaded.
- A request disappears. When the list changes, the inbox selects the first request that is left.
Props
| Prop | Type | Description |
|---|---|---|
requestsrequired | ApprovalRequestData[] | The pending requests, newest first. The type comes from the approval request pattern. |
onApprove | (id: string, note: string) => void | Promise<void> | Called when the person approves. |
onDeny | (id: string, note: string) => void | Promise<void> | Called when the person denies. |
loading | boolean | Shows a loading line in place of the list. |
error | string | Shows this message in place of the list. |
className | string | Class name for the inbox. |