@burdenoff/microfe-movethewheels 2026.1107.2 → 2026.1107.3
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/dist/MoveTheWheelsRoutes.js +9 -5
- package/dist/components/DispatchDecisionCard.js +203 -0
- package/dist/generated/tracking-quality-operations.d.ts +137 -0
- package/dist/hooks/useDispatchPlan.js +88 -0
- package/dist/movethewheels/components/DispatchDecisionCard.d.ts +16 -0
- package/dist/movethewheels/hooks/useDispatchPlan.d.ts +79 -0
- package/dist/movethewheels/pages/DispatchPlanPage.d.ts +14 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/wand-sparkles.js +38 -0
- package/dist/pages/DispatchPlanPage.js +374 -0
- package/dist/pages/RoutesPage.js +85 -80
- package/package.json +1 -1
- package/src/generated/tracking-quality-operations.ts +156 -0
- package/src/movethewheels/MoveTheWheelsRoutes.tsx +2 -0
- package/src/movethewheels/components/DispatchDecisionCard.tsx +243 -0
- package/src/movethewheels/hooks/useDispatchPlan.ts +286 -0
- package/src/movethewheels/pages/DispatchPlanPage.tsx +505 -0
- package/src/movethewheels/pages/RoutesPage.tsx +9 -2
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch planner (BOFF-10562)
|
|
3
|
+
*
|
|
4
|
+
* Decision cards for `mtwPlanDispatch` proposals. The planner proposes a
|
|
5
|
+
* vehicle + driver for each PLANNED shipment without a route; nothing is
|
|
6
|
+
* written until the dispatcher accepts. Accepting some cards and applying
|
|
7
|
+
* creates one PLANNED route per accepted card (partial accept); everything not
|
|
8
|
+
* accepted is rejected. Rejecting the plan writes nothing.
|
|
9
|
+
*
|
|
10
|
+
* Graceful degradation: when AI is switched off, the workspace's AI credits are
|
|
11
|
+
* spent or the model fails, the plan is the same and only the AI-written text
|
|
12
|
+
* is missing; manual route creation is always one click away.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { Loader2, Navigation, Plus, RefreshCw, Sparkles, Wand2 } from 'lucide-react';
|
|
17
|
+
import { CTAOverflowMenu, EmphasisPanel, PagePurpose } from '@burdenoff/fe-libs/ui';
|
|
18
|
+
import { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';
|
|
19
|
+
|
|
20
|
+
import { PageLayout } from '../components/PageLayout';
|
|
21
|
+
import { FormError } from '../components/FormError';
|
|
22
|
+
import { Notice, useNotice } from '../components/Notice';
|
|
23
|
+
import { DispatchDecisionCard, type DispatchChoice } from '../components/DispatchDecisionCard';
|
|
24
|
+
import {
|
|
25
|
+
Badge,
|
|
26
|
+
Button,
|
|
27
|
+
Card,
|
|
28
|
+
CardContent,
|
|
29
|
+
CardHeader,
|
|
30
|
+
CardTitle,
|
|
31
|
+
Select,
|
|
32
|
+
SelectContent,
|
|
33
|
+
SelectItem,
|
|
34
|
+
SelectTrigger,
|
|
35
|
+
SelectValue,
|
|
36
|
+
Skeleton,
|
|
37
|
+
} from '../components/ui';
|
|
38
|
+
import {
|
|
39
|
+
useDispatchPlan,
|
|
40
|
+
type DecisionRationaleStatus,
|
|
41
|
+
type DispatchPlan,
|
|
42
|
+
type DispatchPlanStatus,
|
|
43
|
+
} from '../hooks/useDispatchPlan';
|
|
44
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
45
|
+
import { formatDateTime } from '../utils/formatters';
|
|
46
|
+
import { joinPath } from '../utils/navigation';
|
|
47
|
+
|
|
48
|
+
type Translate = (key: string, fallback: string) => string;
|
|
49
|
+
type Horizon = '24h' | '72h' | '7d' | 'all';
|
|
50
|
+
|
|
51
|
+
const HORIZON_HOURS: Record<Exclude<Horizon, 'all'>, number> = { '24h': 24, '72h': 72, '7d': 168 };
|
|
52
|
+
|
|
53
|
+
const STATUS_LABELS: Record<DispatchPlanStatus, [string, string]> = {
|
|
54
|
+
PROPOSED: ['movethewheels.dispatch.status.proposed', 'Waiting for your decision'],
|
|
55
|
+
APPLYING: ['movethewheels.dispatch.status.applying', 'Applying decisions'],
|
|
56
|
+
APPLIED: ['movethewheels.dispatch.status.applied', 'All accepted'],
|
|
57
|
+
PARTIALLY_APPLIED: ['movethewheels.dispatch.status.partiallyApplied', 'Partly accepted'],
|
|
58
|
+
REJECTED: ['movethewheels.dispatch.status.rejected', 'Rejected — nothing written'],
|
|
59
|
+
EXPIRED: ['movethewheels.dispatch.status.expired', 'Expired'],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const AI_STATUS_MESSAGES: Record<
|
|
63
|
+
Exclude<DecisionRationaleStatus, 'AVAILABLE'>,
|
|
64
|
+
[string, string]
|
|
65
|
+
> = {
|
|
66
|
+
NOT_NEEDED: [
|
|
67
|
+
'movethewheels.dispatch.ai.notNeeded',
|
|
68
|
+
'Nothing could be assigned, so there was nothing for AI to explain.',
|
|
69
|
+
],
|
|
70
|
+
AI_DISABLED: [
|
|
71
|
+
'movethewheels.dispatch.ai.disabled',
|
|
72
|
+
'AI explanations are switched off. The rule-based rationale below is complete.',
|
|
73
|
+
],
|
|
74
|
+
CREDITS_EXHAUSTED: [
|
|
75
|
+
'movethewheels.dispatch.ai.creditsExhausted',
|
|
76
|
+
'This workspace has used its MoveTheWheels AI credits, so no AI explanation was written. The proposal and its rule-based rationale are unaffected.',
|
|
77
|
+
],
|
|
78
|
+
DAILY_CAP_REACHED: [
|
|
79
|
+
'movethewheels.dispatch.ai.dailyCap',
|
|
80
|
+
"Today's AI explanation limit is reached. The proposal and its rule-based rationale are unaffected.",
|
|
81
|
+
],
|
|
82
|
+
UNAVAILABLE: [
|
|
83
|
+
'movethewheels.dispatch.ai.unavailable',
|
|
84
|
+
'The AI explanation could not be produced this time. The proposal and its rule-based rationale are unaffected.',
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const UNASSIGNED_REASONS: Record<string, [string, string]> = {
|
|
89
|
+
NO_ELIGIBLE_PAIR: [
|
|
90
|
+
'movethewheels.dispatch.unassigned.noPair',
|
|
91
|
+
'No linked vehicle and driver are free (vehicle active and not on a live route, driver with a valid licence).',
|
|
92
|
+
],
|
|
93
|
+
FLEET_FULLY_ASSIGNED: [
|
|
94
|
+
'movethewheels.dispatch.unassigned.fleetFull',
|
|
95
|
+
'Every free vehicle and driver pair is already used in this plan.',
|
|
96
|
+
],
|
|
97
|
+
OVER_CAPACITY: [
|
|
98
|
+
'movethewheels.dispatch.unassigned.overCapacity',
|
|
99
|
+
'The load is heavier than every free vehicle’s recorded capacity.',
|
|
100
|
+
],
|
|
101
|
+
PLAN_LIMIT_REACHED: [
|
|
102
|
+
'movethewheels.dispatch.unassigned.limit',
|
|
103
|
+
'The plan reached its assignment limit.',
|
|
104
|
+
],
|
|
105
|
+
NOT_PLANNABLE: [
|
|
106
|
+
'movethewheels.dispatch.unassigned.notPlannable',
|
|
107
|
+
'Not a planned shipment without a route.',
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function horizonWindow(horizon: Horizon): { from?: string; to?: string } {
|
|
112
|
+
if (horizon === 'all') return {};
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
return { to: new Date(now + HORIZON_HOURS[horizon] * 3_600_000).toISOString() };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function PlanSummary({ plan, t }: { plan: DispatchPlan; t: Translate }) {
|
|
118
|
+
const [statusKey, statusFallback] = STATUS_LABELS[plan.status];
|
|
119
|
+
return (
|
|
120
|
+
<EmphasisPanel>
|
|
121
|
+
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
122
|
+
<div className="space-y-1">
|
|
123
|
+
<p className="text-sm font-medium text-text-secondary">
|
|
124
|
+
{t('movethewheels.dispatch.planLabel', 'Latest proposal')} ·{' '}
|
|
125
|
+
{formatDateTime(plan.createdAt)}
|
|
126
|
+
</p>
|
|
127
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
128
|
+
<Badge variant={plan.status === 'PROPOSED' ? 'default' : 'secondary'}>
|
|
129
|
+
{t(statusKey, statusFallback)}
|
|
130
|
+
</Badge>
|
|
131
|
+
<span className="text-xs text-text-secondary">
|
|
132
|
+
{t('movethewheels.dispatch.method', 'Rule-based planner')} ({plan.method})
|
|
133
|
+
</span>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
<div className="grid grid-cols-3 gap-4 text-center">
|
|
137
|
+
<div>
|
|
138
|
+
<p className="text-2xl font-bold tabular-nums text-text-primary">
|
|
139
|
+
{plan.assignments.length}
|
|
140
|
+
</p>
|
|
141
|
+
<p className="text-xs text-text-secondary">
|
|
142
|
+
{t('movethewheels.dispatch.proposed', 'Proposed')}
|
|
143
|
+
</p>
|
|
144
|
+
</div>
|
|
145
|
+
<div>
|
|
146
|
+
<p className="text-2xl font-bold tabular-nums text-text-primary">
|
|
147
|
+
{plan.acceptedCount}
|
|
148
|
+
</p>
|
|
149
|
+
<p className="text-xs text-text-secondary">
|
|
150
|
+
{t('movethewheels.dispatch.acceptedCount', 'Accepted')}
|
|
151
|
+
</p>
|
|
152
|
+
</div>
|
|
153
|
+
<div>
|
|
154
|
+
<p className="text-2xl font-bold tabular-nums text-text-primary">
|
|
155
|
+
{plan.unassigned.length}
|
|
156
|
+
</p>
|
|
157
|
+
<p className="text-xs text-text-secondary">
|
|
158
|
+
{t('movethewheels.dispatch.unassignedCount', 'Unassigned')}
|
|
159
|
+
</p>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
{plan.status === 'PROPOSED' && (
|
|
164
|
+
<p className="mt-3 text-xs text-text-secondary">
|
|
165
|
+
{t('movethewheels.dispatch.expires', 'Valid until')} {formatDateTime(plan.expiresAt)}
|
|
166
|
+
</p>
|
|
167
|
+
)}
|
|
168
|
+
</EmphasisPanel>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function AiExplanation({ plan, t }: { plan: DispatchPlan; t: Translate }) {
|
|
173
|
+
if (plan.aiStatus === 'AVAILABLE' && plan.aiSummary) {
|
|
174
|
+
return (
|
|
175
|
+
<Card>
|
|
176
|
+
<CardHeader>
|
|
177
|
+
<CardTitle className="flex items-center gap-2 text-base">
|
|
178
|
+
<Sparkles size={16} aria-hidden="true" />
|
|
179
|
+
{t('movethewheels.dispatch.ai.title', 'AI summary')}
|
|
180
|
+
</CardTitle>
|
|
181
|
+
</CardHeader>
|
|
182
|
+
<CardContent className="space-y-2">
|
|
183
|
+
<p className="text-sm text-text-primary">{plan.aiSummary}</p>
|
|
184
|
+
<p className="text-xs text-text-secondary">
|
|
185
|
+
{t(
|
|
186
|
+
'movethewheels.dispatch.ai.disclaimer',
|
|
187
|
+
'Written by AI from the planner’s facts. It never changes an assignment; check before accepting.'
|
|
188
|
+
)}
|
|
189
|
+
{plan.aiModel ? ` (${plan.aiModel})` : ''}
|
|
190
|
+
</p>
|
|
191
|
+
</CardContent>
|
|
192
|
+
</Card>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
const [key, fallback] =
|
|
196
|
+
AI_STATUS_MESSAGES[plan.aiStatus === 'AVAILABLE' ? 'UNAVAILABLE' : plan.aiStatus];
|
|
197
|
+
return (
|
|
198
|
+
<div
|
|
199
|
+
role="status"
|
|
200
|
+
className="rounded-lg border border-status-info-border bg-status-info-bg-subtle px-4 py-3 text-sm text-status-info-text"
|
|
201
|
+
>
|
|
202
|
+
{t(key, fallback)}
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export default function DispatchPlanPage() {
|
|
208
|
+
const { t: translate } = useI18n();
|
|
209
|
+
const t: Translate = (key, fallback) => {
|
|
210
|
+
const value = translate(key);
|
|
211
|
+
return value === key ? fallback : value;
|
|
212
|
+
};
|
|
213
|
+
const { basePath, navigate } = useMoveTheWheels();
|
|
214
|
+
const goTo = (path: string) => navigate?.(joinPath(basePath, path));
|
|
215
|
+
const { plan, isLoading, error, pendingAction, refetch, propose, apply, reject } =
|
|
216
|
+
useDispatchPlan();
|
|
217
|
+
const [horizon, setHorizon] = useState<Horizon>('72h');
|
|
218
|
+
const [choices, setChoices] = useState<Record<string, DispatchChoice>>({});
|
|
219
|
+
const [actionError, setActionError] = useState<string | null>(null);
|
|
220
|
+
const { message, notify } = useNotice(6000);
|
|
221
|
+
|
|
222
|
+
// A different plan (new proposal, or a decision returned by the server) starts with no choices.
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
setChoices({});
|
|
225
|
+
}, [plan?.id, plan?.status]);
|
|
226
|
+
|
|
227
|
+
const open = plan?.status === 'PROPOSED';
|
|
228
|
+
const busy = pendingAction !== null;
|
|
229
|
+
const acceptIds = useMemo(
|
|
230
|
+
() => (plan ? plan.assignments.filter((a) => choices[a.id] === 'accept').map((a) => a.id) : []),
|
|
231
|
+
[plan, choices]
|
|
232
|
+
);
|
|
233
|
+
const undecided = plan
|
|
234
|
+
? plan.assignments.filter((a) => a.decision === 'PENDING' && !choices[a.id]).length
|
|
235
|
+
: 0;
|
|
236
|
+
|
|
237
|
+
const runAction = async (
|
|
238
|
+
action: () => Promise<DispatchPlan>,
|
|
239
|
+
success: (p: DispatchPlan) => string
|
|
240
|
+
) => {
|
|
241
|
+
setActionError(null);
|
|
242
|
+
try {
|
|
243
|
+
notify(success(await action()));
|
|
244
|
+
} catch (e) {
|
|
245
|
+
setActionError(e instanceof Error ? e.message : 'The request failed.');
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const onPropose = () =>
|
|
250
|
+
runAction(
|
|
251
|
+
() => propose(horizonWindow(horizon)),
|
|
252
|
+
(p) =>
|
|
253
|
+
p.assignments.length > 0
|
|
254
|
+
? t(
|
|
255
|
+
'movethewheels.dispatch.notice.proposed',
|
|
256
|
+
'New proposal ready. Nothing is written until you accept.'
|
|
257
|
+
)
|
|
258
|
+
: t(
|
|
259
|
+
'movethewheels.dispatch.notice.proposedEmpty',
|
|
260
|
+
'No shipment could be assigned right now.'
|
|
261
|
+
)
|
|
262
|
+
);
|
|
263
|
+
const onApply = () =>
|
|
264
|
+
plan &&
|
|
265
|
+
runAction(
|
|
266
|
+
() => apply(plan.id, acceptIds),
|
|
267
|
+
(p) =>
|
|
268
|
+
`${t('movethewheels.dispatch.notice.applied', 'Decisions applied. Routes created')}: ${p.acceptedCount}`
|
|
269
|
+
);
|
|
270
|
+
const onReject = () =>
|
|
271
|
+
plan &&
|
|
272
|
+
runAction(
|
|
273
|
+
() => reject(plan.id),
|
|
274
|
+
() => t('movethewheels.dispatch.notice.rejected', 'Proposal rejected. Nothing was written.')
|
|
275
|
+
);
|
|
276
|
+
const setAll = (choice: DispatchChoice) =>
|
|
277
|
+
plan && setChoices(Object.fromEntries(plan.assignments.map((a) => [a.id, choice])));
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<PageLayout
|
|
281
|
+
title={t('movethewheels.dispatch.title', 'Dispatch planner')}
|
|
282
|
+
subtitle={t(
|
|
283
|
+
'movethewheels.dispatch.subtitle',
|
|
284
|
+
'Proposed vehicle and driver assignments for planned shipments — you decide what becomes a route.'
|
|
285
|
+
)}
|
|
286
|
+
icon={<Wand2 size={24} aria-hidden="true" />}
|
|
287
|
+
headerActions={
|
|
288
|
+
<CTAOverflowMenu
|
|
289
|
+
primary={{
|
|
290
|
+
label: t('movethewheels.dispatch.manual', 'Create route manually'),
|
|
291
|
+
icon: <Plus size={16} />,
|
|
292
|
+
onSelect: () => goTo('routes/new'),
|
|
293
|
+
}}
|
|
294
|
+
actions={[
|
|
295
|
+
{
|
|
296
|
+
label: t('movethewheels.dispatch.allRoutes', 'All routes'),
|
|
297
|
+
icon: <Navigation size={16} />,
|
|
298
|
+
onSelect: () => goTo('routes'),
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
label: t('movethewheels.dispatch.refresh', 'Refresh'),
|
|
302
|
+
icon: <RefreshCw size={16} />,
|
|
303
|
+
onSelect: () => refetch(),
|
|
304
|
+
},
|
|
305
|
+
]}
|
|
306
|
+
/>
|
|
307
|
+
}
|
|
308
|
+
>
|
|
309
|
+
<PagePurpose icon={<Wand2 size={18} />}>
|
|
310
|
+
{t(
|
|
311
|
+
'movethewheels.dispatch.purpose',
|
|
312
|
+
'The planner pairs each planned shipment that has no route with a free, linked vehicle and driver, earliest due first, and explains why. Proposing writes nothing. Accept the cards you agree with and apply: each accepted card becomes a planned route, checked again at that moment; everything else is rejected.'
|
|
313
|
+
)}
|
|
314
|
+
</PagePurpose>
|
|
315
|
+
|
|
316
|
+
<Card>
|
|
317
|
+
<CardContent className="flex flex-wrap items-center gap-3 p-4">
|
|
318
|
+
<span className="text-sm font-medium">
|
|
319
|
+
{t('movethewheels.dispatch.horizon', 'Shipments due within')}
|
|
320
|
+
</span>
|
|
321
|
+
<Select value={horizon} onValueChange={(value) => setHorizon(value as Horizon)}>
|
|
322
|
+
<SelectTrigger
|
|
323
|
+
className="w-[180px]"
|
|
324
|
+
aria-label={t('movethewheels.dispatch.horizon', 'Shipments due within')}
|
|
325
|
+
>
|
|
326
|
+
<SelectValue />
|
|
327
|
+
</SelectTrigger>
|
|
328
|
+
<SelectContent>
|
|
329
|
+
<SelectItem value="24h">
|
|
330
|
+
{t('movethewheels.dispatch.horizon.24h', 'Next 24 hours')}
|
|
331
|
+
</SelectItem>
|
|
332
|
+
<SelectItem value="72h">
|
|
333
|
+
{t('movethewheels.dispatch.horizon.72h', 'Next 3 days')}
|
|
334
|
+
</SelectItem>
|
|
335
|
+
<SelectItem value="7d">
|
|
336
|
+
{t('movethewheels.dispatch.horizon.7d', 'Next 7 days')}
|
|
337
|
+
</SelectItem>
|
|
338
|
+
<SelectItem value="all">
|
|
339
|
+
{t('movethewheels.dispatch.horizon.all', 'Any due date')}
|
|
340
|
+
</SelectItem>
|
|
341
|
+
</SelectContent>
|
|
342
|
+
</Select>
|
|
343
|
+
<Button onClick={onPropose} disabled={busy}>
|
|
344
|
+
{pendingAction === 'propose' ? (
|
|
345
|
+
<Loader2 size={16} className="animate-spin" aria-hidden="true" />
|
|
346
|
+
) : (
|
|
347
|
+
<Wand2 size={16} aria-hidden="true" />
|
|
348
|
+
)}
|
|
349
|
+
{pendingAction === 'propose'
|
|
350
|
+
? t('movethewheels.dispatch.proposing', 'Proposing…')
|
|
351
|
+
: t('movethewheels.dispatch.propose', 'Propose assignments')}
|
|
352
|
+
</Button>
|
|
353
|
+
<span className="text-xs text-text-secondary">
|
|
354
|
+
{t(
|
|
355
|
+
'movethewheels.dispatch.noUndatedNote',
|
|
356
|
+
'Shipments without a due date are always included.'
|
|
357
|
+
)}
|
|
358
|
+
</span>
|
|
359
|
+
</CardContent>
|
|
360
|
+
</Card>
|
|
361
|
+
|
|
362
|
+
<Notice message={message} />
|
|
363
|
+
<FormError message={actionError} />
|
|
364
|
+
|
|
365
|
+
{isLoading && !plan ? (
|
|
366
|
+
<div className="space-y-3">
|
|
367
|
+
<Skeleton className="h-24 w-full" />
|
|
368
|
+
<Skeleton className="h-40 w-full" />
|
|
369
|
+
</div>
|
|
370
|
+
) : error ? (
|
|
371
|
+
<Card className="border-status-error-border">
|
|
372
|
+
<CardContent className="space-y-3 p-6 text-center">
|
|
373
|
+
<p className="font-medium text-status-error-text">
|
|
374
|
+
{t('movethewheels.dispatch.loadError', "Couldn't load the dispatch plan")}
|
|
375
|
+
</p>
|
|
376
|
+
<p className="text-sm text-text-secondary">{error.message}</p>
|
|
377
|
+
<Button variant="outline" onClick={refetch}>
|
|
378
|
+
{t('movethewheels.fleet.error.retry', 'Retry')}
|
|
379
|
+
</Button>
|
|
380
|
+
</CardContent>
|
|
381
|
+
</Card>
|
|
382
|
+
) : !plan ? (
|
|
383
|
+
<Card>
|
|
384
|
+
<CardContent className="space-y-2 p-6 text-center">
|
|
385
|
+
<p className="font-medium text-text-primary">
|
|
386
|
+
{t('movethewheels.dispatch.empty', 'No proposal yet')}
|
|
387
|
+
</p>
|
|
388
|
+
<p className="text-sm text-text-secondary">
|
|
389
|
+
{t(
|
|
390
|
+
'movethewheels.dispatch.emptyHint',
|
|
391
|
+
'Propose assignments to see decision cards for your planned shipments.'
|
|
392
|
+
)}
|
|
393
|
+
</p>
|
|
394
|
+
</CardContent>
|
|
395
|
+
</Card>
|
|
396
|
+
) : (
|
|
397
|
+
<>
|
|
398
|
+
<PlanSummary plan={plan} t={t} />
|
|
399
|
+
<AiExplanation plan={plan} t={t} />
|
|
400
|
+
|
|
401
|
+
{open && plan.assignments.length > 0 && (
|
|
402
|
+
<Card>
|
|
403
|
+
<CardContent className="flex flex-wrap items-center justify-between gap-3 p-4">
|
|
404
|
+
<div className="space-y-1">
|
|
405
|
+
<p className="text-sm font-medium text-text-primary" aria-live="polite">
|
|
406
|
+
{acceptIds.length} {t('movethewheels.dispatch.toAccept', 'to accept')} ·{' '}
|
|
407
|
+
{plan.assignments.length - acceptIds.length}{' '}
|
|
408
|
+
{t('movethewheels.dispatch.toReject', 'to reject')}
|
|
409
|
+
</p>
|
|
410
|
+
{undecided > 0 && (
|
|
411
|
+
<p className="text-xs text-text-secondary">
|
|
412
|
+
{t(
|
|
413
|
+
'movethewheels.dispatch.undecidedNote',
|
|
414
|
+
'Cards you have not accepted are rejected when you apply.'
|
|
415
|
+
)}
|
|
416
|
+
</p>
|
|
417
|
+
)}
|
|
418
|
+
</div>
|
|
419
|
+
<div className="flex flex-wrap gap-2">
|
|
420
|
+
<Button
|
|
421
|
+
variant="ghost"
|
|
422
|
+
size="sm"
|
|
423
|
+
disabled={busy}
|
|
424
|
+
onClick={() => setAll('accept')}
|
|
425
|
+
>
|
|
426
|
+
{t('movethewheels.dispatch.acceptAll', 'Accept all')}
|
|
427
|
+
</Button>
|
|
428
|
+
<Button variant="ghost" size="sm" disabled={busy} onClick={() => setAll(null)}>
|
|
429
|
+
{t('movethewheels.dispatch.clear', 'Clear')}
|
|
430
|
+
</Button>
|
|
431
|
+
<Button variant="outline" disabled={busy} onClick={onReject}>
|
|
432
|
+
{pendingAction === 'reject' && (
|
|
433
|
+
<Loader2 size={16} className="animate-spin" aria-hidden="true" />
|
|
434
|
+
)}
|
|
435
|
+
{t('movethewheels.dispatch.rejectPlan', 'Reject proposal')}
|
|
436
|
+
</Button>
|
|
437
|
+
<Button disabled={busy || acceptIds.length === 0} onClick={onApply}>
|
|
438
|
+
{pendingAction === 'apply' && (
|
|
439
|
+
<Loader2 size={16} className="animate-spin" aria-hidden="true" />
|
|
440
|
+
)}
|
|
441
|
+
{pendingAction === 'apply'
|
|
442
|
+
? t('movethewheels.dispatch.applying', 'Creating routes…')
|
|
443
|
+
: t('movethewheels.dispatch.apply', 'Apply decisions')}
|
|
444
|
+
</Button>
|
|
445
|
+
</div>
|
|
446
|
+
</CardContent>
|
|
447
|
+
</Card>
|
|
448
|
+
)}
|
|
449
|
+
|
|
450
|
+
{plan.assignments.length > 0 && (
|
|
451
|
+
<section
|
|
452
|
+
aria-label={t('movethewheels.dispatch.cards', 'Decision cards')}
|
|
453
|
+
className="grid gap-4 lg:grid-cols-2"
|
|
454
|
+
>
|
|
455
|
+
{plan.assignments.map((assignment) => (
|
|
456
|
+
<DispatchDecisionCard
|
|
457
|
+
key={assignment.id}
|
|
458
|
+
assignment={assignment}
|
|
459
|
+
open={open}
|
|
460
|
+
choice={choices[assignment.id] ?? null}
|
|
461
|
+
disabled={busy}
|
|
462
|
+
onChoose={(choice) =>
|
|
463
|
+
setChoices((current) => ({ ...current, [assignment.id]: choice }))
|
|
464
|
+
}
|
|
465
|
+
onOpenRoute={(routeId) => goTo(`routes/${routeId}`)}
|
|
466
|
+
t={t}
|
|
467
|
+
/>
|
|
468
|
+
))}
|
|
469
|
+
</section>
|
|
470
|
+
)}
|
|
471
|
+
|
|
472
|
+
{plan.unassigned.length > 0 && (
|
|
473
|
+
<Card>
|
|
474
|
+
<CardHeader>
|
|
475
|
+
<CardTitle className="text-base">
|
|
476
|
+
{t('movethewheels.dispatch.unassignedTitle', 'Not assigned')}
|
|
477
|
+
</CardTitle>
|
|
478
|
+
</CardHeader>
|
|
479
|
+
<CardContent>
|
|
480
|
+
<ul className="divide-y">
|
|
481
|
+
{plan.unassigned.map((u) => {
|
|
482
|
+
const entry = UNASSIGNED_REASONS[u.reason];
|
|
483
|
+
return (
|
|
484
|
+
<li
|
|
485
|
+
key={u.shipmentId}
|
|
486
|
+
className="flex flex-wrap justify-between gap-2 py-2 text-sm"
|
|
487
|
+
>
|
|
488
|
+
<span className="font-medium break-words">
|
|
489
|
+
{u.shipmentNumber ?? u.shipmentId}
|
|
490
|
+
</span>
|
|
491
|
+
<span className="text-text-secondary">
|
|
492
|
+
{entry ? t(entry[0], entry[1]) : u.reason}
|
|
493
|
+
</span>
|
|
494
|
+
</li>
|
|
495
|
+
);
|
|
496
|
+
})}
|
|
497
|
+
</ul>
|
|
498
|
+
</CardContent>
|
|
499
|
+
</Card>
|
|
500
|
+
)}
|
|
501
|
+
</>
|
|
502
|
+
)}
|
|
503
|
+
</PageLayout>
|
|
504
|
+
);
|
|
505
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { useState } from 'react';
|
|
6
|
-
import { Plus, RefreshCw, Navigation, Filter } from 'lucide-react';
|
|
6
|
+
import { Plus, RefreshCw, Navigation, Filter, Wand2 } from 'lucide-react';
|
|
7
7
|
import { PageLayout } from '../components/PageLayout';
|
|
8
8
|
import { DataTable, type Column } from '../components/DataTable';
|
|
9
9
|
import { StatusBadge } from '../components/StatusBadge';
|
|
@@ -116,7 +116,14 @@ export default function RoutesPage() {
|
|
|
116
116
|
icon: <Plus size={16} />,
|
|
117
117
|
onSelect: () => goTo('routes/new'),
|
|
118
118
|
}}
|
|
119
|
-
actions={[
|
|
119
|
+
actions={[
|
|
120
|
+
{
|
|
121
|
+
label: 'Plan dispatch',
|
|
122
|
+
icon: <Wand2 size={16} />,
|
|
123
|
+
onSelect: () => goTo('routes/dispatch-plan'),
|
|
124
|
+
},
|
|
125
|
+
{ label: 'Refresh', icon: <RefreshCw size={16} />, onSelect: () => refetch() },
|
|
126
|
+
]}
|
|
120
127
|
/>
|
|
121
128
|
}
|
|
122
129
|
>
|