@burdenoff/microfe-movethewheels 2026.1016.13 → 2026.1017.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/hooks/useFleet.js +7 -0
- package/dist/hooks/useOrderDispatch.js +93 -0
- package/dist/hooks/useOrders.js +148 -134
- package/dist/movethewheels/hooks/useOrderDispatch.d.ts +26 -0
- package/dist/movethewheels/hooks/useOrders.d.ts +2 -1
- package/dist/movethewheels/utils/graphqlClient.d.ts +2 -1
- package/dist/movethewheels/utils/orderVehicleHold.d.ts +16 -0
- package/dist/pages/OrderDetailsPage.js +269 -241
- package/dist/utils/graphqlClient.js +72 -65
- package/dist/utils/orderVehicleHold.js +38 -0
- package/package.json +3 -2
- package/src/movethewheels/hooks/useFleet.ts +9 -0
- package/src/movethewheels/hooks/useOrderDispatch.ts +196 -0
- package/src/movethewheels/hooks/useOrders.ts +59 -27
- package/src/movethewheels/pages/OrderDetailsPage.tsx +229 -90
- package/src/movethewheels/utils/graphqlClient.ts +36 -7
- package/src/movethewheels/utils/orderVehicleHold.ts +84 -0
package/dist/hooks/useFleet.js
CHANGED
|
@@ -395,6 +395,13 @@ function j(e) {
|
|
|
395
395
|
u(!0), f(null);
|
|
396
396
|
try {
|
|
397
397
|
let n = await t(i, c, { id: e });
|
|
398
|
+
if (n.vehicle && (n.vehicle.id !== e || ![
|
|
399
|
+
"ACTIVE",
|
|
400
|
+
"IN_TRANSIT",
|
|
401
|
+
"MAINTENANCE",
|
|
402
|
+
"INACTIVE",
|
|
403
|
+
"DECOMMISSIONED"
|
|
404
|
+
].includes(n.vehicle.status))) throw Error("Vehicle status could not be verified.");
|
|
398
405
|
s(n.vehicle ? E(n.vehicle) : null);
|
|
399
406
|
} catch (e) {
|
|
400
407
|
f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load vehicle"));
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useTr as e } from "../shared/hooks/useTr.js";
|
|
2
|
+
import { VehicleHoldRefusal as t } from "../utils/orderVehicleHold.js";
|
|
3
|
+
import { useEffect as n, useRef as r, useState as i } from "react";
|
|
4
|
+
//#region src/movethewheels/hooks/useOrderDispatch.ts
|
|
5
|
+
function a(a) {
|
|
6
|
+
let o = e(), { order: s, contextKey: c, updateOrder: l, updateOrderStatus: u, refresh: d } = a, f = `movethewheels.order-dispatch.unconfirmed.v1:${c}`, [p, m] = i(() => {
|
|
7
|
+
try {
|
|
8
|
+
return sessionStorage.getItem(f) !== null;
|
|
9
|
+
} catch {
|
|
10
|
+
return !0;
|
|
11
|
+
}
|
|
12
|
+
}), [h, g] = i(!1), [_, v] = i(null), [y, b] = i(null), x = r(!1), S = r(!0);
|
|
13
|
+
n(() => (S.current = !0, () => {
|
|
14
|
+
S.current = !1;
|
|
15
|
+
}), []);
|
|
16
|
+
let C = (e) => o(e ? "movethewheels.order.movementUnknown" : "movethewheels.order.assignmentUnknown", e ? "Assignment saved. Movement could not be confirmed. Further changes are blocked." : "Assignment could not be confirmed. Further changes are blocked. Check the order before taking another action."), w = () => {
|
|
17
|
+
if (sessionStorage.getItem(f) !== null) throw Error("Unconfirmed order write");
|
|
18
|
+
sessionStorage.setItem(f, "unconfirmed");
|
|
19
|
+
}, T = () => sessionStorage.removeItem(f), E = (e) => {
|
|
20
|
+
if (x.current || p || !S.current || !a.ready || !e || !s) return !1;
|
|
21
|
+
try {
|
|
22
|
+
w();
|
|
23
|
+
} catch {
|
|
24
|
+
return m(!0), v(o("movethewheels.order.retentionUnavailable", "Further changes are blocked because this browser cannot safely retain the order write.")), !1;
|
|
25
|
+
}
|
|
26
|
+
return x.current = !0, g(!0), v(null), !0;
|
|
27
|
+
}, D = () => {
|
|
28
|
+
x.current = !1, S.current && g(!1);
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
assign: async (e, n) => {
|
|
32
|
+
if (!e || !n || !s || s.vehicleId === e && s.driverId === n || !E(a.assignmentReady)) return;
|
|
33
|
+
let r = !1;
|
|
34
|
+
try {
|
|
35
|
+
if (await l(s.id, {
|
|
36
|
+
vehicleId: e,
|
|
37
|
+
driverId: n
|
|
38
|
+
}, "SINGLE_ATTEMPT"), r = !0, S.current && b({
|
|
39
|
+
orderId: s.id,
|
|
40
|
+
vehicleId: e,
|
|
41
|
+
driverId: n
|
|
42
|
+
}), T(), !S.current || (!(s.vehicleId && s.driverId) && s.status === "confirmed" && (w(), await u(s.id, "assigned"), T()), !S.current)) return;
|
|
43
|
+
v(o("movethewheels.order.assignmentSaved", "Assignment saved.")), d();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (e instanceof t && e.operation === (r ? "updateDeliveryJobStatus" : "updateDeliveryJob")) {
|
|
46
|
+
try {
|
|
47
|
+
T();
|
|
48
|
+
} catch {
|
|
49
|
+
S.current && m(!0);
|
|
50
|
+
}
|
|
51
|
+
if (!S.current) return;
|
|
52
|
+
v(o(e.kind === "driver" ? r ? "movethewheels.order.driverMovementBlocked" : "movethewheels.order.driverAssignmentBlocked" : r ? "movethewheels.order.movementBlocked" : "movethewheels.order.assignmentBlocked", e.kind === "driver" ? r ? "Assignment saved. Driver eligibility blocked movement." : "Assignment blocked by driver eligibility. Choose another driver." : r ? "Assignment saved. Movement blocked." : "Assignment blocked by the recorded vehicle status. Choose another vehicle.")), d();
|
|
53
|
+
} else S.current && (m(!0), v(C(r)));
|
|
54
|
+
} finally {
|
|
55
|
+
D();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
changeStatus: async (e) => {
|
|
59
|
+
if (!(!s || [
|
|
60
|
+
"delivered",
|
|
61
|
+
"returned",
|
|
62
|
+
"cancelled",
|
|
63
|
+
"failed"
|
|
64
|
+
].includes(s.status)) && !(e === "assigned" && (!s.vehicleId || !s.driverId)) && !(!E(![
|
|
65
|
+
"assigned",
|
|
66
|
+
"picked_up",
|
|
67
|
+
"in_transit",
|
|
68
|
+
"out_for_delivery"
|
|
69
|
+
].includes(e) || a.movementReady) || !s)) try {
|
|
70
|
+
if (await u(s.id, e), T(), !S.current) return;
|
|
71
|
+
v(o("movethewheels.order.statusSaved", "Order status updated.")), d();
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (e instanceof t && e.operation === "updateDeliveryJobStatus") {
|
|
74
|
+
try {
|
|
75
|
+
T();
|
|
76
|
+
} catch {
|
|
77
|
+
S.current && m(!0);
|
|
78
|
+
}
|
|
79
|
+
if (!S.current) return;
|
|
80
|
+
v(o(e.kind === "driver" ? "movethewheels.order.driverStatusBlocked" : "movethewheels.order.statusBlocked", e.kind === "driver" ? "Movement blocked by driver eligibility. Choose another driver." : "Movement blocked by the recorded vehicle status. Choose another vehicle.")), d();
|
|
81
|
+
} else S.current && (m(!0), v(o("movethewheels.order.statusUnknown", "Order status could not be confirmed. Further changes are blocked.")));
|
|
82
|
+
} finally {
|
|
83
|
+
D();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
busy: h,
|
|
87
|
+
blocked: p,
|
|
88
|
+
message: _,
|
|
89
|
+
knownAssignment: y
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { a as useOrderDispatch };
|
package/dist/hooks/useOrders.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
import { useMoveTheWheels as e } from "../providers/MoveTheWheelsProvider.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { assertOrderAcknowledgement as t } from "../utils/orderVehicleHold.js";
|
|
3
|
+
import { executeGraphQL as n } from "../utils/graphqlClient.js";
|
|
4
|
+
import { mapRoute as r } from "./useRoutes.js";
|
|
5
|
+
import { useCallback as i, useEffect as a, useMemo as o, useState as s } from "react";
|
|
5
6
|
//#region src/movethewheels/hooks/useOrders.ts
|
|
6
|
-
var
|
|
7
|
+
var c = "\n id\n deliveryJobNumber\n customerId\n status\n priority\n pickupAddress\n deliveryAddress\n cargoItems\n pricing\n trackingNumber\n specialInstructions\n scheduledDelivery\n vehicleId\n driverId\n routeId\n route {\n id\n name\n status\n vehicleId\n driverId\n waypoints\n estimatedDistance\n estimatedDuration\n fuelCost\n actualDistance\n actualDuration\n createdAt\n }\n createdAt\n updatedAt\n customer {\n name\n email\n phone\n company\n }\n statusHistory {\n status\n notes\n location\n createdAt\n createdBy\n }\n", l = `
|
|
7
8
|
query ListDeliveryJobs($filter: DeliveryJobFilterInput, $pagination: PaginationInput) {
|
|
8
9
|
deliveryJobs(filter: $filter, pagination: $pagination) {
|
|
9
|
-
${
|
|
10
|
+
${c}
|
|
10
11
|
}
|
|
11
12
|
deliveryJobsCount(filter: $filter)
|
|
12
13
|
}
|
|
13
|
-
`,
|
|
14
|
+
`, u = `
|
|
14
15
|
query GetDeliveryJob($id: ID!) {
|
|
15
16
|
deliveryJob(id: $id) {
|
|
16
|
-
${
|
|
17
|
+
${c}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
`,
|
|
20
|
+
`, d = "\n query GetDeliveryJobStatsBundle {\n deliveryJobStats {\n total\n pending\n confirmed\n assigned\n inTransit\n outForDelivery\n delivered\n cancelled\n failed\n returned\n }\n financeMetrics {\n revenue {\n totalRevenue\n averageOrderValue\n }\n }\n }\n", f = `
|
|
20
21
|
mutation CreateDeliveryJob($input: CreateDeliveryJobInput!) {
|
|
21
22
|
createDeliveryJob(input: $input) {
|
|
22
|
-
${
|
|
23
|
+
${c}
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
`,
|
|
26
|
+
`, p = `
|
|
26
27
|
mutation UpdateDeliveryJob($id: ID!, $input: UpdateDeliveryJobInput!) {
|
|
27
28
|
updateDeliveryJob(id: $id, input: $input) {
|
|
28
|
-
${
|
|
29
|
+
${c}
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
`,
|
|
32
|
+
`, m = `
|
|
32
33
|
mutation UpdateDeliveryJobStatus($id: ID!, $input: UpdateDeliveryJobStatusInput!) {
|
|
33
34
|
updateDeliveryJobStatus(id: $id, input: $input) {
|
|
34
|
-
${
|
|
35
|
+
${c}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
`,
|
|
38
|
-
function
|
|
38
|
+
`, h = "\n mutation DeleteDeliveryJob($id: ID!) {\n deleteDeliveryJob(id: $id)\n }\n";
|
|
39
|
+
function g(e) {
|
|
39
40
|
switch (e) {
|
|
40
41
|
case "PENDING": return "pending";
|
|
41
42
|
case "CONFIRMED": return "confirmed";
|
|
@@ -49,7 +50,7 @@ function h(e) {
|
|
|
49
50
|
default: return "failed";
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
+
function _(e) {
|
|
53
54
|
switch (e) {
|
|
54
55
|
case "LOW": return "low";
|
|
55
56
|
case "HIGH": return "high";
|
|
@@ -58,7 +59,7 @@ function g(e) {
|
|
|
58
59
|
default: return "normal";
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
function
|
|
62
|
+
function v(e) {
|
|
62
63
|
switch (e) {
|
|
63
64
|
case "pending": return "PENDING";
|
|
64
65
|
case "confirmed": return "CONFIRMED";
|
|
@@ -72,7 +73,7 @@ function _(e) {
|
|
|
72
73
|
default: return "FAILED";
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
function
|
|
76
|
+
function y(e) {
|
|
76
77
|
switch (e) {
|
|
77
78
|
case "low": return "LOW";
|
|
78
79
|
case "high": return "HIGH";
|
|
@@ -80,7 +81,7 @@ function v(e) {
|
|
|
80
81
|
default: return "MEDIUM";
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
function
|
|
84
|
+
function b(e) {
|
|
84
85
|
return {
|
|
85
86
|
street: "",
|
|
86
87
|
city: "",
|
|
@@ -90,7 +91,7 @@ function y(e) {
|
|
|
90
91
|
...e ?? {}
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
|
-
function
|
|
94
|
+
function x(e) {
|
|
94
95
|
return {
|
|
95
96
|
id: e.id,
|
|
96
97
|
orderNumber: e.deliveryJobNumber,
|
|
@@ -102,10 +103,10 @@ function b(e) {
|
|
|
102
103
|
company: e.customer?.company ?? void 0
|
|
103
104
|
},
|
|
104
105
|
items: Array.isArray(e.cargoItems) ? e.cargoItems : [],
|
|
105
|
-
status:
|
|
106
|
-
priority:
|
|
107
|
-
pickupAddress:
|
|
108
|
-
deliveryAddress:
|
|
106
|
+
status: g(e.status),
|
|
107
|
+
priority: _(e.priority),
|
|
108
|
+
pickupAddress: b(e.pickupAddress),
|
|
109
|
+
deliveryAddress: b(e.deliveryAddress),
|
|
109
110
|
trackingNumber: e.trackingNumber ?? "",
|
|
110
111
|
specialInstructions: e.specialInstructions ?? void 0,
|
|
111
112
|
pricing: {
|
|
@@ -123,7 +124,7 @@ function b(e) {
|
|
|
123
124
|
},
|
|
124
125
|
timeline: e.statusHistory?.map((e) => ({
|
|
125
126
|
timestamp: new Date(e.createdAt),
|
|
126
|
-
status:
|
|
127
|
+
status: g(e.status),
|
|
127
128
|
location: e.location,
|
|
128
129
|
notes: e.notes ?? void 0,
|
|
129
130
|
performedBy: e.createdBy ?? "system"
|
|
@@ -132,78 +133,78 @@ function b(e) {
|
|
|
132
133
|
vehicleId: e.vehicleId ?? void 0,
|
|
133
134
|
driverId: e.driverId ?? void 0,
|
|
134
135
|
routeId: e.routeId ?? void 0,
|
|
135
|
-
route: e.route ?
|
|
136
|
+
route: e.route ? r(e.route) : void 0,
|
|
136
137
|
createdAt: new Date(e.createdAt),
|
|
137
138
|
updatedAt: new Date(e.updatedAt)
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
-
let { filters:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
]), { apiGatewayUrl:
|
|
149
|
-
apiGatewayUrl:
|
|
150
|
-
authToken:
|
|
151
|
-
workspaceToken:
|
|
152
|
-
workspaceId:
|
|
153
|
-
tenantId:
|
|
154
|
-
actorId:
|
|
141
|
+
function S(r = {}) {
|
|
142
|
+
let { filters: c, limit: u = 20, offset: d = 0 } = r, g = o(() => c, [
|
|
143
|
+
c?.status,
|
|
144
|
+
c?.priority,
|
|
145
|
+
c?.customerId,
|
|
146
|
+
c?.driverId,
|
|
147
|
+
c?.search,
|
|
148
|
+
c?.unassigned
|
|
149
|
+
]), { apiGatewayUrl: _, authToken: b, workspaceToken: S, workspaceId: C, tenantId: w, currentUser: T } = e(), [E, D] = s([]), [O, k] = s(0), [A, j] = s(!1), [M, N] = s(!1), [P, F] = s(null), I = o(() => ({
|
|
150
|
+
apiGatewayUrl: _,
|
|
151
|
+
authToken: b,
|
|
152
|
+
workspaceToken: S,
|
|
153
|
+
workspaceId: C,
|
|
154
|
+
tenantId: w,
|
|
155
|
+
actorId: T?.id
|
|
155
156
|
}), [
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
x,
|
|
157
|
+
_,
|
|
158
|
+
b,
|
|
159
159
|
S,
|
|
160
160
|
C,
|
|
161
|
-
w
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
w,
|
|
162
|
+
T?.id
|
|
163
|
+
]), L = i(async () => {
|
|
164
|
+
N(!0), F(null);
|
|
164
165
|
try {
|
|
165
|
-
let e = await
|
|
166
|
+
let e = await n(I, l, {
|
|
166
167
|
filter: {
|
|
167
|
-
status:
|
|
168
|
-
priority:
|
|
169
|
-
customerId:
|
|
170
|
-
driverId:
|
|
171
|
-
unassigned:
|
|
172
|
-
search:
|
|
168
|
+
status: g?.status ? v(g.status) : void 0,
|
|
169
|
+
priority: g?.priority ? y(g.priority) : void 0,
|
|
170
|
+
customerId: g?.customerId,
|
|
171
|
+
driverId: g?.driverId,
|
|
172
|
+
unassigned: g?.unassigned,
|
|
173
|
+
search: g?.search
|
|
173
174
|
},
|
|
174
175
|
pagination: {
|
|
175
|
-
limit:
|
|
176
|
-
offset:
|
|
176
|
+
limit: u,
|
|
177
|
+
offset: d
|
|
177
178
|
}
|
|
178
|
-
}),
|
|
179
|
-
|
|
179
|
+
}), t = e.deliveryJobs;
|
|
180
|
+
k(e.deliveryJobsCount), j(d + t.length < e.deliveryJobsCount), D(t.map(x));
|
|
180
181
|
} catch (e) {
|
|
181
|
-
|
|
182
|
+
F(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load orders"));
|
|
182
183
|
} finally {
|
|
183
|
-
|
|
184
|
+
N(!1);
|
|
184
185
|
}
|
|
185
186
|
}, [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
g,
|
|
188
|
+
I,
|
|
189
|
+
u,
|
|
190
|
+
d
|
|
190
191
|
]);
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
}, [
|
|
194
|
-
orders:
|
|
195
|
-
totalOrders:
|
|
196
|
-
hasMore:
|
|
197
|
-
isLoading:
|
|
198
|
-
error:
|
|
199
|
-
refetch:
|
|
200
|
-
|
|
201
|
-
}, [
|
|
202
|
-
createOrder:
|
|
203
|
-
let
|
|
192
|
+
return a(() => {
|
|
193
|
+
L();
|
|
194
|
+
}, [L]), {
|
|
195
|
+
orders: E,
|
|
196
|
+
totalOrders: O,
|
|
197
|
+
hasMore: A,
|
|
198
|
+
isLoading: M,
|
|
199
|
+
error: P,
|
|
200
|
+
refetch: i(() => {
|
|
201
|
+
L();
|
|
202
|
+
}, [L]),
|
|
203
|
+
createOrder: i(async (e) => {
|
|
204
|
+
let t = x((await n(I, f, { input: {
|
|
204
205
|
deliveryJobNumber: e.orderNumber ?? `ORD-${(/* @__PURE__ */ new Date()).getFullYear()}-${Date.now().toString().slice(-6)}`,
|
|
205
|
-
status:
|
|
206
|
-
priority:
|
|
206
|
+
status: v(e.status ?? "pending"),
|
|
207
|
+
priority: y(e.priority),
|
|
207
208
|
customerId: e.customerId,
|
|
208
209
|
pickupAddress: e.pickupAddress ?? {},
|
|
209
210
|
deliveryAddress: e.deliveryAddress ?? {},
|
|
@@ -216,84 +217,97 @@ function x(n = {}) {
|
|
|
216
217
|
driverId: e.driverId,
|
|
217
218
|
routeId: e.routeId
|
|
218
219
|
} })).createDeliveryJob);
|
|
219
|
-
return
|
|
220
|
-
}, [
|
|
221
|
-
updateOrder:
|
|
222
|
-
let
|
|
220
|
+
return D((e) => [t, ...e]), t;
|
|
221
|
+
}, [I]),
|
|
222
|
+
updateOrder: i(async (e, r, i = "RETRY_TRANSIENT") => {
|
|
223
|
+
let a = await n(I, p, {
|
|
223
224
|
id: e,
|
|
224
225
|
input: {
|
|
225
|
-
status:
|
|
226
|
-
priority:
|
|
227
|
-
customerId:
|
|
228
|
-
pickupAddress:
|
|
229
|
-
deliveryAddress:
|
|
230
|
-
cargoItems:
|
|
231
|
-
pricing:
|
|
232
|
-
specialInstructions:
|
|
233
|
-
trackingNumber:
|
|
234
|
-
scheduledDelivery:
|
|
235
|
-
vehicleId:
|
|
236
|
-
driverId:
|
|
237
|
-
routeId:
|
|
226
|
+
status: r.status ? v(r.status) : void 0,
|
|
227
|
+
priority: r.priority ? y(r.priority) : void 0,
|
|
228
|
+
customerId: r.customerId,
|
|
229
|
+
pickupAddress: r.pickupAddress,
|
|
230
|
+
deliveryAddress: r.deliveryAddress,
|
|
231
|
+
cargoItems: r.items,
|
|
232
|
+
pricing: r.pricing,
|
|
233
|
+
specialInstructions: r.specialInstructions,
|
|
234
|
+
trackingNumber: r.trackingNumber,
|
|
235
|
+
scheduledDelivery: r.scheduledDelivery === null ? null : r.scheduledDelivery?.toISOString(),
|
|
236
|
+
vehicleId: r.vehicleId,
|
|
237
|
+
driverId: r.driverId,
|
|
238
|
+
routeId: r.routeId
|
|
238
239
|
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
let
|
|
240
|
+
}, i, i === "SINGLE_ATTEMPT" ? "updateDeliveryJob" : void 0);
|
|
241
|
+
i === "SINGLE_ATTEMPT" && t(a.updateDeliveryJob, {
|
|
242
|
+
id: e,
|
|
243
|
+
vehicleId: r.vehicleId,
|
|
244
|
+
driverId: r.driverId,
|
|
245
|
+
status: r.status ? v(r.status) : void 0
|
|
246
|
+
});
|
|
247
|
+
let o = x(a.updateDeliveryJob);
|
|
248
|
+
return D((t) => t.map((t) => t.id === e ? o : t)), o;
|
|
249
|
+
}, [I]),
|
|
250
|
+
deleteOrder: i(async (e) => {
|
|
251
|
+
await n(I, h, { id: e }), D((t) => t.filter((t) => t.id !== e));
|
|
252
|
+
}, [I]),
|
|
253
|
+
updateOrderStatus: i(async (e, r) => {
|
|
254
|
+
let i = await n(I, m, {
|
|
255
|
+
id: e,
|
|
256
|
+
input: { status: v(r) }
|
|
257
|
+
}, "SINGLE_ATTEMPT", "updateDeliveryJobStatus");
|
|
258
|
+
t(i.updateDeliveryJobStatus, {
|
|
247
259
|
id: e,
|
|
248
|
-
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
|
|
260
|
+
status: v(r)
|
|
261
|
+
});
|
|
262
|
+
let a = x(i.updateDeliveryJobStatus);
|
|
263
|
+
return D((t) => t.map((t) => t.id === e ? a : t)), a;
|
|
264
|
+
}, [I])
|
|
252
265
|
};
|
|
253
266
|
}
|
|
254
|
-
function
|
|
255
|
-
let { apiGatewayUrl:
|
|
256
|
-
apiGatewayUrl:
|
|
267
|
+
function C(t) {
|
|
268
|
+
let { apiGatewayUrl: r, authToken: c, workspaceToken: l, workspaceId: d, tenantId: f, currentUser: p } = e(), [m, h] = s(null), [g, _] = s(!1), [v, y] = s(null), b = o(() => ({
|
|
269
|
+
apiGatewayUrl: r,
|
|
257
270
|
authToken: c,
|
|
258
|
-
workspaceToken:
|
|
271
|
+
workspaceToken: l,
|
|
259
272
|
workspaceId: d,
|
|
260
273
|
tenantId: f,
|
|
261
274
|
actorId: p?.id
|
|
262
275
|
}), [
|
|
263
|
-
|
|
276
|
+
r,
|
|
264
277
|
c,
|
|
265
|
-
|
|
278
|
+
l,
|
|
266
279
|
d,
|
|
267
280
|
f,
|
|
268
281
|
p?.id
|
|
269
|
-
]), S =
|
|
270
|
-
if (!
|
|
282
|
+
]), S = i(async () => {
|
|
283
|
+
if (!t) {
|
|
271
284
|
h(null);
|
|
272
285
|
return;
|
|
273
286
|
}
|
|
274
287
|
_(!0), y(null);
|
|
275
288
|
try {
|
|
276
|
-
let e = await
|
|
277
|
-
|
|
289
|
+
let e = await n(b, u, { id: t });
|
|
290
|
+
if (e.deliveryJob && e.deliveryJob.id !== t) throw Error("The requested order could not be verified.");
|
|
291
|
+
h(e.deliveryJob ? x(e.deliveryJob) : null);
|
|
278
292
|
} catch (e) {
|
|
279
293
|
y(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load order"));
|
|
280
294
|
} finally {
|
|
281
295
|
_(!1);
|
|
282
296
|
}
|
|
283
|
-
}, [
|
|
284
|
-
return
|
|
297
|
+
}, [b, t]);
|
|
298
|
+
return a(() => {
|
|
285
299
|
S();
|
|
286
300
|
}, [S]), {
|
|
287
301
|
order: m,
|
|
288
302
|
isLoading: g,
|
|
289
303
|
error: v,
|
|
290
|
-
refetch:
|
|
304
|
+
refetch: i(() => {
|
|
291
305
|
S();
|
|
292
306
|
}, [S])
|
|
293
307
|
};
|
|
294
308
|
}
|
|
295
|
-
function
|
|
296
|
-
let { apiGatewayUrl:
|
|
309
|
+
function w() {
|
|
310
|
+
let { apiGatewayUrl: t, authToken: r, workspaceToken: c, workspaceId: l, tenantId: u, currentUser: f } = e(), [p, m] = s(!1), [h, g] = s(null), [_, v] = s({
|
|
297
311
|
total: 0,
|
|
298
312
|
byStatus: {
|
|
299
313
|
pending: 0,
|
|
@@ -310,24 +324,24 @@ function C() {
|
|
|
310
324
|
totalRevenue: 0,
|
|
311
325
|
todayOrders: 0,
|
|
312
326
|
avgOrderValue: 0
|
|
313
|
-
}), y =
|
|
314
|
-
apiGatewayUrl:
|
|
315
|
-
authToken:
|
|
327
|
+
}), y = o(() => ({
|
|
328
|
+
apiGatewayUrl: t,
|
|
329
|
+
authToken: r,
|
|
316
330
|
workspaceToken: c,
|
|
317
331
|
workspaceId: l,
|
|
318
|
-
tenantId:
|
|
332
|
+
tenantId: u,
|
|
319
333
|
actorId: f?.id
|
|
320
334
|
}), [
|
|
321
|
-
|
|
322
|
-
|
|
335
|
+
t,
|
|
336
|
+
r,
|
|
323
337
|
c,
|
|
324
338
|
l,
|
|
325
|
-
|
|
339
|
+
u,
|
|
326
340
|
f?.id
|
|
327
|
-
]), b =
|
|
341
|
+
]), b = i(async () => {
|
|
328
342
|
m(!0), g(null);
|
|
329
343
|
try {
|
|
330
|
-
let e = await
|
|
344
|
+
let e = await n(y, d);
|
|
331
345
|
v({
|
|
332
346
|
total: e.deliveryJobStats.total,
|
|
333
347
|
byStatus: {
|
|
@@ -352,7 +366,7 @@ function C() {
|
|
|
352
366
|
m(!1);
|
|
353
367
|
}
|
|
354
368
|
}, [y]);
|
|
355
|
-
return
|
|
369
|
+
return a(() => {
|
|
356
370
|
b();
|
|
357
371
|
}, [b]), {
|
|
358
372
|
stats: _,
|
|
@@ -361,4 +375,4 @@ function C() {
|
|
|
361
375
|
};
|
|
362
376
|
}
|
|
363
377
|
//#endregion
|
|
364
|
-
export {
|
|
378
|
+
export { x as mapOrder, _ as mapOrderPriority, g as mapOrderStatus, C as useOrder, w as useOrderStats, S as useOrders };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Order, OrderStatus } from '../types';
|
|
2
|
+
import { OrderWriteInput } from './useOrders';
|
|
3
|
+
interface DispatchOptions {
|
|
4
|
+
order: Order | null;
|
|
5
|
+
contextKey: string;
|
|
6
|
+
ready: boolean;
|
|
7
|
+
assignmentReady: boolean;
|
|
8
|
+
movementReady: boolean;
|
|
9
|
+
updateOrder: (id: string, input: OrderWriteInput, attemptPolicy: 'SINGLE_ATTEMPT') => Promise<Order>;
|
|
10
|
+
updateOrderStatus: (id: string, status: OrderStatus) => Promise<Order>;
|
|
11
|
+
refresh: () => void;
|
|
12
|
+
}
|
|
13
|
+
/** One order/context only. Storage retains uncertainty, never a replayable request or token. */
|
|
14
|
+
export declare function useOrderDispatch(options: DispatchOptions): {
|
|
15
|
+
assign: (vehicleId: string, driverId: string) => Promise<void>;
|
|
16
|
+
changeStatus: (status: OrderStatus) => Promise<void>;
|
|
17
|
+
busy: boolean;
|
|
18
|
+
blocked: boolean;
|
|
19
|
+
message: string | null;
|
|
20
|
+
knownAssignment: {
|
|
21
|
+
orderId: string;
|
|
22
|
+
vehicleId: string;
|
|
23
|
+
driverId: string;
|
|
24
|
+
} | null;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Order, OrderFilter, OrderStatus } from '../types';
|
|
2
|
+
import { GraphQLAttemptPolicy } from '../utils/graphqlClient';
|
|
2
3
|
interface UseOrdersOptions {
|
|
3
4
|
filters?: OrderFilter;
|
|
4
5
|
limit?: number;
|
|
@@ -23,7 +24,7 @@ interface UseOrdersResult {
|
|
|
23
24
|
error: Error | null;
|
|
24
25
|
refetch: () => void;
|
|
25
26
|
createOrder: (order: OrderWriteInput) => Promise<Order>;
|
|
26
|
-
updateOrder: (id: string, updates: OrderWriteInput) => Promise<Order>;
|
|
27
|
+
updateOrder: (id: string, updates: OrderWriteInput, attemptPolicy?: GraphQLAttemptPolicy) => Promise<Order>;
|
|
27
28
|
deleteOrder: (id: string) => Promise<void>;
|
|
28
29
|
updateOrderStatus: (id: string, status: OrderStatus) => Promise<Order>;
|
|
29
30
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VehicleHoldMutation } from './orderVehicleHold';
|
|
1
2
|
export type GraphQLAttemptPolicy = 'RETRY_TRANSIENT' | 'SINGLE_ATTEMPT';
|
|
2
3
|
interface GraphQLRequestOptions {
|
|
3
4
|
apiGatewayUrl?: string;
|
|
@@ -8,5 +9,5 @@ interface GraphQLRequestOptions {
|
|
|
8
9
|
actorId?: string;
|
|
9
10
|
}
|
|
10
11
|
export declare function resolveGraphqlUrl(apiGatewayUrl?: string): string;
|
|
11
|
-
export declare function executeGraphQL<TData>(options: GraphQLRequestOptions, query: string, variables?: Record<string, unknown>, attemptPolicy?: GraphQLAttemptPolicy): Promise<TData>;
|
|
12
|
+
export declare function executeGraphQL<TData>(options: GraphQLRequestOptions, query: string, variables?: Record<string, unknown>, attemptPolicy?: GraphQLAttemptPolicy, holdRefusalField?: VehicleHoldMutation): Promise<TData>;
|
|
12
13
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type VehicleHoldMutation = 'updateDeliveryJob' | 'updateDeliveryJobStatus';
|
|
2
|
+
export declare class VehicleHoldRefusal extends Error {
|
|
3
|
+
readonly operation: VehicleHoldMutation;
|
|
4
|
+
readonly kind: 'vehicle' | 'driver';
|
|
5
|
+
constructor(operation: VehicleHoldMutation, kind?: 'vehicle' | 'driver');
|
|
6
|
+
}
|
|
7
|
+
/** Only the owning pre-write refusal is known to have made no job/history write. */
|
|
8
|
+
export declare function vehicleHoldRefusal(payload: unknown, status: number, operation?: VehicleHoldMutation): VehicleHoldRefusal | null;
|
|
9
|
+
/** Validate the returned write identity before mapping or dispatching a dependent mutation. */
|
|
10
|
+
export declare function assertOrderAcknowledgement(value: unknown, expected: {
|
|
11
|
+
id: string;
|
|
12
|
+
vehicleId?: string;
|
|
13
|
+
driverId?: string;
|
|
14
|
+
status?: string;
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function isVehicleAssignable(status: string): boolean;
|