@burdenoff/microfe-movethewheels 2026.1107.6 → 2026.1108.1
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/components/CarrierRecommendationDialog.js +21 -0
- package/dist/components/DispatchDecisionCard.js +111 -97
- package/dist/components/InventoryCoverPanel.js +401 -0
- package/dist/components/ShipmentDecisionPanel.js +362 -0
- package/dist/components/ShipmentRiskDialog.js +134 -89
- package/dist/generated/tracking-quality-operations.d.ts +288 -0
- package/dist/generated/wspace-types.d.ts +1645 -0
- package/dist/hooks/useInventoryCoverPlan.js +70 -0
- package/dist/hooks/useShipmentDecision.js +111 -0
- package/dist/movethewheels/components/CarrierRecommendationDialog.d.ts +20 -0
- package/dist/movethewheels/components/DispatchDecisionCard.d.ts +5 -1
- package/dist/movethewheels/components/InventoryCoverPanel.d.ts +24 -0
- package/dist/movethewheels/components/ShipmentDecisionPanel.d.ts +14 -0
- package/dist/movethewheels/hooks/useDispatchPlan.d.ts +1 -1
- package/dist/movethewheels/hooks/useInventoryCoverPlan.d.ts +80 -0
- package/dist/movethewheels/hooks/useShipmentDecision.d.ts +67 -0
- package/dist/pages/DispatchPlanPage.js +198 -171
- package/dist/pages/InventoryPage.js +219 -214
- package/package.json +1 -1
- package/src/generated/tracking-quality-operations.ts +321 -0
- package/src/generated/wspace-types.ts +1861 -0
- package/src/movethewheels/components/CarrierRecommendationDialog.tsx +54 -0
- package/src/movethewheels/components/DispatchDecisionCard.tsx +17 -2
- package/src/movethewheels/components/InventoryCoverPanel.tsx +449 -0
- package/src/movethewheels/components/ShipmentDecisionPanel.tsx +459 -0
- package/src/movethewheels/components/ShipmentRiskDialog.tsx +67 -1
- package/src/movethewheels/hooks/useInventoryCoverPlan.ts +250 -0
- package/src/movethewheels/hooks/useShipmentDecision.ts +318 -0
- package/src/movethewheels/pages/DispatchPlanPage.tsx +30 -1
- package/src/movethewheels/pages/InventoryPage.tsx +8 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
4
|
+
import { executeGraphQL } from '../utils/graphqlClient';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Inventory planning (BOFF-10926). Runs the read-only `inventoryCoverPlan`
|
|
8
|
+
* query: weeks of stock cover per warehouse and SKU against forecast
|
|
9
|
+
* outbound demand, with the projected stock-out week and a suggested
|
|
10
|
+
* reorder quantity.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export type CoverStatus =
|
|
14
|
+
'OUT_OF_STOCK' | 'AT_RISK' | 'REORDER' | 'HEALTHY' | 'NOT_ENOUGH_HISTORY' | 'NO_DEMAND';
|
|
15
|
+
|
|
16
|
+
export type DemandStatus = 'FORECAST' | 'NOT_ENOUGH_HISTORY' | 'NO_DEMAND';
|
|
17
|
+
|
|
18
|
+
/** Statuses that ask the planner to act, most urgent first. */
|
|
19
|
+
export const ACTION_STATUSES: CoverStatus[] = ['OUT_OF_STOCK', 'AT_RISK', 'REORDER'];
|
|
20
|
+
|
|
21
|
+
export interface CoverPlanRequest {
|
|
22
|
+
warehouseId: string | null;
|
|
23
|
+
leadTimeWeeks: number;
|
|
24
|
+
targetCoverWeeks: number;
|
|
25
|
+
demandChangePct: number;
|
|
26
|
+
/** Only rows that need action; the summary always counts every row. */
|
|
27
|
+
actionOnly: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CoverPlanRow {
|
|
31
|
+
warehouseId: string;
|
|
32
|
+
warehouseName: string;
|
|
33
|
+
warehouseCode: string;
|
|
34
|
+
cargoItemId: string;
|
|
35
|
+
sku: string;
|
|
36
|
+
name: string;
|
|
37
|
+
onHand: number;
|
|
38
|
+
damaged: number;
|
|
39
|
+
usableStock: number;
|
|
40
|
+
reorderPoint: number | null;
|
|
41
|
+
safetyStock: number | null;
|
|
42
|
+
demandStatus: DemandStatus;
|
|
43
|
+
weeksOfHistory: number;
|
|
44
|
+
weeklyUnits: number[];
|
|
45
|
+
currentWeekUnits: number;
|
|
46
|
+
baselineWeeklyDemand: number | null;
|
|
47
|
+
forecastWeeklyDemand: number | null;
|
|
48
|
+
weeksOfCover: number | null;
|
|
49
|
+
projectedStockOutWeek: string | null;
|
|
50
|
+
stockOutBeforeLeadTime: boolean;
|
|
51
|
+
suggestedReorderQuantity: number | null;
|
|
52
|
+
status: CoverStatus;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface CoverPlanSummary {
|
|
56
|
+
totalItems: number;
|
|
57
|
+
outOfStock: number;
|
|
58
|
+
atRisk: number;
|
|
59
|
+
reorder: number;
|
|
60
|
+
healthy: number;
|
|
61
|
+
notEnoughHistory: number;
|
|
62
|
+
noDemand: number;
|
|
63
|
+
totalSuggestedReorderQuantity: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface CoverPlan {
|
|
67
|
+
generatedAt: string;
|
|
68
|
+
historyStart: string;
|
|
69
|
+
historyEnd: string;
|
|
70
|
+
historyWeeks: number;
|
|
71
|
+
warehouseId: string | null;
|
|
72
|
+
leadTimeWeeks: number;
|
|
73
|
+
targetCoverWeeks: number;
|
|
74
|
+
demandChangePct: number;
|
|
75
|
+
summary: CoverPlanSummary;
|
|
76
|
+
unattributedUnits: number;
|
|
77
|
+
unattributedJobs: number;
|
|
78
|
+
truncated: boolean;
|
|
79
|
+
matchingItems: number;
|
|
80
|
+
rows: CoverPlanRow[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const COVER_PLAN_QUERY = `
|
|
84
|
+
query GetMovethewheelsInventoryCoverPlan($input: InventoryCoverPlanInput) {
|
|
85
|
+
inventoryCoverPlan(input: $input) {
|
|
86
|
+
generatedAt
|
|
87
|
+
historyStart
|
|
88
|
+
historyEnd
|
|
89
|
+
historyWeeks
|
|
90
|
+
warehouseId
|
|
91
|
+
leadTimeWeeks
|
|
92
|
+
targetCoverWeeks
|
|
93
|
+
demandChangePct
|
|
94
|
+
summary {
|
|
95
|
+
totalItems
|
|
96
|
+
outOfStock
|
|
97
|
+
atRisk
|
|
98
|
+
reorder
|
|
99
|
+
healthy
|
|
100
|
+
notEnoughHistory
|
|
101
|
+
noDemand
|
|
102
|
+
totalSuggestedReorderQuantity
|
|
103
|
+
}
|
|
104
|
+
unattributedUnits
|
|
105
|
+
unattributedJobs
|
|
106
|
+
truncated
|
|
107
|
+
matchingItems
|
|
108
|
+
rows {
|
|
109
|
+
warehouseId
|
|
110
|
+
warehouseName
|
|
111
|
+
warehouseCode
|
|
112
|
+
cargoItemId
|
|
113
|
+
sku
|
|
114
|
+
name
|
|
115
|
+
onHand
|
|
116
|
+
damaged
|
|
117
|
+
usableStock
|
|
118
|
+
reorderPoint
|
|
119
|
+
safetyStock
|
|
120
|
+
demandStatus
|
|
121
|
+
weeksOfHistory
|
|
122
|
+
weeklyUnits
|
|
123
|
+
currentWeekUnits
|
|
124
|
+
baselineWeeklyDemand
|
|
125
|
+
forecastWeeklyDemand
|
|
126
|
+
weeksOfCover
|
|
127
|
+
projectedStockOutWeek
|
|
128
|
+
stockOutBeforeLeadTime
|
|
129
|
+
suggestedReorderQuantity
|
|
130
|
+
status
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
/** Rows the panel asks for; the summary still counts every position. */
|
|
137
|
+
export const COVER_PLAN_ROW_LIMIT = 200;
|
|
138
|
+
|
|
139
|
+
export const DEFAULT_COVER_REQUEST: CoverPlanRequest = {
|
|
140
|
+
warehouseId: null,
|
|
141
|
+
leadTimeWeeks: 2,
|
|
142
|
+
targetCoverWeeks: 6,
|
|
143
|
+
demandChangePct: 0,
|
|
144
|
+
actionOnly: false,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
interface UseInventoryCoverPlanResult {
|
|
148
|
+
plan: CoverPlan | null;
|
|
149
|
+
isLoading: boolean;
|
|
150
|
+
error: Error | null;
|
|
151
|
+
/** Run a plan; the latest request wins if several overlap. */
|
|
152
|
+
run: (request: CoverPlanRequest) => void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function useInventoryCoverPlan(
|
|
156
|
+
initial: CoverPlanRequest = DEFAULT_COVER_REQUEST
|
|
157
|
+
): UseInventoryCoverPlanResult {
|
|
158
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
159
|
+
useMoveTheWheels();
|
|
160
|
+
const [plan, setPlan] = useState<CoverPlan | null>(null);
|
|
161
|
+
// The plan is fetched on mount, so start in the loading state to show the
|
|
162
|
+
// skeleton on the first render instead of an empty panel.
|
|
163
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
164
|
+
const [error, setError] = useState<Error | null>(null);
|
|
165
|
+
const latest = useRef(0);
|
|
166
|
+
// The in-flight request, aborted when a newer one starts or on unmount.
|
|
167
|
+
const inFlight = useRef<AbortController | null>(null);
|
|
168
|
+
// Re-run the user's last request (not the initial one) when the auth
|
|
169
|
+
// context changes, so a token refresh never resets their settings.
|
|
170
|
+
const lastRequest = useRef(initial);
|
|
171
|
+
|
|
172
|
+
const graphQLOptions = useMemo(
|
|
173
|
+
() => ({
|
|
174
|
+
apiGatewayUrl,
|
|
175
|
+
authToken,
|
|
176
|
+
workspaceToken,
|
|
177
|
+
workspaceId,
|
|
178
|
+
tenantId,
|
|
179
|
+
actorId: currentUser?.id,
|
|
180
|
+
}),
|
|
181
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const load = useCallback(
|
|
185
|
+
async (request: CoverPlanRequest) => {
|
|
186
|
+
lastRequest.current = request;
|
|
187
|
+
const id = latest.current + 1;
|
|
188
|
+
latest.current = id;
|
|
189
|
+
inFlight.current?.abort();
|
|
190
|
+
const controller = new AbortController();
|
|
191
|
+
inFlight.current = controller;
|
|
192
|
+
setIsLoading(true);
|
|
193
|
+
setError(null);
|
|
194
|
+
try {
|
|
195
|
+
const data = await executeGraphQL<{ inventoryCoverPlan: CoverPlan }>(
|
|
196
|
+
{ ...graphQLOptions, signal: controller.signal },
|
|
197
|
+
COVER_PLAN_QUERY,
|
|
198
|
+
{
|
|
199
|
+
input: {
|
|
200
|
+
warehouseId: request.warehouseId,
|
|
201
|
+
leadTimeWeeks: request.leadTimeWeeks,
|
|
202
|
+
targetCoverWeeks: request.targetCoverWeeks,
|
|
203
|
+
demandChangePct: request.demandChangePct,
|
|
204
|
+
statuses: request.actionOnly ? ACTION_STATUSES : null,
|
|
205
|
+
limit: COVER_PLAN_ROW_LIMIT,
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
if (latest.current === id) {
|
|
210
|
+
setPlan(data.inventoryCoverPlan);
|
|
211
|
+
}
|
|
212
|
+
} catch (fetchError) {
|
|
213
|
+
if (latest.current === id && !controller.signal.aborted) {
|
|
214
|
+
setError(
|
|
215
|
+
fetchError instanceof Error
|
|
216
|
+
? fetchError
|
|
217
|
+
: new Error('Failed to load the stock cover plan')
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
} finally {
|
|
221
|
+
if (latest.current === id) {
|
|
222
|
+
setIsLoading(false);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
[graphQLOptions]
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
void load(lastRequest.current);
|
|
231
|
+
}, [load]);
|
|
232
|
+
|
|
233
|
+
useEffect(
|
|
234
|
+
() => () => {
|
|
235
|
+
// Invalidate and cancel whatever is in flight when the panel unmounts.
|
|
236
|
+
latest.current += 1;
|
|
237
|
+
inFlight.current?.abort();
|
|
238
|
+
},
|
|
239
|
+
[]
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const run = useCallback(
|
|
243
|
+
(request: CoverPlanRequest) => {
|
|
244
|
+
void load(request);
|
|
245
|
+
},
|
|
246
|
+
[load]
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
return { plan, isLoading, error, run };
|
|
250
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shipment decision proposals (BOFF-10908).
|
|
3
|
+
*
|
|
4
|
+
* Reads a shipment's latest decision of one kind and drives its three steps:
|
|
5
|
+
*
|
|
6
|
+
* - `propose` calls `mtwRecommendCarrier` (carrier recommendation) or
|
|
7
|
+
* `mtwResolveException` (exception remediation). Both only store a proposal.
|
|
8
|
+
* - `accept(optionId)` calls `mtwAcceptShipmentDecision`. An APPLY option
|
|
9
|
+
* changes the shipment (carrier or promised delivery); FOLLOW_UP and RECORD
|
|
10
|
+
* options only record the decision.
|
|
11
|
+
* - `reject` calls `mtwRejectShipmentDecision`, which changes nothing.
|
|
12
|
+
*
|
|
13
|
+
* The server decides everything (ranking, staleness, expiry, AI credit gating).
|
|
14
|
+
* This hook only reflects the record the server returns after each call.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
18
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
19
|
+
import { executeGraphQL } from '../utils/graphqlClient';
|
|
20
|
+
import type { DecisionRationaleStatus } from './useDispatchPlan';
|
|
21
|
+
|
|
22
|
+
export type ShipmentDecisionKind = 'CARRIER_RECOMMENDATION' | 'EXCEPTION_REMEDIATION';
|
|
23
|
+
export type ShipmentDecisionStatus = 'PROPOSED' | 'ACCEPTED' | 'REJECTED' | 'STALE' | 'EXPIRED';
|
|
24
|
+
export type ShipmentDecisionAction =
|
|
25
|
+
| 'USE_CARRIER'
|
|
26
|
+
| 'REASSIGN_VEHICLE'
|
|
27
|
+
| 'REPROMISE_DELIVERY'
|
|
28
|
+
| 'REQUEST_TRACKING_UPDATE'
|
|
29
|
+
| 'SWITCH_CARRIER'
|
|
30
|
+
| 'ACCEPT_SLIP';
|
|
31
|
+
export type ShipmentDecisionExecution = 'APPLY' | 'FOLLOW_UP' | 'RECORD';
|
|
32
|
+
export type ShipmentDecisionOutcome = 'APPLIED' | 'RECORDED' | 'FOLLOW_UP';
|
|
33
|
+
|
|
34
|
+
export interface ShipmentDecisionOption {
|
|
35
|
+
id: string;
|
|
36
|
+
rank: number;
|
|
37
|
+
action: ShipmentDecisionAction;
|
|
38
|
+
execution: ShipmentDecisionExecution;
|
|
39
|
+
confidence: number;
|
|
40
|
+
score: number | null;
|
|
41
|
+
reasons: string[];
|
|
42
|
+
rationale: string;
|
|
43
|
+
aiRationale: string | null;
|
|
44
|
+
carrierId: string | null;
|
|
45
|
+
newEstimatedDelivery: string | null;
|
|
46
|
+
followUpMutation: string | null;
|
|
47
|
+
followUpArgs: Record<string, string> | null;
|
|
48
|
+
deliveredCount: number | null;
|
|
49
|
+
onTimeCount: number | null;
|
|
50
|
+
laneDeliveredCount: number | null;
|
|
51
|
+
laneOnTimeCount: number | null;
|
|
52
|
+
medianLaneCost: number | null;
|
|
53
|
+
currency: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ShipmentDecision {
|
|
57
|
+
id: string;
|
|
58
|
+
kind: ShipmentDecisionKind;
|
|
59
|
+
shipmentId: string;
|
|
60
|
+
shipmentNumber: string | null;
|
|
61
|
+
status: ShipmentDecisionStatus;
|
|
62
|
+
method: string;
|
|
63
|
+
options: ShipmentDecisionOption[];
|
|
64
|
+
chosenOptionId: string | null;
|
|
65
|
+
outcome: ShipmentDecisionOutcome | null;
|
|
66
|
+
decisionReason: string | null;
|
|
67
|
+
currentCarrierId: string | null;
|
|
68
|
+
promisedDelivery: string | null;
|
|
69
|
+
riskScore: number | null;
|
|
70
|
+
predictedSlipMinutes: number | null;
|
|
71
|
+
breached: boolean | null;
|
|
72
|
+
laneKnown: boolean | null;
|
|
73
|
+
historyCount: number | null;
|
|
74
|
+
aiStatus: DecisionRationaleStatus;
|
|
75
|
+
aiSummary: string | null;
|
|
76
|
+
aiModel: string | null;
|
|
77
|
+
expiresAt: string;
|
|
78
|
+
decidedAt: string | null;
|
|
79
|
+
createdAt: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const DECISION_FIELDS = `
|
|
83
|
+
id
|
|
84
|
+
kind
|
|
85
|
+
shipmentId
|
|
86
|
+
shipmentNumber
|
|
87
|
+
status
|
|
88
|
+
method
|
|
89
|
+
options {
|
|
90
|
+
id
|
|
91
|
+
rank
|
|
92
|
+
action
|
|
93
|
+
execution
|
|
94
|
+
confidence
|
|
95
|
+
score
|
|
96
|
+
reasons
|
|
97
|
+
rationale
|
|
98
|
+
aiRationale
|
|
99
|
+
carrierId
|
|
100
|
+
newEstimatedDelivery
|
|
101
|
+
followUpMutation
|
|
102
|
+
followUpArgs
|
|
103
|
+
deliveredCount
|
|
104
|
+
onTimeCount
|
|
105
|
+
laneDeliveredCount
|
|
106
|
+
laneOnTimeCount
|
|
107
|
+
medianLaneCost
|
|
108
|
+
currency
|
|
109
|
+
}
|
|
110
|
+
chosenOptionId
|
|
111
|
+
outcome
|
|
112
|
+
decisionReason
|
|
113
|
+
currentCarrierId
|
|
114
|
+
promisedDelivery
|
|
115
|
+
riskScore
|
|
116
|
+
predictedSlipMinutes
|
|
117
|
+
breached
|
|
118
|
+
laneKnown
|
|
119
|
+
historyCount
|
|
120
|
+
aiStatus
|
|
121
|
+
aiSummary
|
|
122
|
+
aiModel
|
|
123
|
+
expiresAt
|
|
124
|
+
decidedAt
|
|
125
|
+
createdAt
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
const LATEST_QUERY = `
|
|
129
|
+
query LatestShipmentDecision($shipmentId: ID!, $kind: MtwShipmentDecisionKind!) {
|
|
130
|
+
mtwLatestShipmentDecision(shipmentId: $shipmentId, kind: $kind) {
|
|
131
|
+
${DECISION_FIELDS}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
const RECOMMEND_CARRIER_MUTATION = `
|
|
137
|
+
mutation RecommendCarrier($shipmentId: ID!) {
|
|
138
|
+
mtwRecommendCarrier(shipmentId: $shipmentId) {
|
|
139
|
+
${DECISION_FIELDS}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
const RESOLVE_EXCEPTION_MUTATION = `
|
|
145
|
+
mutation ResolveException($shipmentId: ID!) {
|
|
146
|
+
mtwResolveException(shipmentId: $shipmentId) {
|
|
147
|
+
${DECISION_FIELDS}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
const ACCEPT_MUTATION = `
|
|
153
|
+
mutation AcceptShipmentDecision($decisionId: ID!, $optionId: ID!) {
|
|
154
|
+
mtwAcceptShipmentDecision(decisionId: $decisionId, optionId: $optionId) {
|
|
155
|
+
${DECISION_FIELDS}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
const REJECT_MUTATION = `
|
|
161
|
+
mutation RejectShipmentDecision($decisionId: ID!) {
|
|
162
|
+
mtwRejectShipmentDecision(decisionId: $decisionId) {
|
|
163
|
+
${DECISION_FIELDS}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
type PendingAction = 'propose' | 'accept' | 'reject';
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param shipmentId the shipment, or undefined while nothing is selected (no request is made)
|
|
172
|
+
*/
|
|
173
|
+
export function useShipmentDecision(shipmentId: string | undefined, kind: ShipmentDecisionKind) {
|
|
174
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
175
|
+
useMoveTheWheels();
|
|
176
|
+
const graphQLOptions = useMemo(
|
|
177
|
+
() => ({
|
|
178
|
+
apiGatewayUrl,
|
|
179
|
+
authToken,
|
|
180
|
+
workspaceToken,
|
|
181
|
+
workspaceId,
|
|
182
|
+
tenantId,
|
|
183
|
+
actorId: currentUser?.id,
|
|
184
|
+
}),
|
|
185
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
186
|
+
);
|
|
187
|
+
const [decision, setDecision] = useState<ShipmentDecision | null>(null);
|
|
188
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
189
|
+
const [error, setError] = useState<Error | null>(null);
|
|
190
|
+
const [pendingAction, setPendingAction] = useState<PendingAction | null>(null);
|
|
191
|
+
|
|
192
|
+
const load = useCallback(
|
|
193
|
+
async (signal?: AbortSignal) => {
|
|
194
|
+
if (!shipmentId) return;
|
|
195
|
+
setIsLoading(true);
|
|
196
|
+
setError(null);
|
|
197
|
+
try {
|
|
198
|
+
const data = await executeGraphQL<{ mtwLatestShipmentDecision: ShipmentDecision | null }>(
|
|
199
|
+
{ ...graphQLOptions, signal },
|
|
200
|
+
LATEST_QUERY,
|
|
201
|
+
{ shipmentId, kind }
|
|
202
|
+
);
|
|
203
|
+
if (signal?.aborted) return;
|
|
204
|
+
setDecision(data.mtwLatestShipmentDecision);
|
|
205
|
+
} catch (fetchError) {
|
|
206
|
+
if (signal?.aborted) return;
|
|
207
|
+
setError(
|
|
208
|
+
fetchError instanceof Error ? fetchError : new Error('Failed to load the decision')
|
|
209
|
+
);
|
|
210
|
+
} finally {
|
|
211
|
+
if (!signal?.aborted) setIsLoading(false);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
[graphQLOptions, shipmentId, kind]
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
// A newer shipment (or unmount) cancels the older load, so a late reply cannot overwrite it.
|
|
219
|
+
const controller = new AbortController();
|
|
220
|
+
// A different shipment never shows the previous shipment's decision, not even while loading.
|
|
221
|
+
setDecision(null);
|
|
222
|
+
void load(controller.signal);
|
|
223
|
+
return () => controller.abort();
|
|
224
|
+
}, [load]);
|
|
225
|
+
|
|
226
|
+
const run = useCallback(
|
|
227
|
+
async <T>(
|
|
228
|
+
action: PendingAction,
|
|
229
|
+
call: () => Promise<T>,
|
|
230
|
+
pick: (data: T) => ShipmentDecision
|
|
231
|
+
): Promise<ShipmentDecision> => {
|
|
232
|
+
setPendingAction(action);
|
|
233
|
+
try {
|
|
234
|
+
const next = pick(await call());
|
|
235
|
+
setDecision(next);
|
|
236
|
+
return next;
|
|
237
|
+
} catch (actionError) {
|
|
238
|
+
// The proposal may have changed underneath (expired, decided elsewhere): show the stored record.
|
|
239
|
+
void load();
|
|
240
|
+
throw actionError;
|
|
241
|
+
} finally {
|
|
242
|
+
setPendingAction(null);
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
[load]
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const propose = useCallback(() => {
|
|
249
|
+
if (!shipmentId) return Promise.reject(new Error('No shipment selected'));
|
|
250
|
+
if (kind === 'CARRIER_RECOMMENDATION') {
|
|
251
|
+
return run(
|
|
252
|
+
'propose',
|
|
253
|
+
() =>
|
|
254
|
+
executeGraphQL<{ mtwRecommendCarrier: ShipmentDecision }>(
|
|
255
|
+
graphQLOptions,
|
|
256
|
+
RECOMMEND_CARRIER_MUTATION,
|
|
257
|
+
{ shipmentId },
|
|
258
|
+
'SINGLE_ATTEMPT'
|
|
259
|
+
),
|
|
260
|
+
(data) => data.mtwRecommendCarrier
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
return run(
|
|
264
|
+
'propose',
|
|
265
|
+
() =>
|
|
266
|
+
executeGraphQL<{ mtwResolveException: ShipmentDecision }>(
|
|
267
|
+
graphQLOptions,
|
|
268
|
+
RESOLVE_EXCEPTION_MUTATION,
|
|
269
|
+
{ shipmentId },
|
|
270
|
+
'SINGLE_ATTEMPT'
|
|
271
|
+
),
|
|
272
|
+
(data) => data.mtwResolveException
|
|
273
|
+
);
|
|
274
|
+
}, [graphQLOptions, kind, run, shipmentId]);
|
|
275
|
+
|
|
276
|
+
const accept = useCallback(
|
|
277
|
+
(decisionId: string, optionId: string) =>
|
|
278
|
+
run(
|
|
279
|
+
'accept',
|
|
280
|
+
() =>
|
|
281
|
+
executeGraphQL<{ mtwAcceptShipmentDecision: ShipmentDecision }>(
|
|
282
|
+
graphQLOptions,
|
|
283
|
+
ACCEPT_MUTATION,
|
|
284
|
+
{ decisionId, optionId },
|
|
285
|
+
'SINGLE_ATTEMPT'
|
|
286
|
+
),
|
|
287
|
+
(data) => data.mtwAcceptShipmentDecision
|
|
288
|
+
),
|
|
289
|
+
[graphQLOptions, run]
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
const reject = useCallback(
|
|
293
|
+
(decisionId: string) =>
|
|
294
|
+
run(
|
|
295
|
+
'reject',
|
|
296
|
+
() =>
|
|
297
|
+
executeGraphQL<{ mtwRejectShipmentDecision: ShipmentDecision }>(
|
|
298
|
+
graphQLOptions,
|
|
299
|
+
REJECT_MUTATION,
|
|
300
|
+
{ decisionId },
|
|
301
|
+
'SINGLE_ATTEMPT'
|
|
302
|
+
),
|
|
303
|
+
(data) => data.mtwRejectShipmentDecision
|
|
304
|
+
),
|
|
305
|
+
[graphQLOptions, run]
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
decision,
|
|
310
|
+
isLoading,
|
|
311
|
+
error,
|
|
312
|
+
pendingAction,
|
|
313
|
+
refetch: () => void load(),
|
|
314
|
+
propose,
|
|
315
|
+
accept,
|
|
316
|
+
reject,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { useEffect, useMemo, useState } from 'react';
|
|
16
|
-
import { Loader2, Navigation, Plus, RefreshCw, Sparkles, Wand2 } from 'lucide-react';
|
|
16
|
+
import { Building2, Loader2, Navigation, Plus, RefreshCw, Sparkles, Wand2 } from 'lucide-react';
|
|
17
17
|
import { CTAOverflowMenu, EmphasisPanel, PagePurpose } from '@burdenoff/fe-libs/ui';
|
|
18
18
|
import { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';
|
|
19
19
|
|
|
@@ -21,6 +21,7 @@ import { PageLayout } from '../components/PageLayout';
|
|
|
21
21
|
import { FormError } from '../components/FormError';
|
|
22
22
|
import { Notice, useNotice } from '../components/Notice';
|
|
23
23
|
import { DispatchDecisionCard, type DispatchChoice } from '../components/DispatchDecisionCard';
|
|
24
|
+
import { CarrierRecommendationDialog } from '../components/CarrierRecommendationDialog';
|
|
24
25
|
import {
|
|
25
26
|
Badge,
|
|
26
27
|
Button,
|
|
@@ -217,6 +218,7 @@ export default function DispatchPlanPage() {
|
|
|
217
218
|
const [horizon, setHorizon] = useState<Horizon>('72h');
|
|
218
219
|
const [choices, setChoices] = useState<Record<string, DispatchChoice>>({});
|
|
219
220
|
const [actionError, setActionError] = useState<string | null>(null);
|
|
221
|
+
const [carrierFor, setCarrierFor] = useState<{ id: string; number: string | null } | null>(null);
|
|
220
222
|
const { message, notify } = useNotice(6000);
|
|
221
223
|
|
|
222
224
|
// A different plan (new proposal, or a decision returned by the server) starts with no choices.
|
|
@@ -463,6 +465,7 @@ export default function DispatchPlanPage() {
|
|
|
463
465
|
setChoices((current) => ({ ...current, [assignment.id]: choice }))
|
|
464
466
|
}
|
|
465
467
|
onOpenRoute={(routeId) => goTo(`routes/${routeId}`)}
|
|
468
|
+
onRecommendCarrier={(id, number) => setCarrierFor({ id, number })}
|
|
466
469
|
t={t}
|
|
467
470
|
/>
|
|
468
471
|
))}
|
|
@@ -491,6 +494,18 @@ export default function DispatchPlanPage() {
|
|
|
491
494
|
<span className="text-text-secondary">
|
|
492
495
|
{entry ? t(entry[0], entry[1]) : u.reason}
|
|
493
496
|
</span>
|
|
497
|
+
{u.reason !== 'NOT_PLANNABLE' && (
|
|
498
|
+
<Button
|
|
499
|
+
size="sm"
|
|
500
|
+
variant="outline"
|
|
501
|
+
onClick={() =>
|
|
502
|
+
setCarrierFor({ id: u.shipmentId, number: u.shipmentNumber })
|
|
503
|
+
}
|
|
504
|
+
>
|
|
505
|
+
<Building2 size={14} aria-hidden="true" />
|
|
506
|
+
{t('movethewheels.carrierDecision.propose', 'Recommend a carrier')}
|
|
507
|
+
</Button>
|
|
508
|
+
)}
|
|
494
509
|
</li>
|
|
495
510
|
);
|
|
496
511
|
})}
|
|
@@ -500,6 +515,20 @@ export default function DispatchPlanPage() {
|
|
|
500
515
|
)}
|
|
501
516
|
</>
|
|
502
517
|
)}
|
|
518
|
+
|
|
519
|
+
<CarrierRecommendationDialog
|
|
520
|
+
shipment={carrierFor}
|
|
521
|
+
onOpenChange={(isOpen) => !isOpen && setCarrierFor(null)}
|
|
522
|
+
onApplied={() =>
|
|
523
|
+
notify(
|
|
524
|
+
t(
|
|
525
|
+
'movethewheels.carrierDecision.applied',
|
|
526
|
+
'Carrier assigned to the shipment. It stays planned for you to hand over.'
|
|
527
|
+
)
|
|
528
|
+
)
|
|
529
|
+
}
|
|
530
|
+
t={t}
|
|
531
|
+
/>
|
|
503
532
|
</PageLayout>
|
|
504
533
|
);
|
|
505
534
|
}
|
|
@@ -24,6 +24,7 @@ import { MetricCard, MetricGrid, MetricCardSkeleton } from '../components/Metric
|
|
|
24
24
|
import { DataTable, type Column } from '../components/DataTable';
|
|
25
25
|
import { StatusBadge } from '../components/StatusBadge';
|
|
26
26
|
import { Notice, useNotice } from '../components/Notice';
|
|
27
|
+
import { InventoryCoverPanel } from '../components/InventoryCoverPanel';
|
|
27
28
|
import {
|
|
28
29
|
AdjustStockDialog,
|
|
29
30
|
ReceiveStockDialog,
|
|
@@ -135,6 +136,10 @@ export default function InventoryPage() {
|
|
|
135
136
|
limit: pageSize,
|
|
136
137
|
offset: pageIndex * pageSize,
|
|
137
138
|
});
|
|
139
|
+
const coverWarehouses = useMemo(
|
|
140
|
+
() => warehouses.map((warehouse) => ({ id: warehouse.id, name: warehouse.name })),
|
|
141
|
+
[warehouses]
|
|
142
|
+
);
|
|
138
143
|
const { stats, refetch: refetchStats } = useInventoryStats();
|
|
139
144
|
const {
|
|
140
145
|
transactions,
|
|
@@ -454,6 +459,9 @@ export default function InventoryPage() {
|
|
|
454
459
|
</EmphasisPanel>
|
|
455
460
|
)}
|
|
456
461
|
|
|
462
|
+
{/* Inventory planning (BOFF-10926): weeks of cover against forecast outbound demand. */}
|
|
463
|
+
<InventoryCoverPanel warehouses={coverWarehouses} />
|
|
464
|
+
|
|
457
465
|
{/* Stock position + ledger. The table is the per-warehouse stock line;
|
|
458
466
|
the side panel is the real movement history from Query.inventoryTransactions. */}
|
|
459
467
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|