@burdenoff/microfe-movethewheels 2026.1117.1 → 2026.1123.2
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/MoveTheWheelsRoot.js +149 -133
- package/dist/MoveTheWheelsRoutes.js +157 -139
- package/dist/components/EntityConversationsCard.js +145 -0
- package/dist/components/maps/MapCanvas.js +4 -3
- package/dist/events/rybbit.js +87 -0
- package/dist/generated/tracking-quality-operations.d.ts +342 -0
- package/dist/hooks/useEntityComments.js +111 -0
- package/dist/hooks/useFleet.js +394 -311
- package/dist/hooks/useInventory.js +378 -313
- package/dist/hooks/useMultiModalShipments.js +58 -53
- package/dist/hooks/useOrders.js +178 -158
- package/dist/hooks/useRoutes.js +146 -130
- package/dist/index.js +35 -34
- package/dist/movethewheels/components/EntityConversationsCard.d.ts +8 -0
- package/dist/movethewheels/events/rybbit.d.ts +27 -0
- package/dist/movethewheels/hooks/useEntityComments.d.ts +26 -0
- package/dist/movethewheels/hooks/useFleet.d.ts +73 -1
- package/dist/movethewheels/hooks/useInventory.d.ts +19 -0
- package/dist/movethewheels/index.d.ts +1 -0
- package/dist/movethewheels/pages/DocumentsLibraryPage.d.ts +1 -0
- package/dist/movethewheels/pages/NotificationsCenterPage.d.ts +1 -0
- package/dist/movethewheels/types/index.d.ts +95 -2
- package/dist/node_modules/lucide-react/dist/esm/icons/check-check.js +10 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/layers.js +17 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/message-square.js +7 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/send.js +10 -0
- package/dist/pages/DocumentsLibraryPage.js +235 -0
- package/dist/pages/DriverDetailsPage.js +625 -351
- package/dist/pages/NotificationsCenterPage.js +310 -0
- package/dist/pages/OrderDetailsPage.js +48 -42
- package/dist/pages/RouteDetailsPage.js +257 -251
- package/dist/pages/TrackingPage.js +202 -196
- package/dist/pages/VehicleDetailsPage.js +616 -314
- package/dist/pages/WarehouseDetailsPage.js +539 -253
- package/dist/stories/ControlTowerWidgets.stories.d.ts +10 -0
- package/dist/stories/DataTable.stories.d.ts +15 -0
- package/dist/stories/FleetCards.stories.d.ts +9 -0
- package/dist/stories/OrderForms.stories.d.ts +8 -0
- package/dist/stories/RouteMap.stories.d.ts +7 -0
- package/dist/stories/ShipmentTimeline.stories.d.ts +6 -0
- package/package.json +1 -1
- package/src/generated/tracking-quality-operations.ts +407 -0
- package/src/movethewheels/MoveTheWheelsRoot.tsx +16 -0
- package/src/movethewheels/MoveTheWheelsRoutes.tsx +17 -2
- package/src/movethewheels/components/EntityConversationsCard.tsx +143 -0
- package/src/movethewheels/components/maps/MapCanvas.tsx +3 -3
- package/src/movethewheels/events/__tests__/rybbit.test.ts +98 -0
- package/src/movethewheels/events/rybbit.ts +191 -0
- package/src/movethewheels/hooks/useEntityComments.ts +258 -0
- package/src/movethewheels/hooks/useFleet.ts +300 -5
- package/src/movethewheels/hooks/useInventory.ts +231 -3
- package/src/movethewheels/hooks/useMultiModalShipments.ts +8 -1
- package/src/movethewheels/hooks/useOrders.ts +19 -3
- package/src/movethewheels/hooks/useRoutes.ts +14 -2
- package/src/movethewheels/index.ts +1 -0
- package/src/movethewheels/pages/DocumentsLibraryPage.tsx +229 -0
- package/src/movethewheels/pages/DriverDetailsPage.tsx +250 -1
- package/src/movethewheels/pages/NotificationsCenterPage.tsx +331 -0
- package/src/movethewheels/pages/OrderDetailsPage.tsx +8 -0
- package/src/movethewheels/pages/RouteDetailsPage.tsx +6 -0
- package/src/movethewheels/pages/TrackingPage.tsx +8 -0
- package/src/movethewheels/pages/VehicleDetailsPage.tsx +255 -1
- package/src/movethewheels/pages/WarehouseDetailsPage.tsx +266 -2
- package/src/movethewheels/types/index.ts +103 -2
- package/src/stories/ControlTowerWidgets.stories.tsx +150 -0
- package/src/stories/DataTable.stories.tsx +94 -0
- package/src/stories/FleetCards.stories.tsx +77 -0
- package/src/stories/OrderForms.stories.tsx +84 -0
- package/src/stories/RouteMap.stories.tsx +43 -0
- package/src/stories/ShipmentTimeline.stories.tsx +128 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEntityComments — entity-level conversation threads via wspace-conversations-svc (BOFF-3992).
|
|
3
|
+
*
|
|
4
|
+
* Uses the federated workspace gateway's `getEntityComments`, `createEntityComment`,
|
|
5
|
+
* `resolveEntityComment`, and `deleteEntityComment` operations so Orders, Shipments,
|
|
6
|
+
* and Routes get real workspace-isolated comment threads without duplicating storage.
|
|
7
|
+
*/
|
|
8
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
10
|
+
import { executeGraphQL } from '../utils/graphqlClient';
|
|
11
|
+
|
|
12
|
+
export type ConversationEntityType = 'mtw_order' | 'mtw_shipment' | 'mtw_route';
|
|
13
|
+
|
|
14
|
+
export interface EntityCommentItem {
|
|
15
|
+
id: string;
|
|
16
|
+
entityType: string;
|
|
17
|
+
entityId: string;
|
|
18
|
+
text: string;
|
|
19
|
+
authorId: string;
|
|
20
|
+
status: string;
|
|
21
|
+
isPinned: boolean;
|
|
22
|
+
parentCommentId?: string | null;
|
|
23
|
+
replyCount: number;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ApiEntityComment {
|
|
29
|
+
id: string;
|
|
30
|
+
entityType: string;
|
|
31
|
+
entityId: string;
|
|
32
|
+
content?: { text?: string | null; markdown?: string | null } | null;
|
|
33
|
+
authorId: string;
|
|
34
|
+
status: string;
|
|
35
|
+
isPinned: boolean;
|
|
36
|
+
parentCommentId?: string | null;
|
|
37
|
+
replyCount: number;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const GET_ENTITY_COMMENTS_QUERY = `
|
|
43
|
+
query GetMtwEntityComments($input: GetCommentsInput!) {
|
|
44
|
+
getEntityComments(input: $input) {
|
|
45
|
+
items {
|
|
46
|
+
id
|
|
47
|
+
entityType
|
|
48
|
+
entityId
|
|
49
|
+
content {
|
|
50
|
+
text
|
|
51
|
+
markdown
|
|
52
|
+
}
|
|
53
|
+
authorId
|
|
54
|
+
status
|
|
55
|
+
isPinned
|
|
56
|
+
parentCommentId
|
|
57
|
+
replyCount
|
|
58
|
+
createdAt
|
|
59
|
+
updatedAt
|
|
60
|
+
}
|
|
61
|
+
total
|
|
62
|
+
hasMore
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const CREATE_ENTITY_COMMENT_MUTATION = `
|
|
68
|
+
mutation CreateMtwEntityComment($input: CreateEntityCommentInput!) {
|
|
69
|
+
createEntityComment(input: $input) {
|
|
70
|
+
id
|
|
71
|
+
entityType
|
|
72
|
+
entityId
|
|
73
|
+
content {
|
|
74
|
+
text
|
|
75
|
+
markdown
|
|
76
|
+
}
|
|
77
|
+
authorId
|
|
78
|
+
status
|
|
79
|
+
isPinned
|
|
80
|
+
parentCommentId
|
|
81
|
+
replyCount
|
|
82
|
+
createdAt
|
|
83
|
+
updatedAt
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const RESOLVE_ENTITY_COMMENT_MUTATION = `
|
|
89
|
+
mutation ResolveMtwEntityComment($input: ResolveCommentInput!) {
|
|
90
|
+
resolveEntityComment(input: $input) {
|
|
91
|
+
id
|
|
92
|
+
status
|
|
93
|
+
updatedAt
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
const DELETE_ENTITY_COMMENT_MUTATION = `
|
|
99
|
+
mutation DeleteMtwEntityComment($input: DeleteCommentInput!) {
|
|
100
|
+
deleteEntityComment(input: $input)
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
function mapComment(raw: ApiEntityComment): EntityCommentItem {
|
|
105
|
+
return {
|
|
106
|
+
id: raw.id,
|
|
107
|
+
entityType: raw.entityType,
|
|
108
|
+
entityId: raw.entityId,
|
|
109
|
+
text: raw.content?.text ?? raw.content?.markdown ?? '',
|
|
110
|
+
authorId: raw.authorId,
|
|
111
|
+
status: raw.status,
|
|
112
|
+
isPinned: raw.isPinned,
|
|
113
|
+
parentCommentId: raw.parentCommentId ?? null,
|
|
114
|
+
replyCount: raw.replyCount,
|
|
115
|
+
createdAt: new Date(raw.createdAt),
|
|
116
|
+
updatedAt: new Date(raw.updatedAt),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function useEntityComments(
|
|
121
|
+
entityType: ConversationEntityType,
|
|
122
|
+
entityId: string | undefined
|
|
123
|
+
) {
|
|
124
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
125
|
+
useMoveTheWheels();
|
|
126
|
+
const [comments, setComments] = useState<EntityCommentItem[]>([]);
|
|
127
|
+
const [total, setTotal] = useState(0);
|
|
128
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
129
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
130
|
+
const [error, setError] = useState<Error | null>(null);
|
|
131
|
+
|
|
132
|
+
const graphQLOptions = useMemo(
|
|
133
|
+
() => ({
|
|
134
|
+
apiGatewayUrl,
|
|
135
|
+
authToken,
|
|
136
|
+
workspaceToken,
|
|
137
|
+
workspaceId,
|
|
138
|
+
tenantId,
|
|
139
|
+
actorId: currentUser?.id,
|
|
140
|
+
}),
|
|
141
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const load = useCallback(async () => {
|
|
145
|
+
if (!entityId) {
|
|
146
|
+
setComments([]);
|
|
147
|
+
setTotal(0);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
setIsLoading(true);
|
|
151
|
+
setError(null);
|
|
152
|
+
try {
|
|
153
|
+
const data = await executeGraphQL<{
|
|
154
|
+
getEntityComments: { items: ApiEntityComment[]; total: number; hasMore: boolean };
|
|
155
|
+
}>(graphQLOptions, GET_ENTITY_COMMENTS_QUERY, {
|
|
156
|
+
input: {
|
|
157
|
+
entityType,
|
|
158
|
+
entityId,
|
|
159
|
+
take: 50,
|
|
160
|
+
skip: 0,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
setComments((data.getEntityComments?.items ?? []).map(mapComment));
|
|
164
|
+
setTotal(data.getEntityComments?.total ?? 0);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
setError(err instanceof Error ? err : new Error('Failed to load conversation thread'));
|
|
167
|
+
setComments([]);
|
|
168
|
+
} finally {
|
|
169
|
+
setIsLoading(false);
|
|
170
|
+
}
|
|
171
|
+
}, [entityId, entityType, graphQLOptions]);
|
|
172
|
+
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
void load();
|
|
175
|
+
}, [load]);
|
|
176
|
+
|
|
177
|
+
const addComment = useCallback(
|
|
178
|
+
async (text: string, parentCommentId?: string): Promise<EntityCommentItem | null> => {
|
|
179
|
+
const trimmed = text.trim();
|
|
180
|
+
if (!entityId || !trimmed) return null;
|
|
181
|
+
setIsSubmitting(true);
|
|
182
|
+
setError(null);
|
|
183
|
+
try {
|
|
184
|
+
const data = await executeGraphQL<{ createEntityComment: ApiEntityComment }>(
|
|
185
|
+
graphQLOptions,
|
|
186
|
+
CREATE_ENTITY_COMMENT_MUTATION,
|
|
187
|
+
{
|
|
188
|
+
input: {
|
|
189
|
+
entityType,
|
|
190
|
+
entityId,
|
|
191
|
+
content: { text: trimmed },
|
|
192
|
+
...(parentCommentId ? { parentCommentId } : {}),
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
const created = mapComment(data.createEntityComment);
|
|
197
|
+
setComments((prev) => [...prev, created]);
|
|
198
|
+
setTotal((prev) => prev + 1);
|
|
199
|
+
return created;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
const mapped = err instanceof Error ? err : new Error('Failed to post comment');
|
|
202
|
+
setError(mapped);
|
|
203
|
+
throw mapped;
|
|
204
|
+
} finally {
|
|
205
|
+
setIsSubmitting(false);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
[entityId, entityType, graphQLOptions]
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const toggleResolve = useCallback(
|
|
212
|
+
async (id: string, resolved: boolean): Promise<void> => {
|
|
213
|
+
const data = await executeGraphQL<{
|
|
214
|
+
resolveEntityComment: { id: string; status: string; updatedAt: string };
|
|
215
|
+
}>(graphQLOptions, RESOLVE_ENTITY_COMMENT_MUTATION, {
|
|
216
|
+
input: { id, resolved },
|
|
217
|
+
});
|
|
218
|
+
setComments((prev) =>
|
|
219
|
+
prev.map((item) =>
|
|
220
|
+
item.id === id
|
|
221
|
+
? {
|
|
222
|
+
...item,
|
|
223
|
+
status: data.resolveEntityComment.status,
|
|
224
|
+
updatedAt: new Date(data.resolveEntityComment.updatedAt),
|
|
225
|
+
}
|
|
226
|
+
: item
|
|
227
|
+
)
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
[graphQLOptions]
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const deleteComment = useCallback(
|
|
234
|
+
async (id: string): Promise<void> => {
|
|
235
|
+
await executeGraphQL<{ deleteEntityComment: boolean }>(
|
|
236
|
+
graphQLOptions,
|
|
237
|
+
DELETE_ENTITY_COMMENT_MUTATION,
|
|
238
|
+
{ input: { id, soft: true } }
|
|
239
|
+
);
|
|
240
|
+
setComments((prev) => prev.filter((item) => item.id !== id));
|
|
241
|
+
setTotal((prev) => Math.max(0, prev - 1));
|
|
242
|
+
},
|
|
243
|
+
[graphQLOptions]
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
comments,
|
|
248
|
+
total,
|
|
249
|
+
isLoading,
|
|
250
|
+
isSubmitting,
|
|
251
|
+
error,
|
|
252
|
+
refetch: load,
|
|
253
|
+
addComment,
|
|
254
|
+
toggleResolve,
|
|
255
|
+
deleteComment,
|
|
256
|
+
currentUserId: currentUser?.id,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useEventBus } from '@burdenoff/fe-libs/shared/events';
|
|
2
3
|
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
4
|
+
import { emitVehicleAssigned, emitVehicleServiceRecorded } from '../events/rybbit';
|
|
3
5
|
import type {
|
|
4
6
|
Driver,
|
|
7
|
+
DriverComplianceRecord,
|
|
8
|
+
DriverShift,
|
|
5
9
|
DriverStatus,
|
|
6
10
|
FleetFilter,
|
|
7
11
|
Location,
|
|
8
12
|
Vehicle,
|
|
13
|
+
VehicleDiagnostics,
|
|
9
14
|
VehicleFuelType,
|
|
15
|
+
VehicleMaintenanceLog,
|
|
10
16
|
VehicleStatus,
|
|
17
|
+
VehicleUtilizationSummary,
|
|
11
18
|
} from '../types';
|
|
12
19
|
import { executeGraphQL } from '../utils/graphqlClient';
|
|
13
20
|
|
|
@@ -97,6 +104,29 @@ export interface ApiVehicle {
|
|
|
97
104
|
lastServiceDate?: string | null;
|
|
98
105
|
nextServiceDueDate?: string | null;
|
|
99
106
|
nextServiceDueMileage?: number | null;
|
|
107
|
+
diagnostics?: VehicleDiagnostics | null;
|
|
108
|
+
maintenanceLogs?: Array<{
|
|
109
|
+
id: string;
|
|
110
|
+
vehicleId: string;
|
|
111
|
+
serviceDate: string;
|
|
112
|
+
serviceType: string;
|
|
113
|
+
description: string;
|
|
114
|
+
mileage?: number | null;
|
|
115
|
+
cost?: number | null;
|
|
116
|
+
currency?: string | null;
|
|
117
|
+
vendor?: string | null;
|
|
118
|
+
notes?: string | null;
|
|
119
|
+
createdAt: string;
|
|
120
|
+
}>;
|
|
121
|
+
utilizationSummary?: {
|
|
122
|
+
totalRoutes: number;
|
|
123
|
+
completedRoutes: number;
|
|
124
|
+
activeRoutes: number;
|
|
125
|
+
totalDeliveryJobs: number;
|
|
126
|
+
completedDeliveryJobs: number;
|
|
127
|
+
totalDistanceKm: number;
|
|
128
|
+
utilizationRate?: number | null;
|
|
129
|
+
} | null;
|
|
100
130
|
createdAt: string;
|
|
101
131
|
updatedAt?: string;
|
|
102
132
|
drivers?: Array<{ id: string }>;
|
|
@@ -126,6 +156,26 @@ export interface ApiDriver {
|
|
|
126
156
|
onLeaveUntil?: string | null;
|
|
127
157
|
terminatedAt?: string | null;
|
|
128
158
|
terminationReason?: string | null;
|
|
159
|
+
shifts?: Array<{
|
|
160
|
+
id: string;
|
|
161
|
+
driverId: string;
|
|
162
|
+
shiftDate: string;
|
|
163
|
+
startTime: string;
|
|
164
|
+
endTime: string;
|
|
165
|
+
status: string;
|
|
166
|
+
maxHours?: number | null;
|
|
167
|
+
notes?: string | null;
|
|
168
|
+
}>;
|
|
169
|
+
complianceRecords?: Array<{
|
|
170
|
+
id: string;
|
|
171
|
+
driverId: string;
|
|
172
|
+
recordType: string;
|
|
173
|
+
status: string;
|
|
174
|
+
issuedAt?: string | null;
|
|
175
|
+
expiresAt?: string | null;
|
|
176
|
+
referenceNumber?: string | null;
|
|
177
|
+
notes?: string | null;
|
|
178
|
+
}>;
|
|
129
179
|
createdAt: string;
|
|
130
180
|
}
|
|
131
181
|
|
|
@@ -215,6 +265,29 @@ const GET_VEHICLE_QUERY = `
|
|
|
215
265
|
lastServiceDate
|
|
216
266
|
nextServiceDueDate
|
|
217
267
|
nextServiceDueMileage
|
|
268
|
+
diagnostics
|
|
269
|
+
maintenanceLogs {
|
|
270
|
+
id
|
|
271
|
+
vehicleId
|
|
272
|
+
serviceDate
|
|
273
|
+
serviceType
|
|
274
|
+
description
|
|
275
|
+
mileage
|
|
276
|
+
cost
|
|
277
|
+
currency
|
|
278
|
+
vendor
|
|
279
|
+
notes
|
|
280
|
+
createdAt
|
|
281
|
+
}
|
|
282
|
+
utilizationSummary {
|
|
283
|
+
totalRoutes
|
|
284
|
+
completedRoutes
|
|
285
|
+
activeRoutes
|
|
286
|
+
totalDeliveryJobs
|
|
287
|
+
completedDeliveryJobs
|
|
288
|
+
totalDistanceKm
|
|
289
|
+
utilizationRate
|
|
290
|
+
}
|
|
218
291
|
createdAt
|
|
219
292
|
updatedAt
|
|
220
293
|
drivers {
|
|
@@ -249,6 +322,26 @@ const GET_DRIVER_QUERY = `
|
|
|
249
322
|
onLeaveUntil
|
|
250
323
|
terminatedAt
|
|
251
324
|
terminationReason
|
|
325
|
+
shifts {
|
|
326
|
+
id
|
|
327
|
+
driverId
|
|
328
|
+
shiftDate
|
|
329
|
+
startTime
|
|
330
|
+
endTime
|
|
331
|
+
status
|
|
332
|
+
maxHours
|
|
333
|
+
notes
|
|
334
|
+
}
|
|
335
|
+
complianceRecords {
|
|
336
|
+
id
|
|
337
|
+
driverId
|
|
338
|
+
recordType
|
|
339
|
+
status
|
|
340
|
+
issuedAt
|
|
341
|
+
expiresAt
|
|
342
|
+
referenceNumber
|
|
343
|
+
notes
|
|
344
|
+
}
|
|
252
345
|
createdAt
|
|
253
346
|
vehicles {
|
|
254
347
|
id
|
|
@@ -257,6 +350,72 @@ const GET_DRIVER_QUERY = `
|
|
|
257
350
|
}
|
|
258
351
|
`;
|
|
259
352
|
|
|
353
|
+
const CREATE_VEHICLE_MAINTENANCE_LOG_MUTATION = `
|
|
354
|
+
mutation CreateVehicleMaintenanceLog($input: CreateVehicleMaintenanceLogInput!) {
|
|
355
|
+
createVehicleMaintenanceLog(input: $input) {
|
|
356
|
+
id
|
|
357
|
+
vehicleId
|
|
358
|
+
serviceDate
|
|
359
|
+
serviceType
|
|
360
|
+
description
|
|
361
|
+
mileage
|
|
362
|
+
cost
|
|
363
|
+
currency
|
|
364
|
+
vendor
|
|
365
|
+
notes
|
|
366
|
+
createdAt
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
`;
|
|
370
|
+
|
|
371
|
+
const DELETE_VEHICLE_MAINTENANCE_LOG_MUTATION = `
|
|
372
|
+
mutation DeleteVehicleMaintenanceLog($id: ID!) {
|
|
373
|
+
deleteVehicleMaintenanceLog(id: $id)
|
|
374
|
+
}
|
|
375
|
+
`;
|
|
376
|
+
|
|
377
|
+
const CREATE_DRIVER_SHIFT_MUTATION = `
|
|
378
|
+
mutation CreateDriverShift($input: CreateDriverShiftInput!) {
|
|
379
|
+
createDriverShift(input: $input) {
|
|
380
|
+
id
|
|
381
|
+
driverId
|
|
382
|
+
shiftDate
|
|
383
|
+
startTime
|
|
384
|
+
endTime
|
|
385
|
+
status
|
|
386
|
+
maxHours
|
|
387
|
+
notes
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
`;
|
|
391
|
+
|
|
392
|
+
const DELETE_DRIVER_SHIFT_MUTATION = `
|
|
393
|
+
mutation DeleteDriverShift($id: ID!) {
|
|
394
|
+
deleteDriverShift(id: $id)
|
|
395
|
+
}
|
|
396
|
+
`;
|
|
397
|
+
|
|
398
|
+
const CREATE_DRIVER_COMPLIANCE_MUTATION = `
|
|
399
|
+
mutation CreateDriverComplianceRecord($input: CreateDriverComplianceRecordInput!) {
|
|
400
|
+
createDriverComplianceRecord(input: $input) {
|
|
401
|
+
id
|
|
402
|
+
driverId
|
|
403
|
+
recordType
|
|
404
|
+
status
|
|
405
|
+
issuedAt
|
|
406
|
+
expiresAt
|
|
407
|
+
referenceNumber
|
|
408
|
+
notes
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
`;
|
|
412
|
+
|
|
413
|
+
const DELETE_DRIVER_COMPLIANCE_MUTATION = `
|
|
414
|
+
mutation DeleteDriverComplianceRecord($id: ID!) {
|
|
415
|
+
deleteDriverComplianceRecord(id: $id)
|
|
416
|
+
}
|
|
417
|
+
`;
|
|
418
|
+
|
|
260
419
|
const DELETE_DRIVER_MUTATION = `
|
|
261
420
|
mutation DeleteDriver($id: ID!) {
|
|
262
421
|
deleteDriver(id: $id)
|
|
@@ -632,7 +791,31 @@ export function mapVehicle(vehicle: ApiVehicle): Vehicle {
|
|
|
632
791
|
fuelEfficiencyLPer100Km: vehicle.fuelEfficiencyLPer100Km ?? undefined,
|
|
633
792
|
fuelLevel: vehicle.fuelLevel ?? undefined,
|
|
634
793
|
mileage: vehicle.mileage ?? undefined,
|
|
635
|
-
|
|
794
|
+
diagnostics: vehicle.diagnostics ?? undefined,
|
|
795
|
+
maintenanceLogs: vehicle.maintenanceLogs?.map((log): VehicleMaintenanceLog => ({
|
|
796
|
+
id: log.id,
|
|
797
|
+
vehicleId: log.vehicleId,
|
|
798
|
+
serviceDate: new Date(log.serviceDate),
|
|
799
|
+
serviceType: log.serviceType,
|
|
800
|
+
description: log.description,
|
|
801
|
+
mileage: log.mileage ?? undefined,
|
|
802
|
+
cost: log.cost ?? undefined,
|
|
803
|
+
currency: log.currency ?? undefined,
|
|
804
|
+
vendor: log.vendor ?? undefined,
|
|
805
|
+
notes: log.notes ?? undefined,
|
|
806
|
+
createdAt: new Date(log.createdAt),
|
|
807
|
+
})),
|
|
808
|
+
utilizationSummary: vehicle.utilizationSummary
|
|
809
|
+
? ({
|
|
810
|
+
totalRoutes: vehicle.utilizationSummary.totalRoutes,
|
|
811
|
+
completedRoutes: vehicle.utilizationSummary.completedRoutes,
|
|
812
|
+
activeRoutes: vehicle.utilizationSummary.activeRoutes,
|
|
813
|
+
totalDeliveryJobs: vehicle.utilizationSummary.totalDeliveryJobs,
|
|
814
|
+
completedDeliveryJobs: vehicle.utilizationSummary.completedDeliveryJobs,
|
|
815
|
+
totalDistanceKm: vehicle.utilizationSummary.totalDistanceKm,
|
|
816
|
+
utilizationRate: vehicle.utilizationSummary.utilizationRate ?? undefined,
|
|
817
|
+
} satisfies VehicleUtilizationSummary)
|
|
818
|
+
: undefined,
|
|
636
819
|
createdAt: new Date(vehicle.createdAt),
|
|
637
820
|
};
|
|
638
821
|
}
|
|
@@ -666,7 +849,26 @@ export function mapDriver(driver: ApiDriver): Driver {
|
|
|
666
849
|
onLeaveUntil: driver.onLeaveUntil ? new Date(driver.onLeaveUntil) : undefined,
|
|
667
850
|
terminatedAt: driver.terminatedAt ? new Date(driver.terminatedAt) : undefined,
|
|
668
851
|
terminationReason: driver.terminationReason ?? undefined,
|
|
669
|
-
|
|
852
|
+
shifts: driver.shifts?.map((shift): DriverShift => ({
|
|
853
|
+
id: shift.id,
|
|
854
|
+
driverId: shift.driverId,
|
|
855
|
+
shiftDate: new Date(shift.shiftDate),
|
|
856
|
+
startTime: shift.startTime,
|
|
857
|
+
endTime: shift.endTime,
|
|
858
|
+
status: shift.status,
|
|
859
|
+
maxHours: shift.maxHours ?? undefined,
|
|
860
|
+
notes: shift.notes ?? undefined,
|
|
861
|
+
})),
|
|
862
|
+
complianceRecords: driver.complianceRecords?.map((rec): DriverComplianceRecord => ({
|
|
863
|
+
id: rec.id,
|
|
864
|
+
driverId: rec.driverId,
|
|
865
|
+
recordType: rec.recordType,
|
|
866
|
+
status: rec.status,
|
|
867
|
+
issuedAt: rec.issuedAt ? new Date(rec.issuedAt) : undefined,
|
|
868
|
+
expiresAt: rec.expiresAt ? new Date(rec.expiresAt) : undefined,
|
|
869
|
+
referenceNumber: rec.referenceNumber ?? undefined,
|
|
870
|
+
notes: rec.notes ?? undefined,
|
|
871
|
+
})),
|
|
670
872
|
createdAt: new Date(driver.createdAt),
|
|
671
873
|
};
|
|
672
874
|
}
|
|
@@ -959,6 +1161,7 @@ interface UseVehiclesResult {
|
|
|
959
1161
|
export function useVehicles(options: UseVehiclesOptions = {}): UseVehiclesResult {
|
|
960
1162
|
const { limit = 20, offset = 0, search, status, vehicleType, driverId, ids } = options;
|
|
961
1163
|
const graphQLOptions = useGraphqlOptions();
|
|
1164
|
+
const bus = useEventBus();
|
|
962
1165
|
const [vehicles, setVehicles] = useState<Vehicle[]>([]);
|
|
963
1166
|
const [totalVehicles, setTotalVehicles] = useState(0);
|
|
964
1167
|
const [hasMore, setHasMore] = useState(false);
|
|
@@ -1109,9 +1312,10 @@ export function useVehicles(options: UseVehiclesOptions = {}): UseVehiclesResult
|
|
|
1109
1312
|
if (!data.vehicle) throw new Error('Vehicle not found');
|
|
1110
1313
|
const updated = mapVehicle(data.vehicle);
|
|
1111
1314
|
setVehicles((previous) => previous.map((item) => (item.id === vehicleId ? updated : item)));
|
|
1315
|
+
emitVehicleAssigned(bus, vehicleId, driverId, graphQLOptions.workspaceId);
|
|
1112
1316
|
return updated;
|
|
1113
1317
|
},
|
|
1114
|
-
[graphQLOptions]
|
|
1318
|
+
[bus, graphQLOptions]
|
|
1115
1319
|
);
|
|
1116
1320
|
|
|
1117
1321
|
const deleteVehicle = useCallback(
|
|
@@ -1141,6 +1345,7 @@ export function useVehicles(options: UseVehiclesOptions = {}): UseVehiclesResult
|
|
|
1141
1345
|
|
|
1142
1346
|
export function useVehicle(vehicleId: string | undefined) {
|
|
1143
1347
|
const graphQLOptions = useGraphqlOptions();
|
|
1348
|
+
const bus = useEventBus();
|
|
1144
1349
|
const [vehicle, setVehicle] = useState<Vehicle | null>(null);
|
|
1145
1350
|
const [isLoading, setIsLoading] = useState(false);
|
|
1146
1351
|
const [error, setError] = useState<Error | null>(null);
|
|
@@ -1186,7 +1391,36 @@ export function useVehicle(vehicleId: string | undefined) {
|
|
|
1186
1391
|
void load();
|
|
1187
1392
|
}, [load]);
|
|
1188
1393
|
|
|
1189
|
-
|
|
1394
|
+
const addMaintenanceLog = useCallback(
|
|
1395
|
+
async (input: {
|
|
1396
|
+
serviceDate: string;
|
|
1397
|
+
serviceType: string;
|
|
1398
|
+
description: string;
|
|
1399
|
+
mileage?: number;
|
|
1400
|
+
cost?: number;
|
|
1401
|
+
currency?: string;
|
|
1402
|
+
vendor?: string;
|
|
1403
|
+
notes?: string;
|
|
1404
|
+
}) => {
|
|
1405
|
+
if (!vehicleId) return;
|
|
1406
|
+
await executeGraphQL(graphQLOptions, CREATE_VEHICLE_MAINTENANCE_LOG_MUTATION, {
|
|
1407
|
+
input: { ...input, vehicleId },
|
|
1408
|
+
});
|
|
1409
|
+
emitVehicleServiceRecorded(bus, vehicleId, graphQLOptions.workspaceId, input.serviceType);
|
|
1410
|
+
await load();
|
|
1411
|
+
},
|
|
1412
|
+
[bus, graphQLOptions, load, vehicleId]
|
|
1413
|
+
);
|
|
1414
|
+
|
|
1415
|
+
const removeMaintenanceLog = useCallback(
|
|
1416
|
+
async (id: string) => {
|
|
1417
|
+
await executeGraphQL(graphQLOptions, DELETE_VEHICLE_MAINTENANCE_LOG_MUTATION, { id });
|
|
1418
|
+
await load();
|
|
1419
|
+
},
|
|
1420
|
+
[graphQLOptions, load]
|
|
1421
|
+
);
|
|
1422
|
+
|
|
1423
|
+
return { vehicle, isLoading, error, refetch, addMaintenanceLog, removeMaintenanceLog };
|
|
1190
1424
|
}
|
|
1191
1425
|
|
|
1192
1426
|
interface UseDriversResult {
|
|
@@ -1388,7 +1622,68 @@ export function useDriver(driverId: string | undefined) {
|
|
|
1388
1622
|
void load();
|
|
1389
1623
|
}, [load]);
|
|
1390
1624
|
|
|
1391
|
-
|
|
1625
|
+
const addShift = useCallback(
|
|
1626
|
+
async (input: {
|
|
1627
|
+
shiftDate: string;
|
|
1628
|
+
startTime: string;
|
|
1629
|
+
endTime: string;
|
|
1630
|
+
status?: string;
|
|
1631
|
+
maxHours?: number;
|
|
1632
|
+
notes?: string;
|
|
1633
|
+
}) => {
|
|
1634
|
+
if (!driverId) return;
|
|
1635
|
+
await executeGraphQL(graphQLOptions, CREATE_DRIVER_SHIFT_MUTATION, {
|
|
1636
|
+
input: { ...input, driverId },
|
|
1637
|
+
});
|
|
1638
|
+
await load();
|
|
1639
|
+
},
|
|
1640
|
+
[driverId, graphQLOptions, load]
|
|
1641
|
+
);
|
|
1642
|
+
|
|
1643
|
+
const removeShift = useCallback(
|
|
1644
|
+
async (id: string) => {
|
|
1645
|
+
await executeGraphQL(graphQLOptions, DELETE_DRIVER_SHIFT_MUTATION, { id });
|
|
1646
|
+
await load();
|
|
1647
|
+
},
|
|
1648
|
+
[graphQLOptions, load]
|
|
1649
|
+
);
|
|
1650
|
+
|
|
1651
|
+
const addComplianceRecord = useCallback(
|
|
1652
|
+
async (input: {
|
|
1653
|
+
recordType: string;
|
|
1654
|
+
status?: string;
|
|
1655
|
+
issuedAt?: string;
|
|
1656
|
+
expiresAt?: string;
|
|
1657
|
+
referenceNumber?: string;
|
|
1658
|
+
notes?: string;
|
|
1659
|
+
}) => {
|
|
1660
|
+
if (!driverId) return;
|
|
1661
|
+
await executeGraphQL(graphQLOptions, CREATE_DRIVER_COMPLIANCE_MUTATION, {
|
|
1662
|
+
input: { ...input, driverId },
|
|
1663
|
+
});
|
|
1664
|
+
await load();
|
|
1665
|
+
},
|
|
1666
|
+
[driverId, graphQLOptions, load]
|
|
1667
|
+
);
|
|
1668
|
+
|
|
1669
|
+
const removeComplianceRecord = useCallback(
|
|
1670
|
+
async (id: string) => {
|
|
1671
|
+
await executeGraphQL(graphQLOptions, DELETE_DRIVER_COMPLIANCE_MUTATION, { id });
|
|
1672
|
+
await load();
|
|
1673
|
+
},
|
|
1674
|
+
[graphQLOptions, load]
|
|
1675
|
+
);
|
|
1676
|
+
|
|
1677
|
+
return {
|
|
1678
|
+
driver,
|
|
1679
|
+
isLoading,
|
|
1680
|
+
error,
|
|
1681
|
+
refetch,
|
|
1682
|
+
addShift,
|
|
1683
|
+
removeShift,
|
|
1684
|
+
addComplianceRecord,
|
|
1685
|
+
removeComplianceRecord,
|
|
1686
|
+
};
|
|
1392
1687
|
}
|
|
1393
1688
|
|
|
1394
1689
|
export interface DriverStatusCounts {
|