@partrunner-ai/ui 2.4.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +444 -0
- package/README.md +19 -26
- package/dist/index.cjs +366 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +228 -4
- package/dist/index.d.ts +228 -4
- package/dist/index.js +360 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/recipes/form.md +296 -0
- package/recipes/inbox.md +460 -0
- package/recipes/list-page.md +290 -0
- package/recipes/record-page.md +198 -0
- package/recipes/states.md +78 -0
- package/recipes/work-queue.md +220 -0
- package/styles/light.css +475 -2
- package/styles/theme.css +475 -2
- package/styles/ui.css +475 -2
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Recipe: Work queue
|
|
2
|
+
|
|
3
|
+
The person makes the same decision on many records.
|
|
4
|
+
|
|
5
|
+
This is the full source of a screen that compiles and is tested. Copy the structure and
|
|
6
|
+
the props. Replace the sample data with the data of the app.
|
|
7
|
+
|
|
8
|
+
- `./fixtures` is sample data and two format helpers (`formatMoney`, `formatDate`). Use the
|
|
9
|
+
app's own data and its shared format helpers.
|
|
10
|
+
- `./states` is in `states.md`.
|
|
11
|
+
- The `state` prop exists only to show each state in the catalogue. In an app, the state
|
|
12
|
+
comes from the data request.
|
|
13
|
+
- The rules are in `../DESIGN.md`.
|
|
14
|
+
|
|
15
|
+
<!-- Generated from packages/showcase/src/recipes/WorkQueueRecipe.tsx. Do not edit. -->
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { useState } from 'react';
|
|
19
|
+
import { MoreHorizontal } from 'lucide-react';
|
|
20
|
+
import {
|
|
21
|
+
Badge,
|
|
22
|
+
Button,
|
|
23
|
+
DropdownMenu,
|
|
24
|
+
DropdownMenuContent,
|
|
25
|
+
DropdownMenuItem,
|
|
26
|
+
DropdownMenuSeparator,
|
|
27
|
+
DropdownMenuTrigger,
|
|
28
|
+
IconButton,
|
|
29
|
+
Notice,
|
|
30
|
+
Page,
|
|
31
|
+
PageHeader,
|
|
32
|
+
SegmentedControl,
|
|
33
|
+
Table,
|
|
34
|
+
TableFrame,
|
|
35
|
+
TableSkeleton,
|
|
36
|
+
ToolbarGroup,
|
|
37
|
+
} from '@partrunner-ai/ui';
|
|
38
|
+
import {
|
|
39
|
+
BALANCES,
|
|
40
|
+
BALANCE_STATUS,
|
|
41
|
+
PAYMENT_PLANS,
|
|
42
|
+
formatDate,
|
|
43
|
+
formatMoney,
|
|
44
|
+
type Balance,
|
|
45
|
+
type PaymentPlan,
|
|
46
|
+
} from './fixtures';
|
|
47
|
+
import { ErrorNotice, ForbiddenState, NoResults, type RecipeProps } from './states';
|
|
48
|
+
|
|
49
|
+
type Queue = 'review' | 'plans';
|
|
50
|
+
|
|
51
|
+
/** Recipe 2.5 · Work queue: queue switch, table with one primary row action and a menu. */
|
|
52
|
+
export function WorkQueueRecipe({ state, onRetry }: RecipeProps) {
|
|
53
|
+
const [queue, setQueue] = useState<Queue>('review');
|
|
54
|
+
const [balances, setBalances] = useState<Balance[]>(BALANCES);
|
|
55
|
+
const [plans, setPlans] = useState<PaymentPlan[]>(PAYMENT_PLANS);
|
|
56
|
+
const [pendingId, setPendingId] = useState<string | null>(null);
|
|
57
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
58
|
+
|
|
59
|
+
const reviewRows = state === 'empty' ? [] : balances;
|
|
60
|
+
const planRows = state === 'empty' ? [] : plans;
|
|
61
|
+
const total = reviewRows.reduce((sum, row) => sum + row.amount, 0);
|
|
62
|
+
|
|
63
|
+
const createPlan = (row: Balance) => {
|
|
64
|
+
setPendingId(row.id);
|
|
65
|
+
window.setTimeout(() => {
|
|
66
|
+
setPendingId(null);
|
|
67
|
+
setBalances((current) => current.filter((item) => item.id !== row.id));
|
|
68
|
+
setPlans((current) => [
|
|
69
|
+
{ id: `new-${row.id}`, fleet: row.fleet, weekly: Math.round(row.amount / 8), progress: '0 de 8', next: '2026-12-01', status: 'active' },
|
|
70
|
+
...current,
|
|
71
|
+
]);
|
|
72
|
+
setMessage(`Plan creado para ${row.fleet}. El primer cobro es el 1 dic 2026.`);
|
|
73
|
+
}, 700);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const switcher = (
|
|
77
|
+
<SegmentedControl<Queue>
|
|
78
|
+
aria-label="Cola"
|
|
79
|
+
value={queue}
|
|
80
|
+
onChange={setQueue}
|
|
81
|
+
options={[
|
|
82
|
+
{ value: 'review', label: 'Por revisar', count: state === 'loading' ? undefined : reviewRows.length },
|
|
83
|
+
{ value: 'plans', label: 'Planes', count: state === 'loading' ? undefined : planRows.length },
|
|
84
|
+
]}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const header = (
|
|
89
|
+
<PageHeader
|
|
90
|
+
actions={state === 'forbidden' ? undefined : switcher}
|
|
91
|
+
title="Saldos a cargo"
|
|
92
|
+
subtitle={
|
|
93
|
+
state === 'data' || state === 'error'
|
|
94
|
+
? `${reviewRows.length} saldos por revisar · ${formatMoney(total)} en total`
|
|
95
|
+
: 'Saldos de flotas que esperan un plan de pago.'
|
|
96
|
+
}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (state === 'forbidden') {
|
|
101
|
+
return (
|
|
102
|
+
<Page width="wide">
|
|
103
|
+
{header}
|
|
104
|
+
<ForbiddenState who="Finanzas" />
|
|
105
|
+
</Page>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (state === 'loading') {
|
|
111
|
+
return (
|
|
112
|
+
<Page width="wide">
|
|
113
|
+
{header}
|
|
114
|
+
<TableSkeleton rows={7} columns={7} label="Cargando saldos" />
|
|
115
|
+
</Page>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<Page width="wide">
|
|
121
|
+
{header}
|
|
122
|
+
{state === 'error' ? <ErrorNotice what="los saldos" onRetry={onRetry} /> : null}
|
|
123
|
+
{message ? (
|
|
124
|
+
<Notice tone="success" title="Listo" onDismiss={() => setMessage(null)} dismissLabel="Cerrar aviso">
|
|
125
|
+
{message}
|
|
126
|
+
</Notice>
|
|
127
|
+
) : null}
|
|
128
|
+
|
|
129
|
+
{queue === 'review' ? (
|
|
130
|
+
<TableFrame title="Por revisar" count={reviewRows.length} countLabel={(count) => `${count} saldos`}>
|
|
131
|
+
<Table
|
|
132
|
+
bare
|
|
133
|
+
label="Saldos por revisar"
|
|
134
|
+
rows={reviewRows}
|
|
135
|
+
getRowKey={rowId}
|
|
136
|
+
empty={
|
|
137
|
+
<NoResults
|
|
138
|
+
title="No hay saldos por revisar"
|
|
139
|
+
description="Cuando una flota quede con saldo a cargo, aparecerá en esta cola."
|
|
140
|
+
/>
|
|
141
|
+
}
|
|
142
|
+
columns={[
|
|
143
|
+
{ key: 'fleet', header: 'Flota', render: (row: Balance) => row.fleet },
|
|
144
|
+
{ key: 'concept', header: 'Concepto', render: (row: Balance) => row.concept, hideOnMobile: true },
|
|
145
|
+
{ key: 'week', header: 'Semana', render: (row: Balance) => row.week, hideOnMobile: true },
|
|
146
|
+
{ key: 'amount', header: 'Saldo a cargo', align: 'right', render: (row: Balance) => formatMoney(row.amount) },
|
|
147
|
+
{ key: 'age', header: 'Antigüedad', align: 'right', render: (row: Balance) => `${row.age} d`, hideOnMobile: true },
|
|
148
|
+
{
|
|
149
|
+
key: 'status',
|
|
150
|
+
header: 'Estado',
|
|
151
|
+
render: (row: Balance) => (
|
|
152
|
+
<Badge tone={BALANCE_STATUS[row.status].tone}>{BALANCE_STATUS[row.status].label}</Badge>
|
|
153
|
+
),
|
|
154
|
+
hideOnMobile: true,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: 'actions',
|
|
158
|
+
header: 'Acciones',
|
|
159
|
+
align: 'right',
|
|
160
|
+
render: (row: Balance) => (
|
|
161
|
+
<ToolbarGroup>
|
|
162
|
+
<Button
|
|
163
|
+
size="sm"
|
|
164
|
+
variant="secondary"
|
|
165
|
+
loading={pendingId === row.id}
|
|
166
|
+
onClick={() => createPlan(row)}
|
|
167
|
+
>
|
|
168
|
+
Crear plan
|
|
169
|
+
</Button>
|
|
170
|
+
<DropdownMenu>
|
|
171
|
+
<DropdownMenuTrigger asChild>
|
|
172
|
+
<IconButton label={`Más acciones para ${row.fleet}`} icon={<MoreHorizontal size={16} aria-hidden />} size="sm" variant="ghost" />
|
|
173
|
+
</DropdownMenuTrigger>
|
|
174
|
+
<DropdownMenuContent align="end">
|
|
175
|
+
<DropdownMenuItem onSelect={() => undefined}>Ver ficha de la flota</DropdownMenuItem>
|
|
176
|
+
<DropdownMenuItem onSelect={() => undefined}>Marcar en aclaración</DropdownMenuItem>
|
|
177
|
+
<DropdownMenuSeparator />
|
|
178
|
+
<DropdownMenuItem destructive onSelect={() => undefined}>
|
|
179
|
+
Condonar saldo
|
|
180
|
+
</DropdownMenuItem>
|
|
181
|
+
</DropdownMenuContent>
|
|
182
|
+
</DropdownMenu>
|
|
183
|
+
</ToolbarGroup>
|
|
184
|
+
),
|
|
185
|
+
},
|
|
186
|
+
]}
|
|
187
|
+
/>
|
|
188
|
+
</TableFrame>
|
|
189
|
+
) : (
|
|
190
|
+
<TableFrame title="Planes de pago" count={planRows.length} countLabel={(count) => `${count} planes`}>
|
|
191
|
+
<Table
|
|
192
|
+
bare
|
|
193
|
+
label="Planes de pago"
|
|
194
|
+
rows={planRows}
|
|
195
|
+
getRowKey={rowId}
|
|
196
|
+
empty={<NoResults title="Aún no hay planes" description="Crea un plan desde la cola Por revisar." />}
|
|
197
|
+
columns={[
|
|
198
|
+
{ key: 'fleet', header: 'Flota', render: (row: PaymentPlan) => row.fleet },
|
|
199
|
+
{ key: 'weekly', header: 'Cobro semanal', align: 'right', render: (row: PaymentPlan) => formatMoney(row.weekly) },
|
|
200
|
+
{ key: 'progress', header: 'Avance', render: (row: PaymentPlan) => row.progress },
|
|
201
|
+
{ key: 'next', header: 'Próximo cobro', render: (row: PaymentPlan) => formatDate(row.next) },
|
|
202
|
+
{
|
|
203
|
+
key: 'status',
|
|
204
|
+
header: 'Estado',
|
|
205
|
+
render: (row: PaymentPlan) => (
|
|
206
|
+
<Badge tone={row.status === 'late' ? 'danger' : 'success'}>{row.status === 'late' ? 'Atrasado' : 'Al corriente'}</Badge>
|
|
207
|
+
),
|
|
208
|
+
},
|
|
209
|
+
]}
|
|
210
|
+
/>
|
|
211
|
+
</TableFrame>
|
|
212
|
+
)}
|
|
213
|
+
</Page>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function rowId(row: { id: string }): string {
|
|
218
|
+
return row.id;
|
|
219
|
+
}
|
|
220
|
+
```
|