Approvals queue with bulk actions
Join requests with per-row and bulk approve and reject, one reason dialog and an undo toast.
A queue is a table where every row asks for a decision. Fast decisions need three things: actions on the row, checkboxes for many at once, and feedback that says what happened and lets you take it back. This recipe uses the PR Portal's pieces (and its theme).
The whole recipe
A queue of join requests with per-row Approve and Reject, checkboxes for bulk actions, one reason dialog for every rejection (single or many), and a toast that says the outcome and offers Undo. The New creators tab is newCreatorColumns, with Reject and Approve named for each creator. The rows are state here; in an app they come from your API and the handlers call useAction.
Code
import { useState } from 'react';
import { BulkAction, Button, DataTable, PageGrid, PillTabs, PrBulkBar, PrEmpty, ReasonDialog, ToastRegion, joinRequestColumns, newCreatorColumns, type JoinRequestRow, type PrNewCreatorRow, type ToastMessage } from '@ergasti/bricks';
import { joinRequests } from './pr';
const NEW_CREATORS: PrNewCreatorRow[] = [
{ id: 101, name: 'Laila Mostafa', followers: { instagram: 48200, tiktok: 12100 }, signedUp: 'Today' },
{ id: 102, name: 'Omar Fathy', followers: { tiktok: 91000 }, signedUp: 'Yesterday' },
{ id: 103, name: 'Nour Hassan', customer: true, followers: { instagram: 2300 }, signedUp: '16 Nov' },
];
function Queue() {
const [rows, setRows] = useState<JoinRequestRow[]>(joinRequests);
const [selected, setSelected] = useState<ReadonlySet<string | number>>(new Set());
const [rejecting, setRejecting] = useState<Array<string | number> | null>(null);
const [toast, setToast] = useState<ToastMessage | null>(null);
const [tab, setTab] = useState('join');
const [fresh, setFresh] = useState<PrNewCreatorRow[]>(NEW_CREATORS);
const settleNew = (row: PrNewCreatorRow, message: string) => { setFresh((all) => all.filter((r) => r.id !== row.id)); setToast({ message }); };
const remove = (ids: Array<string | number>, message: string) => {
const before = rows;
setRows((all) => all.filter((r) => !ids.includes(r.id)));
setSelected(new Set());
setToast({ message, actionLabel: 'Undo', onAction: () => { setRows(before); setToast(null); } });
};
const approve = (ids: Array<string | number>) => remove(ids, ids.length === 1 ? 'Approved. They get a WhatsApp.' : `Approved ${ids.length} creators.`);
return (
<PageGrid>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center', justifyContent: 'space-between' }}>
<PillTabs label="Approvals" idPrefix="recipe-approvals" value={tab} onChange={setTab}>
<PillTabs.Tab value="join" count={rows.length}>Join requests</PillTabs.Tab>
<PillTabs.Tab value="new" count={fresh.length}>New creators</PillTabs.Tab>
</PillTabs>
<PrBulkBar count={selected.size} onClear={() => setSelected(new Set())}>
<BulkAction kind="danger" onClick={() => setRejecting([...selected])}>Reject</BulkAction>
<BulkAction kind="approve" onClick={() => approve([...selected])}>Approve {selected.size}</BulkAction>
</PrBulkBar>
</div>
{tab === 'new' ? (
<DataTable label="New creators" rows={fresh} rowKey={(r) => r.id} columns={newCreatorColumns('en', { onApprove: (r) => settleNew(r, `Approved ${r.name}.`), onReject: (r) => settleNew(r, `Rejected ${r.name}.`) })} />
) : rows.length === 0 ? (
<PrEmpty card title="All clear" text="Nothing waiting here." icon="check" tone="lime" action={<Button onClick={() => setRows(joinRequests)}>Bring them back</Button>} />
) : (
<DataTable
label="Join requests"
rows={rows}
rowKey={(r) => r.id}
columns={joinRequestColumns('en', { onApprove: (r) => approve([r.id]), onReject: (r) => setRejecting([r.id]), onOpen: () => {} })}
selection={{ selected, onChange: setSelected, rowLabel: (r) => r.creator.name }}
sort={{ key: 'waiting', dir: 'desc' }}
onSort={() => {}}
/>
)}
<ReasonDialog
open={rejecting !== null}
onClose={() => setRejecting(null)}
onConfirm={() => { if (rejecting) remove(rejecting, rejecting.length === 1 ? 'Rejected. They can request again in 2 weeks.' : `Rejected ${rejecting.length} requests.`); setRejecting(null); }}
title={rejecting && rejecting.length > 1 ? `Reject ${rejecting.length} requests?` : 'Reject this request?'}
sub="They won’t join the brand. They can request again after 2 weeks."
reasons={['Not a fit for this brand', 'Audience doesn’t match', 'Already promoting a competitor', 'Other'].map((r) => ({ value: r, label: r }))}
confirmLabel="Reject"
/>
<ToastRegion toast={toast} onDismiss={() => setToast(null)} />
</PageGrid>
);
}How it fits together
joinRequestColumns(language, handlers)is the column preset forDataTable: creator, followers, brand, source, waiting time and the Approve and Reject buttons. You passonApprove,onReject, an optionalonOpenand a per-rowbusy.- Selection is
selection={{ selected, onChange, rowLabel }}on the table.PrBulkBarshows the count with a Clear button and yourBulkActions (approveis the primary one,dangerthe destructive one). - One
ReasonDialogfor every rejection: the single and the bulk paths both setrejectingto the ids and open the same dialog. It asks for a reason (a choice or free text) and a note. - Say the outcome, then offer Undo.
ToastRegionshows one message at a time for five seconds; keep the rows from before the change and restore them inonAction. In an app, "undo" is a second request, or you delay the write until the toast expires. - Empty state: when the queue is empty show
PrEmptyrather than an empty table. - New creators. The second tab is newCreatorColumns
(language, { onApprove, onReject }): the creator (with "Customer asking to become a creator" for a customer affiliate), followers, when they signed up, and Reject / Approve named for the creator.busy(row)locks a row while it saves.
Related: joinRequestColumns, newCreatorColumns, PrBulkBar, ReasonDialog, ToastRegion, ApprovalRow.