@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.
Files changed (70) hide show
  1. package/dist/MoveTheWheelsRoot.js +149 -133
  2. package/dist/MoveTheWheelsRoutes.js +157 -139
  3. package/dist/components/EntityConversationsCard.js +145 -0
  4. package/dist/components/maps/MapCanvas.js +4 -3
  5. package/dist/events/rybbit.js +87 -0
  6. package/dist/generated/tracking-quality-operations.d.ts +342 -0
  7. package/dist/hooks/useEntityComments.js +111 -0
  8. package/dist/hooks/useFleet.js +394 -311
  9. package/dist/hooks/useInventory.js +378 -313
  10. package/dist/hooks/useMultiModalShipments.js +58 -53
  11. package/dist/hooks/useOrders.js +178 -158
  12. package/dist/hooks/useRoutes.js +146 -130
  13. package/dist/index.js +35 -34
  14. package/dist/movethewheels/components/EntityConversationsCard.d.ts +8 -0
  15. package/dist/movethewheels/events/rybbit.d.ts +27 -0
  16. package/dist/movethewheels/hooks/useEntityComments.d.ts +26 -0
  17. package/dist/movethewheels/hooks/useFleet.d.ts +73 -1
  18. package/dist/movethewheels/hooks/useInventory.d.ts +19 -0
  19. package/dist/movethewheels/index.d.ts +1 -0
  20. package/dist/movethewheels/pages/DocumentsLibraryPage.d.ts +1 -0
  21. package/dist/movethewheels/pages/NotificationsCenterPage.d.ts +1 -0
  22. package/dist/movethewheels/types/index.d.ts +95 -2
  23. package/dist/node_modules/lucide-react/dist/esm/icons/check-check.js +10 -0
  24. package/dist/node_modules/lucide-react/dist/esm/icons/layers.js +17 -0
  25. package/dist/node_modules/lucide-react/dist/esm/icons/message-square.js +7 -0
  26. package/dist/node_modules/lucide-react/dist/esm/icons/send.js +10 -0
  27. package/dist/pages/DocumentsLibraryPage.js +235 -0
  28. package/dist/pages/DriverDetailsPage.js +625 -351
  29. package/dist/pages/NotificationsCenterPage.js +310 -0
  30. package/dist/pages/OrderDetailsPage.js +48 -42
  31. package/dist/pages/RouteDetailsPage.js +257 -251
  32. package/dist/pages/TrackingPage.js +202 -196
  33. package/dist/pages/VehicleDetailsPage.js +616 -314
  34. package/dist/pages/WarehouseDetailsPage.js +539 -253
  35. package/dist/stories/ControlTowerWidgets.stories.d.ts +10 -0
  36. package/dist/stories/DataTable.stories.d.ts +15 -0
  37. package/dist/stories/FleetCards.stories.d.ts +9 -0
  38. package/dist/stories/OrderForms.stories.d.ts +8 -0
  39. package/dist/stories/RouteMap.stories.d.ts +7 -0
  40. package/dist/stories/ShipmentTimeline.stories.d.ts +6 -0
  41. package/package.json +1 -1
  42. package/src/generated/tracking-quality-operations.ts +407 -0
  43. package/src/movethewheels/MoveTheWheelsRoot.tsx +16 -0
  44. package/src/movethewheels/MoveTheWheelsRoutes.tsx +17 -2
  45. package/src/movethewheels/components/EntityConversationsCard.tsx +143 -0
  46. package/src/movethewheels/components/maps/MapCanvas.tsx +3 -3
  47. package/src/movethewheels/events/__tests__/rybbit.test.ts +98 -0
  48. package/src/movethewheels/events/rybbit.ts +191 -0
  49. package/src/movethewheels/hooks/useEntityComments.ts +258 -0
  50. package/src/movethewheels/hooks/useFleet.ts +300 -5
  51. package/src/movethewheels/hooks/useInventory.ts +231 -3
  52. package/src/movethewheels/hooks/useMultiModalShipments.ts +8 -1
  53. package/src/movethewheels/hooks/useOrders.ts +19 -3
  54. package/src/movethewheels/hooks/useRoutes.ts +14 -2
  55. package/src/movethewheels/index.ts +1 -0
  56. package/src/movethewheels/pages/DocumentsLibraryPage.tsx +229 -0
  57. package/src/movethewheels/pages/DriverDetailsPage.tsx +250 -1
  58. package/src/movethewheels/pages/NotificationsCenterPage.tsx +331 -0
  59. package/src/movethewheels/pages/OrderDetailsPage.tsx +8 -0
  60. package/src/movethewheels/pages/RouteDetailsPage.tsx +6 -0
  61. package/src/movethewheels/pages/TrackingPage.tsx +8 -0
  62. package/src/movethewheels/pages/VehicleDetailsPage.tsx +255 -1
  63. package/src/movethewheels/pages/WarehouseDetailsPage.tsx +266 -2
  64. package/src/movethewheels/types/index.ts +103 -2
  65. package/src/stories/ControlTowerWidgets.stories.tsx +150 -0
  66. package/src/stories/DataTable.stories.tsx +94 -0
  67. package/src/stories/FleetCards.stories.tsx +77 -0
  68. package/src/stories/OrderForms.stories.tsx +84 -0
  69. package/src/stories/RouteMap.stories.tsx +43 -0
  70. package/src/stories/ShipmentTimeline.stories.tsx +128 -0
@@ -1,6 +1,17 @@
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';
3
- import type { Inventory, InventoryFilter, Product, ProductDimensions, Warehouse } from '../types';
4
+ import { emitWarehouseInboundReceived } from '../events/rybbit';
5
+ import type {
6
+ Inventory,
7
+ InventoryFilter,
8
+ Product,
9
+ ProductDimensions,
10
+ Warehouse,
11
+ WarehouseMetrics,
12
+ WarehouseStaffMember,
13
+ WarehouseZone,
14
+ } from '../types';
4
15
  import { executeGraphQL } from '../utils/graphqlClient';
5
16
 
6
17
  interface UseInventoryOptions {
@@ -111,6 +122,39 @@ interface ApiWarehouse {
111
122
  operatingHours?: Record<string, unknown> | null;
112
123
  totalCapacity?: number | null;
113
124
  usedCapacity?: number | null;
125
+ zones?: Array<{
126
+ id: string;
127
+ warehouseId: string;
128
+ code: string;
129
+ name: string;
130
+ zoneType: string;
131
+ temperatureRange?: string | null;
132
+ totalCapacity?: number | null;
133
+ usedCapacity?: number | null;
134
+ status: string;
135
+ }>;
136
+ staff?: Array<{
137
+ id: string;
138
+ warehouseId: string;
139
+ userId?: string | null;
140
+ name: string;
141
+ role: string;
142
+ shift?: string | null;
143
+ status: string;
144
+ contactEmail?: string | null;
145
+ contactPhone?: string | null;
146
+ }>;
147
+ metrics?: {
148
+ totalLocations: number;
149
+ activeLocations: number;
150
+ zoneCount: number;
151
+ staffCount: number;
152
+ totalSkus: number;
153
+ totalOnHand: number;
154
+ totalAvailable: number;
155
+ lowStockCount: number;
156
+ utilizationPercent?: number | null;
157
+ } | null;
114
158
  createdAt: string;
115
159
  }
116
160
 
@@ -217,11 +261,88 @@ const GET_WAREHOUSE_QUERY = `
217
261
  operatingHours
218
262
  totalCapacity
219
263
  usedCapacity
264
+ zones {
265
+ id
266
+ warehouseId
267
+ code
268
+ name
269
+ zoneType
270
+ temperatureRange
271
+ totalCapacity
272
+ usedCapacity
273
+ status
274
+ }
275
+ staff {
276
+ id
277
+ warehouseId
278
+ userId
279
+ name
280
+ role
281
+ shift
282
+ status
283
+ contactEmail
284
+ contactPhone
285
+ }
286
+ metrics {
287
+ totalLocations
288
+ activeLocations
289
+ zoneCount
290
+ staffCount
291
+ totalSkus
292
+ totalOnHand
293
+ totalAvailable
294
+ lowStockCount
295
+ utilizationPercent
296
+ }
220
297
  createdAt
221
298
  }
222
299
  }
223
300
  `;
224
301
 
302
+ const CREATE_WAREHOUSE_ZONE_MUTATION = `
303
+ mutation CreateWarehouseZone($input: CreateWarehouseZoneInput!) {
304
+ createWarehouseZone(input: $input) {
305
+ id
306
+ warehouseId
307
+ code
308
+ name
309
+ zoneType
310
+ temperatureRange
311
+ totalCapacity
312
+ usedCapacity
313
+ status
314
+ }
315
+ }
316
+ `;
317
+
318
+ const DELETE_WAREHOUSE_ZONE_MUTATION = `
319
+ mutation DeleteWarehouseZone($id: ID!) {
320
+ deleteWarehouseZone(id: $id)
321
+ }
322
+ `;
323
+
324
+ const CREATE_WAREHOUSE_STAFF_MUTATION = `
325
+ mutation CreateWarehouseStaff($input: CreateWarehouseStaffInput!) {
326
+ createWarehouseStaff(input: $input) {
327
+ id
328
+ warehouseId
329
+ userId
330
+ name
331
+ role
332
+ shift
333
+ status
334
+ contactEmail
335
+ contactPhone
336
+ }
337
+ }
338
+ `;
339
+
340
+ const DELETE_WAREHOUSE_STAFF_MUTATION = `
341
+ mutation DeleteWarehouseStaff($id: ID!) {
342
+ deleteWarehouseStaff(id: $id)
343
+ }
344
+ `;
345
+
225
346
  const INVENTORY_STATS_QUERY = `
226
347
  query GetInventoryStats {
227
348
  inventoryStats {
@@ -499,6 +620,41 @@ function mapWarehouse(warehouse: ApiWarehouse): Warehouse {
499
620
  }
500
621
  : undefined,
501
622
  utilization,
623
+ zones: warehouse.zones?.map((z): WarehouseZone => ({
624
+ id: z.id,
625
+ warehouseId: z.warehouseId,
626
+ code: z.code,
627
+ name: z.name,
628
+ zoneType: z.zoneType,
629
+ temperatureRange: z.temperatureRange ?? undefined,
630
+ totalCapacity: z.totalCapacity ?? undefined,
631
+ usedCapacity: z.usedCapacity ?? undefined,
632
+ status: z.status,
633
+ })),
634
+ staff: warehouse.staff?.map((s): WarehouseStaffMember => ({
635
+ id: s.id,
636
+ warehouseId: s.warehouseId,
637
+ userId: s.userId ?? undefined,
638
+ name: s.name,
639
+ role: s.role,
640
+ shift: s.shift ?? undefined,
641
+ status: s.status,
642
+ contactEmail: s.contactEmail ?? undefined,
643
+ contactPhone: s.contactPhone ?? undefined,
644
+ })),
645
+ metrics: warehouse.metrics
646
+ ? ({
647
+ totalLocations: warehouse.metrics.totalLocations,
648
+ activeLocations: warehouse.metrics.activeLocations,
649
+ zoneCount: warehouse.metrics.zoneCount,
650
+ staffCount: warehouse.metrics.staffCount,
651
+ totalSkus: warehouse.metrics.totalSkus,
652
+ totalOnHand: warehouse.metrics.totalOnHand,
653
+ totalAvailable: warehouse.metrics.totalAvailable,
654
+ lowStockCount: warehouse.metrics.lowStockCount,
655
+ utilizationPercent: warehouse.metrics.utilizationPercent ?? undefined,
656
+ } satisfies WarehouseMetrics)
657
+ : undefined,
502
658
  createdAt: new Date(warehouse.createdAt),
503
659
  };
504
660
  }
@@ -547,6 +703,7 @@ export function useInventory(options: UseInventoryOptions = {}): UseInventoryRes
547
703
  [rawFilters?.lowStock, rawFilters?.productId, rawFilters?.search, rawFilters?.warehouseId]
548
704
  );
549
705
  const graphQLOptions = useGraphqlOptions();
706
+ const bus = useEventBus();
550
707
  const [inventory, setInventory] = useState<Inventory[]>([]);
551
708
  const [lowStockItems, setLowStockItems] = useState<Inventory[]>([]);
552
709
  const [products, setProducts] = useState<Product[]>([]);
@@ -647,9 +804,17 @@ export function useInventory(options: UseInventoryOptions = {}): UseInventoryRes
647
804
  setInventory((previous) =>
648
805
  previous.map((item) => (item.id === inventoryId ? updated : item))
649
806
  );
807
+ if (quantity > 0) {
808
+ emitWarehouseInboundReceived(
809
+ bus,
810
+ updated.warehouseId,
811
+ updated.id,
812
+ graphQLOptions.workspaceId
813
+ );
814
+ }
650
815
  return updated;
651
816
  },
652
- [graphQLOptions, inventory]
817
+ [bus, graphQLOptions, inventory]
653
818
  );
654
819
 
655
820
  const transferStock = useCallback(
@@ -1185,7 +1350,70 @@ export function useWarehouse(warehouseId: string | undefined) {
1185
1350
  void load();
1186
1351
  }, [load]);
1187
1352
 
1188
- return { warehouse, isLoading, error, refetch: () => void load(), reload: load };
1353
+ const addZone = useCallback(
1354
+ async (input: {
1355
+ code: string;
1356
+ name: string;
1357
+ zoneType?: string;
1358
+ temperatureRange?: string;
1359
+ totalCapacity?: number;
1360
+ usedCapacity?: number;
1361
+ status?: string;
1362
+ }) => {
1363
+ if (!warehouseId) return;
1364
+ await executeGraphQL(graphQLOptions, CREATE_WAREHOUSE_ZONE_MUTATION, {
1365
+ input: { ...input, warehouseId },
1366
+ });
1367
+ await load();
1368
+ },
1369
+ [graphQLOptions, load, warehouseId]
1370
+ );
1371
+
1372
+ const removeZone = useCallback(
1373
+ async (id: string) => {
1374
+ await executeGraphQL(graphQLOptions, DELETE_WAREHOUSE_ZONE_MUTATION, { id });
1375
+ await load();
1376
+ },
1377
+ [graphQLOptions, load]
1378
+ );
1379
+
1380
+ const addStaff = useCallback(
1381
+ async (input: {
1382
+ name: string;
1383
+ role?: string;
1384
+ shift?: string;
1385
+ status?: string;
1386
+ contactEmail?: string;
1387
+ contactPhone?: string;
1388
+ }) => {
1389
+ if (!warehouseId) return;
1390
+ await executeGraphQL(graphQLOptions, CREATE_WAREHOUSE_STAFF_MUTATION, {
1391
+ input: { ...input, warehouseId },
1392
+ });
1393
+ await load();
1394
+ },
1395
+ [graphQLOptions, load, warehouseId]
1396
+ );
1397
+
1398
+ const removeStaff = useCallback(
1399
+ async (id: string) => {
1400
+ await executeGraphQL(graphQLOptions, DELETE_WAREHOUSE_STAFF_MUTATION, { id });
1401
+ await load();
1402
+ },
1403
+ [graphQLOptions, load]
1404
+ );
1405
+
1406
+ return {
1407
+ warehouse,
1408
+ isLoading,
1409
+ error,
1410
+ refetch: () => void load(),
1411
+ reload: load,
1412
+ addZone,
1413
+ removeZone,
1414
+ addStaff,
1415
+ removeStaff,
1416
+ };
1189
1417
  }
1190
1418
 
1191
1419
  export interface InventoryStats {
@@ -7,6 +7,8 @@
7
7
  * anything (see BOFF-3922 schema-drift guard / prior MFE-schema-drift incidents).
8
8
  */
9
9
  import { useCallback, useEffect, useMemo, useState } from 'react';
10
+ import { useEventBus } from '@burdenoff/fe-libs/shared/events';
11
+ import { emitShipmentCreated } from '../events/rybbit';
10
12
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
11
13
  import { executeGraphQL } from '../utils/graphqlClient';
12
14
 
@@ -270,6 +272,7 @@ export function useMultiModalShipments(
270
272
  ) {
271
273
  const { limit = 10, offset = 0, search = '' } = options;
272
274
  const graphQLOptions = useGraphqlOptions();
275
+ const bus = useEventBus();
273
276
  const [shipments, setShipments] = useState<MultiModalShipment[]>([]);
274
277
  const [totalShipments, setTotalShipments] = useState(0);
275
278
  const [hasMore, setHasMore] = useState(false);
@@ -338,9 +341,13 @@ export function useMultiModalShipments(
338
341
  const created = mapShipment(data.planMultiModalShipment);
339
342
  setShipments((previous) => [created, ...previous]);
340
343
  setTotalShipments((previous) => previous + 1);
344
+ emitShipmentCreated(bus, created.id, graphQLOptions.workspaceId, {
345
+ mode: created.primaryMode,
346
+ isMultiModal: created.isMultiModal,
347
+ });
341
348
  return created;
342
349
  },
343
- [graphQLOptions]
350
+ [bus, graphQLOptions]
344
351
  );
345
352
 
346
353
  return {
@@ -1,5 +1,7 @@
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 { emitDeliveryJobAssigned, emitOrderCreated, emitShipmentDelivered } from '../events/rybbit';
3
5
  import type { Order, OrderFilter, OrderStatus } from '../types';
4
6
  import { mapRoute } from './useRoutes';
5
7
  import { executeGraphQL, type GraphQLAttemptPolicy } from '../utils/graphqlClient';
@@ -377,6 +379,7 @@ export function useOrders(options: UseOrdersOptions = {}): UseOrdersResult {
377
379
  const [orders, setOrders] = useState<Order[]>([]);
378
380
  const [totalOrders, setTotalOrders] = useState(0);
379
381
  const [hasMore, setHasMore] = useState(false);
382
+ const bus = useEventBus();
380
383
  const [isLoading, setIsLoading] = useState(false);
381
384
  const [error, setError] = useState<Error | null>(null);
382
385
 
@@ -461,9 +464,13 @@ export function useOrders(options: UseOrdersOptions = {}): UseOrdersResult {
461
464
 
462
465
  const created = mapOrder(data.createDeliveryJob);
463
466
  setOrders((previous) => [created, ...previous]);
467
+ emitOrderCreated(bus, created.id, workspaceId, {
468
+ priority: created.priority,
469
+ itemCount: created.items.length,
470
+ });
464
471
  return created;
465
472
  },
466
- [graphQLOptions]
473
+ [bus, graphQLOptions, workspaceId]
467
474
  );
468
475
 
469
476
  const updateOrder = useCallback(
@@ -510,9 +517,15 @@ export function useOrders(options: UseOrdersOptions = {}): UseOrdersResult {
510
517
  });
511
518
  const updated = mapOrder(data.updateDeliveryJob);
512
519
  setOrders((previous) => previous.map((item) => (item.id === id ? updated : item)));
520
+ if (updates.driverId !== undefined || updates.vehicleId !== undefined) {
521
+ emitDeliveryJobAssigned(bus, updated.id, workspaceId, {
522
+ hasDriver: Boolean(updated.driverId),
523
+ hasVehicle: Boolean(updated.vehicleId),
524
+ });
525
+ }
513
526
  return updated;
514
527
  },
515
- [graphQLOptions]
528
+ [bus, graphQLOptions, workspaceId]
516
529
  );
517
530
 
518
531
  const deleteOrder = useCallback(
@@ -545,9 +558,12 @@ export function useOrders(options: UseOrdersOptions = {}): UseOrdersResult {
545
558
  assertOrderAcknowledgement(data.updateDeliveryJobStatus, { id, status: toApiStatus(status) });
546
559
  const updated = mapOrder(data.updateDeliveryJobStatus);
547
560
  setOrders((previous) => previous.map((item) => (item.id === id ? updated : item)));
561
+ if (status === 'delivered') {
562
+ emitShipmentDelivered(bus, updated.id, workspaceId);
563
+ }
548
564
  return updated;
549
565
  },
550
- [graphQLOptions]
566
+ [bus, graphQLOptions, workspaceId]
551
567
  );
552
568
 
553
569
  return {
@@ -1,5 +1,7 @@
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 { emitRoutePlanned } from '../events/rybbit';
3
5
  import type {
4
6
  Route,
5
7
  RouteOptimizationStrategy,
@@ -300,6 +302,8 @@ function useGraphqlOptions() {
300
302
  export function useRoutes(options: UseRoutesOptions = {}): UseRoutesResult {
301
303
  const { driverId, vehicleId, status, search, limit = 20, offset = 0 } = options;
302
304
  const graphQLOptions = useGraphqlOptions();
305
+ const bus = useEventBus();
306
+ const workspaceId = graphQLOptions.workspaceId;
303
307
  const [routes, setRoutes] = useState<Route[]>([]);
304
308
  const [totalRoutes, setTotalRoutes] = useState(0);
305
309
  const [hasMore, setHasMore] = useState(false);
@@ -413,9 +417,13 @@ export function useRoutes(options: UseRoutesOptions = {}): UseRoutesResult {
413
417
 
414
418
  const created = mapRoute(data.createRoute);
415
419
  setRoutes((previous) => [created, ...previous]);
420
+ emitRoutePlanned(bus, created.id, workspaceId, {
421
+ optimized: false,
422
+ stopCount: created.stops.length,
423
+ });
416
424
  return created;
417
425
  },
418
- [graphQLOptions]
426
+ [bus, graphQLOptions, workspaceId]
419
427
  );
420
428
 
421
429
  const updateRoute = useCallback(
@@ -477,9 +485,13 @@ export function useRoutes(options: UseRoutesOptions = {}): UseRoutesResult {
477
485
  );
478
486
  const optimized = mapRoute(data.optimizeRoute);
479
487
  setRoutes((previous) => previous.map((item) => (item.id === routeId ? optimized : item)));
488
+ emitRoutePlanned(bus, optimized.id, workspaceId, {
489
+ optimized: true,
490
+ stopCount: optimized.stops.length,
491
+ });
480
492
  return optimized;
481
493
  },
482
- [graphQLOptions]
494
+ [bus, graphQLOptions, workspaceId]
483
495
  );
484
496
 
485
497
  const updateStopStatus = useCallback(
@@ -60,6 +60,7 @@ export type {
60
60
  } from './types';
61
61
  export { useMoveTheWheels, useMoveTheWheelsNavigate } from './providers/MoveTheWheelsProvider';
62
62
  export { useMoveTheWheelsStore } from './store/movethewheelsStore';
63
+ export { MOVETHEWHEELS_RYBBIT_EVENT_ALLOWLIST } from './events/rybbit';
63
64
 
64
65
  // Transport adapter for the shared fe-libs AssistantWidget.
65
66
  // Consumers import it from the dedicated subpath
@@ -0,0 +1,229 @@
1
+ /**
2
+ * DocumentsLibraryPage — Global MoveTheWheels files & documents view (BOFF-3992).
3
+ *
4
+ * Reuses `wspace-files-svc` (`getFiles`) with MoveTheWheels entity-tag filters
5
+ * (All, Orders, Shipments, Vehicles, Drivers, Routes) so operators can browse,
6
+ * filter, and open all logistics documents from one screen, or jump into the
7
+ * platform `/files/browse` manager to upload new files.
8
+ */
9
+ import { useCallback, useEffect, useMemo, useState } from 'react';
10
+ import { Download, ExternalLink, FileText, Search, Upload } from 'lucide-react';
11
+ import { PageLayout } from '../components/PageLayout';
12
+ import { Badge, Button, Card, CardContent, CardHeader, CardTitle, Input } from '../components/ui';
13
+ import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
14
+ import { executeGraphQL } from '../utils/graphqlClient';
15
+ import type { EntityDocument, EntityDocumentType } from '../hooks/useEntityDocuments';
16
+ import { formatDate } from '../utils/formatters';
17
+
18
+ type ScopeFilter = 'all' | EntityDocumentType;
19
+
20
+ const SCOPE_TABS: Array<{ id: ScopeFilter; label: string }> = [
21
+ { id: 'all', label: 'All documents' },
22
+ { id: 'order', label: 'Orders' },
23
+ { id: 'shipment', label: 'Shipments' },
24
+ { id: 'vehicle', label: 'Vehicles' },
25
+ { id: 'driver', label: 'Drivers' },
26
+ { id: 'route', label: 'Routes' },
27
+ ];
28
+
29
+ const LIST_WORKSPACE_FILES_QUERY = `
30
+ query ListMoveTheWheelsDocuments($filter: FileFilterInput, $pagination: PaginationInput) {
31
+ getFiles(filter: $filter, pagination: $pagination) {
32
+ files {
33
+ id
34
+ name
35
+ size
36
+ mimeType
37
+ createdAt
38
+ downloadUrl
39
+ }
40
+ hasMore
41
+ }
42
+ }
43
+ `;
44
+
45
+ interface ApiFile {
46
+ id: string;
47
+ name: string;
48
+ size: string | number | null;
49
+ mimeType: string;
50
+ createdAt: string;
51
+ downloadUrl?: string | null;
52
+ }
53
+
54
+ function formatSize(bytes: number): string {
55
+ if (!Number.isFinite(bytes) || bytes <= 0) return '—';
56
+ const units = ['B', 'KB', 'MB', 'GB'];
57
+ let val = bytes;
58
+ let idx = 0;
59
+ while (val >= 1024 && idx < units.length - 1) {
60
+ val /= 1024;
61
+ idx += 1;
62
+ }
63
+ return `${val.toFixed(val >= 10 || idx === 0 ? 0 : 1)} ${units[idx]}`;
64
+ }
65
+
66
+ export default function DocumentsLibraryPage() {
67
+ const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser, navigate } =
68
+ useMoveTheWheels();
69
+ const [scope, setScope] = useState<ScopeFilter>('all');
70
+ const [search, setSearch] = useState('');
71
+ const [files, setFiles] = useState<EntityDocument[]>([]);
72
+ const [isLoading, setIsLoading] = useState(false);
73
+ const [error, setError] = useState<string | null>(null);
74
+
75
+ const graphQLOptions = useMemo(
76
+ () => ({
77
+ apiGatewayUrl,
78
+ authToken,
79
+ workspaceToken,
80
+ workspaceId,
81
+ tenantId,
82
+ actorId: currentUser?.id,
83
+ }),
84
+ [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
85
+ );
86
+
87
+ const load = useCallback(async () => {
88
+ setIsLoading(true);
89
+ setError(null);
90
+ try {
91
+ const filter: Record<string, unknown> = {};
92
+ if (scope !== 'all') {
93
+ filter.tags = [{ key: 'mtwEntityType', label: scope }];
94
+ }
95
+ if (search.trim()) {
96
+ filter.search = search.trim();
97
+ }
98
+ const data = await executeGraphQL<{
99
+ getFiles: { files: ApiFile[]; hasMore?: boolean | null };
100
+ }>(graphQLOptions, LIST_WORKSPACE_FILES_QUERY, {
101
+ filter: Object.keys(filter).length > 0 ? filter : undefined,
102
+ pagination: { limit: 50, offset: 0 },
103
+ });
104
+ setFiles(
105
+ (data.getFiles?.files ?? []).map((item) => ({
106
+ id: item.id,
107
+ name: item.name,
108
+ size: item.size != null ? Number(item.size) : 0,
109
+ mimeType: item.mimeType,
110
+ createdAt: new Date(item.createdAt),
111
+ downloadUrl: item.downloadUrl ?? undefined,
112
+ }))
113
+ );
114
+ } catch (err) {
115
+ setError(err instanceof Error ? err.message : 'Failed to load workspace documents.');
116
+ setFiles([]);
117
+ } finally {
118
+ setIsLoading(false);
119
+ }
120
+ }, [graphQLOptions, scope, search]);
121
+
122
+ useEffect(() => {
123
+ void load();
124
+ }, [load]);
125
+
126
+ return (
127
+ <PageLayout
128
+ title="Documents"
129
+ subtitle="BOLs, ePODs, customs paperwork, compliance certificates, and fleet files"
130
+ icon={<FileText size={24} />}
131
+ headerActions={
132
+ <Button onClick={() => navigate('/files/browse')}>
133
+ <Upload size={16} aria-hidden="true" /> Manage in Files
134
+ </Button>
135
+ }
136
+ >
137
+ <div className="space-y-6">
138
+ <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
139
+ <div className="flex flex-wrap gap-2" role="tablist" aria-label="Document scope">
140
+ {SCOPE_TABS.map((tab) => (
141
+ <Button
142
+ key={tab.id}
143
+ type="button"
144
+ role="tab"
145
+ aria-selected={scope === tab.id}
146
+ variant={scope === tab.id ? 'default' : 'outline'}
147
+ size="sm"
148
+ onClick={() => setScope(tab.id)}
149
+ >
150
+ {tab.label}
151
+ </Button>
152
+ ))}
153
+ </div>
154
+ <div className="relative w-full sm:w-64">
155
+ <Search
156
+ size={15}
157
+ aria-hidden="true"
158
+ className="absolute left-3 top-1/2 -translate-y-1/2 text-text-secondary"
159
+ />
160
+ <Input
161
+ value={search}
162
+ onChange={(event) => setSearch(event.target.value)}
163
+ placeholder="Search files..."
164
+ className="pl-9"
165
+ aria-label="Search documents"
166
+ />
167
+ </div>
168
+ </div>
169
+
170
+ <Card>
171
+ <CardHeader className="flex flex-row items-center justify-between">
172
+ <CardTitle className="flex items-center gap-2">
173
+ <FileText size={18} aria-hidden="true" />
174
+ Workspace Documents
175
+ <Badge variant="secondary">{files.length}</Badge>
176
+ </CardTitle>
177
+ <Button variant="outline" size="sm" onClick={() => void load()} disabled={isLoading}>
178
+ Refresh
179
+ </Button>
180
+ </CardHeader>
181
+ <CardContent>
182
+ {error && <p className="text-sm text-status-error-text mb-3">{error}</p>}
183
+ {isLoading ? (
184
+ <p className="text-sm text-text-secondary py-6 text-center">Loading documents…</p>
185
+ ) : files.length === 0 ? (
186
+ <div className="py-10 text-center space-y-2">
187
+ <FileText size={32} className="mx-auto text-text-secondary opacity-50" />
188
+ <p className="text-sm text-text-secondary">
189
+ No documents found for this workspace filter.
190
+ </p>
191
+ <Button variant="outline" size="sm" onClick={() => navigate('/files/browse')}>
192
+ <ExternalLink size={14} aria-hidden="true" /> Upload in Files
193
+ </Button>
194
+ </div>
195
+ ) : (
196
+ <ul className="divide-y divide-border-seam">
197
+ {files.map((file) => (
198
+ <li key={file.id} className="flex items-center justify-between gap-4 py-3">
199
+ <div className="min-w-0">
200
+ <p className="font-medium text-text-primary truncate">{file.name}</p>
201
+ <p className="text-xs text-text-secondary">
202
+ {file.mimeType} · {formatSize(file.size)} ·{' '}
203
+ {formatDate(file.createdAt, 'relative')}
204
+ </p>
205
+ </div>
206
+ {file.downloadUrl ? (
207
+ <a
208
+ href={file.downloadUrl}
209
+ target="_blank"
210
+ rel="noopener noreferrer"
211
+ className="inline-flex items-center gap-1 text-sm text-primary hover:underline shrink-0"
212
+ >
213
+ <Download size={14} aria-hidden="true" /> Open
214
+ </a>
215
+ ) : (
216
+ <Button variant="ghost" size="sm" onClick={() => navigate('/files/browse')}>
217
+ <ExternalLink size={14} aria-hidden="true" /> View
218
+ </Button>
219
+ )}
220
+ </li>
221
+ ))}
222
+ </ul>
223
+ )}
224
+ </CardContent>
225
+ </Card>
226
+ </div>
227
+ </PageLayout>
228
+ );
229
+ }