@burdenoff/microfe-movethewheels 2026.924.1 → 2026.925.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.
@@ -0,0 +1,210 @@
1
+ import { Trash2 as e } from "../node_modules/lucide-react/dist/esm/icons/trash-2.js";
2
+ import { useProduct as t, useProductStockLevels as n } from "../hooks/useInventory.js";
3
+ import { Button as r, Input as i, Label as a } from "./ui.js";
4
+ import { EntityCombobox as o } from "./EntityCombobox.js";
5
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
6
+ //#region src/movethewheels/components/OrderItemRow.tsx
7
+ function u(e, t) {
8
+ return e <= 0 ? "No stock recorded for this item." : t.length === 1 ? `${e.toLocaleString()} available at ${t[0].warehouseName}` : `${e.toLocaleString()} available across ${t.length} warehouses`;
9
+ }
10
+ function d({ item: d, index: f, products: p, productsLoading: m, onUpdate: h, onRemove: g }) {
11
+ let { product: _, isLoading: v } = t(d.productId || void 0), { levels: y, totalAvailable: b, isLoading: x } = n(d.productId || void 0), S = d.dimensions ?? {
12
+ length: 0,
13
+ width: 0,
14
+ height: 0,
15
+ unit: "cm"
16
+ }, C = (e) => {
17
+ if (!e) {
18
+ h(f, "productId", "");
19
+ return;
20
+ }
21
+ let t = p.find((t) => t.id === e);
22
+ t && (h(f, "productId", t.id), h(f, "name", t.name), h(f, "sku", t.sku), h(f, "weight", t.weight), h(f, "value", t.value), h(f, "dimensions", t.dimensions));
23
+ }, w = (e, t) => {
24
+ h(f, "dimensions", {
25
+ ...S,
26
+ [e]: Number.parseFloat(t) || 0
27
+ });
28
+ };
29
+ return /* @__PURE__ */ l("div", {
30
+ className: "rounded-card border border-border-subtle bg-bg-surface p-4 shadow-elevation-1 sm:p-5",
31
+ "aria-labelledby": `order-item-${d.id}-title`,
32
+ children: [/* @__PURE__ */ l("div", {
33
+ className: "mb-4 flex items-start justify-between gap-4",
34
+ children: [/* @__PURE__ */ l("div", { children: [/* @__PURE__ */ l("h3", {
35
+ id: `order-item-${d.id}-title`,
36
+ className: "text-sm font-semibold text-text-primary",
37
+ children: ["Item ", f + 1]
38
+ }), /* @__PURE__ */ c("p", {
39
+ className: "mt-1 text-xs text-text-secondary",
40
+ children: "Select a catalog item to prefill details, or enter a one-off shipment manually."
41
+ })] }), /* @__PURE__ */ c(r, {
42
+ type: "button",
43
+ variant: "ghost",
44
+ size: "icon",
45
+ className: "shrink-0 text-status-error-text",
46
+ onClick: () => g(f),
47
+ "aria-label": `Remove item ${f + 1}`,
48
+ title: `Remove item ${f + 1}`,
49
+ children: /* @__PURE__ */ c(e, {
50
+ size: 16,
51
+ "aria-hidden": "true"
52
+ })
53
+ })]
54
+ }), /* @__PURE__ */ l("div", {
55
+ className: "space-y-4",
56
+ children: [
57
+ /* @__PURE__ */ l("div", {
58
+ className: "rounded-card border border-border-subtle bg-bg-sunken/40 p-3 sm:p-4",
59
+ children: [
60
+ /* @__PURE__ */ c(a, {
61
+ htmlFor: `item-product-${d.id}`,
62
+ children: "Catalog item (optional)"
63
+ }),
64
+ /* @__PURE__ */ c(o, {
65
+ id: `item-product-${d.id}`,
66
+ value: d.productId,
67
+ onChange: C,
68
+ options: p,
69
+ loading: m,
70
+ getId: (e) => e.id,
71
+ getLabel: (e) => `${e.name} (${e.sku})`,
72
+ renderOption: (e) => /* @__PURE__ */ l(s, { children: [
73
+ e.name,
74
+ " ",
75
+ /* @__PURE__ */ l("span", {
76
+ className: "text-text-tertiary",
77
+ children: [
78
+ "(",
79
+ e.sku,
80
+ ")"
81
+ ]
82
+ })
83
+ ] }),
84
+ selectedOption: _,
85
+ selectedLoading: v,
86
+ placeholder: "Pick from your product catalog",
87
+ emptyText: "No products found.",
88
+ noneLabel: "Enter details manually"
89
+ }),
90
+ d.productId && !x && /* @__PURE__ */ c("p", {
91
+ className: "mt-2 text-xs text-text-secondary",
92
+ role: "status",
93
+ children: u(b, y)
94
+ })
95
+ ]
96
+ }),
97
+ /* @__PURE__ */ l("div", {
98
+ className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-12",
99
+ children: [
100
+ /* @__PURE__ */ l("div", {
101
+ className: "space-y-2 lg:col-span-4",
102
+ children: [/* @__PURE__ */ c(a, {
103
+ htmlFor: `item-name-${d.id}`,
104
+ children: "Item name"
105
+ }), /* @__PURE__ */ c(i, {
106
+ id: `item-name-${d.id}`,
107
+ value: d.name,
108
+ onChange: (e) => h(f, "name", e.target.value),
109
+ placeholder: "Product name"
110
+ })]
111
+ }),
112
+ /* @__PURE__ */ l("div", {
113
+ className: "space-y-2 lg:col-span-3",
114
+ children: [/* @__PURE__ */ c(a, {
115
+ htmlFor: `item-sku-${d.id}`,
116
+ children: "SKU"
117
+ }), /* @__PURE__ */ c(i, {
118
+ id: `item-sku-${d.id}`,
119
+ value: d.sku,
120
+ onChange: (e) => h(f, "sku", e.target.value),
121
+ placeholder: "SKU-001"
122
+ })]
123
+ }),
124
+ /* @__PURE__ */ l("div", {
125
+ className: "space-y-2 lg:col-span-2",
126
+ children: [/* @__PURE__ */ c(a, {
127
+ htmlFor: `item-quantity-${d.id}`,
128
+ children: "Quantity"
129
+ }), /* @__PURE__ */ c(i, {
130
+ id: `item-quantity-${d.id}`,
131
+ type: "number",
132
+ min: "1",
133
+ value: d.quantity,
134
+ onChange: (e) => h(f, "quantity", parseInt(e.target.value, 10) || 1)
135
+ })]
136
+ }),
137
+ /* @__PURE__ */ l("div", {
138
+ className: "space-y-2 lg:col-span-2",
139
+ children: [/* @__PURE__ */ c(a, {
140
+ htmlFor: `item-weight-${d.id}`,
141
+ children: "Weight (kg)"
142
+ }), /* @__PURE__ */ c(i, {
143
+ id: `item-weight-${d.id}`,
144
+ type: "number",
145
+ min: "0",
146
+ step: "0.1",
147
+ value: d.weight,
148
+ onChange: (e) => h(f, "weight", parseFloat(e.target.value) || 0)
149
+ })]
150
+ }),
151
+ /* @__PURE__ */ l("div", {
152
+ className: "space-y-2 lg:col-span-1",
153
+ children: [/* @__PURE__ */ c(a, {
154
+ htmlFor: `item-value-${d.id}`,
155
+ children: "Value ($)"
156
+ }), /* @__PURE__ */ c(i, {
157
+ id: `item-value-${d.id}`,
158
+ type: "number",
159
+ min: "0",
160
+ step: "0.01",
161
+ value: d.value,
162
+ onChange: (e) => h(f, "value", parseFloat(e.target.value) || 0)
163
+ })]
164
+ })
165
+ ]
166
+ }),
167
+ /* @__PURE__ */ l("fieldset", {
168
+ className: "rounded-card border border-border-subtle bg-bg-sunken/40 p-3 sm:p-4",
169
+ children: [
170
+ /* @__PURE__ */ l("legend", {
171
+ className: "px-1 text-xs font-medium text-text-secondary",
172
+ children: [
173
+ "Dimensions (",
174
+ S.unit,
175
+ ")"
176
+ ]
177
+ }),
178
+ /* @__PURE__ */ c("div", {
179
+ className: "grid grid-cols-1 gap-4 sm:grid-cols-3",
180
+ children: [
181
+ "length",
182
+ "width",
183
+ "height"
184
+ ].map((e) => /* @__PURE__ */ l("div", {
185
+ className: "space-y-2",
186
+ children: [/* @__PURE__ */ c(a, {
187
+ htmlFor: `item-${e}-${d.id}`,
188
+ children: e.charAt(0).toUpperCase() + e.slice(1)
189
+ }), /* @__PURE__ */ c(i, {
190
+ id: `item-${e}-${d.id}`,
191
+ type: "number",
192
+ min: "0",
193
+ step: "0.1",
194
+ value: S[e],
195
+ onChange: (t) => w(e, t.target.value)
196
+ })]
197
+ }, e))
198
+ }),
199
+ /* @__PURE__ */ c("p", {
200
+ className: "mt-2 text-xs text-text-secondary",
201
+ children: "Catalog selections prefill these measurements, and you can adjust them for this order."
202
+ })
203
+ ]
204
+ })
205
+ ]
206
+ })]
207
+ });
208
+ }
209
+ //#endregion
210
+ export { d as OrderItemRow };
@@ -26,6 +26,7 @@ var e = {
26
26
  in_transit: r,
27
27
  out_for_delivery: t,
28
28
  delivered: e,
29
+ returned: t,
29
30
  cancelled: n,
30
31
  failed: n
31
32
  }, o = {
@@ -873,10 +873,15 @@ export type GetMovethewheelsDashboardQuery = {
873
873
  __typename?: 'MtwDeliveryJobStats';
874
874
  total: number;
875
875
  pending: number;
876
+ confirmed: number;
877
+ assigned: number;
878
+ pickedUp: number;
876
879
  inTransit: number;
880
+ outForDelivery: number;
877
881
  delivered: number;
878
882
  cancelled: number;
879
883
  failed: number;
884
+ returned: number;
880
885
  };
881
886
  fleetStats: {
882
887
  __typename?: 'MtwFleetStats';
@@ -1386,6 +1391,7 @@ export type GetShipmentQuery = {
1386
1391
  };
1387
1392
  export type GetDeliveryJobTrackingQueryVariables = Types.Exact<{
1388
1393
  deliveryJobId: Types.Scalars['ID']['input'];
1394
+ pagination?: Types.InputMaybe<Types.PaginationInput>;
1389
1395
  }>;
1390
1396
  export type GetDeliveryJobTrackingQuery = {
1391
1397
  __typename?: 'Query';
@@ -2943,6 +2949,7 @@ export declare const GetDeliveryJobTrackingDocument: Apollo.DocumentNode;
2943
2949
  * const { data, loading, error } = useGetDeliveryJobTrackingQuery({
2944
2950
  * variables: {
2945
2951
  * deliveryJobId: // value for 'deliveryJobId'
2952
+ * pagination: // value for 'pagination'
2946
2953
  * },
2947
2954
  * });
2948
2955
  */
@@ -16,7 +16,7 @@ var s = "\n id\n deliveryJobNumber\n customerId\n status\n priority\n pick
16
16
  ${s}
17
17
  }
18
18
  }
19
- `, u = "\n query GetDeliveryJobStatsBundle {\n deliveryJobStats {\n total\n pending\n inTransit\n delivered\n cancelled\n failed\n }\n financeMetrics {\n revenue {\n totalRevenue\n averageOrderValue\n }\n }\n }\n", d = `
19
+ `, u = "\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", d = `
20
20
  mutation CreateDeliveryJob($input: CreateDeliveryJobInput!) {
21
21
  createDeliveryJob(input: $input) {
22
22
  ${s}
@@ -44,6 +44,7 @@ function h(e) {
44
44
  case "IN_TRANSIT": return "in_transit";
45
45
  case "OUT_FOR_DELIVERY": return "out_for_delivery";
46
46
  case "DELIVERED": return "delivered";
47
+ case "RETURNED": return "returned";
47
48
  case "CANCELLED": return "cancelled";
48
49
  default: return "failed";
49
50
  }
@@ -66,6 +67,7 @@ function _(e) {
66
67
  case "in_transit": return "IN_TRANSIT";
67
68
  case "out_for_delivery": return "OUT_FOR_DELIVERY";
68
69
  case "delivered": return "DELIVERED";
70
+ case "returned": return "RETURNED";
69
71
  case "cancelled": return "CANCELLED";
70
72
  default: return "FAILED";
71
73
  }
@@ -301,6 +303,7 @@ function C() {
301
303
  in_transit: 0,
302
304
  out_for_delivery: 0,
303
305
  delivered: 0,
306
+ returned: 0,
304
307
  cancelled: 0,
305
308
  failed: 0
306
309
  },
@@ -329,12 +332,13 @@ function C() {
329
332
  total: e.deliveryJobStats.total,
330
333
  byStatus: {
331
334
  pending: e.deliveryJobStats.pending,
332
- confirmed: 0,
333
- assigned: 0,
335
+ confirmed: e.deliveryJobStats.confirmed,
336
+ assigned: e.deliveryJobStats.assigned,
334
337
  picked_up: 0,
335
338
  in_transit: e.deliveryJobStats.inTransit,
336
- out_for_delivery: 0,
339
+ out_for_delivery: e.deliveryJobStats.outForDelivery,
337
340
  delivered: e.deliveryJobStats.delivered,
341
+ returned: e.deliveryJobStats.returned,
338
342
  cancelled: e.deliveryJobStats.cancelled,
339
343
  failed: e.deliveryJobStats.failed
340
344
  },
@@ -4,28 +4,33 @@ import { mapOrder as n, useOrder as r } from "./useOrders.js";
4
4
  import { mapDriver as i, mapVehicle as a, useDriver as o, useDrivers as s, useVehicle as c, useVehicles as l } from "./useFleet.js";
5
5
  import { useCallback as u, useEffect as d, useMemo as f, useState as p } from "react";
6
6
  //#region src/movethewheels/hooks/useTracking.ts
7
- var m = "\n query ListShipments($filter: ShipmentFilterInput, $pagination: PaginationInput) {\n shipments(filter: $filter, pagination: $pagination) {\n id\n shipmentNumber\n deliveryJobId\n status\n estimatedDelivery\n }\n }\n", h = "\n query GetDeliveryJobTracking($deliveryJobId: ID!, $pagination: PaginationInput) {\n deliveryJobTracking(deliveryJobId: $deliveryJobId, pagination: $pagination) {\n id\n shipmentId\n eventType\n location\n details\n timestamp\n }\n }\n", g = "\n query GetActiveDeliveries($pagination: PaginationInput) {\n activeDeliveries(pagination: $pagination) {\n id\n shipmentNumber\n deliveryJobId\n status\n estimatedDelivery\n trackingEvents(pagination: { limit: 1, offset: 0 }) {\n id\n shipmentId\n eventType\n location\n details\n timestamp\n }\n deliveryJob {\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 createdAt\n updatedAt\n customer {\n name\n email\n phone\n company\n }\n vehicle {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n }\n driver {\n id\n userId\n firstName\n lastName\n email\n phone\n employeeId\n licenseNumber\n licenseClass\n licenseExpiry\n status\n currentLocation\n rating\n vehicleId\n createdAt\n }\n }\n }\n }\n", _ = "\n query GetTrackingAlerts {\n trackingAlerts {\n shipmentId\n shipmentNumber\n alertType\n message\n }\n }\n";
8
- function v(e, t) {
9
- let n = {
7
+ var m = "\n query ListShipments($filter: ShipmentFilterInput, $pagination: PaginationInput) {\n shipments(filter: $filter, pagination: $pagination) {\n id\n shipmentNumber\n deliveryJobId\n status\n trackingNumber\n estimatedDelivery\n }\n }\n", h = "\n query LookupDeliveryJob($id: ID!) {\n deliveryJob(id: $id) {\n id\n }\n }\n", g = "\n query LookupDeliveryJobs($filter: DeliveryJobFilterInput, $pagination: PaginationInput) {\n deliveryJobs(filter: $filter, pagination: $pagination) {\n id\n deliveryJobNumber\n trackingNumber\n }\n }\n", _ = "\n query GetDeliveryJobTracking($deliveryJobId: ID!, $pagination: PaginationInput) {\n deliveryJobTracking(deliveryJobId: $deliveryJobId, pagination: $pagination) {\n id\n shipmentId\n eventType\n location\n details\n timestamp\n }\n }\n", v = "\n query GetActiveDeliveries($pagination: PaginationInput) {\n activeDeliveries(pagination: $pagination) {\n id\n shipmentNumber\n deliveryJobId\n status\n estimatedDelivery\n trackingEvents(pagination: { limit: 1, offset: 0 }) {\n id\n shipmentId\n eventType\n location\n details\n timestamp\n }\n deliveryJob {\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 createdAt\n updatedAt\n customer {\n name\n email\n phone\n company\n }\n vehicle {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n }\n driver {\n id\n userId\n firstName\n lastName\n email\n phone\n employeeId\n licenseNumber\n licenseClass\n licenseExpiry\n status\n currentLocation\n rating\n vehicleId\n createdAt\n }\n }\n }\n }\n", y = "\n query GetTrackingAlerts {\n trackingAlerts {\n shipmentId\n shipmentNumber\n alertType\n message\n }\n }\n";
8
+ function b(e) {
9
+ return {
10
10
  latitude: Number(e.location?.latitude ?? 0),
11
11
  longitude: Number(e.location?.longitude ?? 0),
12
12
  address: e.location?.address ?? void 0,
13
13
  timestamp: new Date(e.timestamp)
14
14
  };
15
- return {
16
- id: e.id,
15
+ }
16
+ function x(e, t) {
17
+ let n = e[0];
18
+ if (!n) return null;
19
+ let r = e.map(b), i = r[0];
20
+ return i ? {
21
+ id: n.id,
17
22
  entityId: t,
18
23
  entityType: "order",
19
- currentLocation: n,
20
- locationHistory: [n],
21
- status: e.eventType.toLowerCase(),
24
+ currentLocation: i,
25
+ locationHistory: r,
26
+ status: n.eventType.toLowerCase(),
22
27
  estimatedArrival: void 0,
23
- nextCheckpoint: e.details ?? void 0,
28
+ nextCheckpoint: n.details ?? void 0,
24
29
  alerts: [],
25
- lastUpdated: new Date(e.timestamp)
26
- };
30
+ lastUpdated: new Date(n.timestamp)
31
+ } : null;
27
32
  }
28
- function y() {
33
+ function S() {
29
34
  let { apiGatewayUrl: t, authToken: n, workspaceToken: r, workspaceId: i, tenantId: a, currentUser: o } = e();
30
35
  return f(() => ({
31
36
  apiGatewayUrl: t,
@@ -43,11 +48,23 @@ function y() {
43
48
  o?.id
44
49
  ]);
45
50
  }
46
- function b(e = {}) {
47
- let { entityId: n, entityType: r } = e, i = y(), [a, o] = p([]), [s, c] = p(!1), [l, f] = p(null), h = u(async () => {
48
- c(!0), f(null);
51
+ var C = 3e4;
52
+ function w(e, t) {
53
+ d(() => {
54
+ if (!t || typeof document > "u") return;
55
+ let n = () => {
56
+ document.visibilityState === "visible" && e();
57
+ }, r = window.setInterval(n, C);
58
+ return document.addEventListener("visibilitychange", n), () => {
59
+ window.clearInterval(r), document.removeEventListener("visibilitychange", n);
60
+ };
61
+ }, [t, e]);
62
+ }
63
+ function T(e = {}) {
64
+ let { entityId: n, entityType: r, realtime: i = !1 } = e, a = S(), [o, s] = p([]), [c, l] = p(!1), [f, h] = p(null), g = u(async () => {
65
+ l(!0), h(null);
49
66
  try {
50
- o((await t(i, m, {
67
+ s((await t(a, m, {
51
68
  filter: n ? {
52
69
  ...r === "order" ? { deliveryJobId: n } : {},
53
70
  ...r === "vehicle" ? { vehicleId: n } : {},
@@ -74,57 +91,103 @@ function b(e = {}) {
74
91
  lastUpdated: /* @__PURE__ */ new Date()
75
92
  })));
76
93
  } catch (e) {
77
- f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load tracking data"));
94
+ h(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load tracking data"));
78
95
  } finally {
79
- c(!1);
96
+ l(!1);
80
97
  }
81
98
  }, [
82
99
  n,
83
100
  r,
84
- i
101
+ a
85
102
  ]);
86
103
  return d(() => {
87
- h();
88
- }, [h]), {
89
- tracking: a,
90
- isLoading: s,
91
- error: l,
92
- refetch: () => void h()
104
+ g();
105
+ }, [g]), w(g, i), {
106
+ tracking: o,
107
+ isLoading: c,
108
+ error: f,
109
+ refetch: () => void g()
93
110
  };
94
111
  }
95
- function x(e) {
96
- let n = y(), { order: i } = r(e), [a, o] = p(null), [s, c] = p(!1), [l, f] = p(null), m = u(async () => {
97
- if (!e) {
98
- o(null);
112
+ async function E(e, n) {
113
+ let r = n.trim(), i = await t(e, h, { id: r });
114
+ if (i.deliveryJob?.id) return i.deliveryJob.id;
115
+ let a = await t(e, g, {
116
+ filter: { search: r },
117
+ pagination: {
118
+ limit: 50,
119
+ offset: 0
120
+ }
121
+ }), o = r.toLocaleLowerCase(), s = a.deliveryJobs.filter((e) => [
122
+ e.id,
123
+ e.deliveryJobNumber,
124
+ e.trackingNumber
125
+ ].filter((e) => !!e).some((e) => e.toLocaleLowerCase() === o));
126
+ if (s.length > 1) throw Error("Multiple deliveries match that reference. Enter the full tracking number.");
127
+ if (s[0]) return s[0].id;
128
+ let c = (await t(e, m, {
129
+ filter: { search: r },
130
+ pagination: {
131
+ limit: 50,
132
+ offset: 0
133
+ }
134
+ })).shipments.filter((e) => [e.trackingNumber, e.shipmentNumber].filter((e) => !!e).some((e) => e.toLocaleLowerCase() === o)), l = [...new Set(c.map((e) => e.deliveryJobId).filter((e) => !!e))];
135
+ if (l.length > 1) throw Error("Multiple shipments match that reference. Enter the full tracking number.");
136
+ return l[0] ?? null;
137
+ }
138
+ function D(e) {
139
+ let n = S(), [i, a] = p(), [o, s] = p(!1), [c, l] = p(null), [f, m] = p(0), { order: h, isLoading: g, error: v, refetch: y } = r(i), [b, C] = p(null), [T, D] = p(!1), [O, k] = p(null);
140
+ d(() => {
141
+ let t = !1, r = e?.trim() ?? "";
142
+ return a(void 0), C(null), l(null), r ? (s(!0), E(n, r).then((e) => {
143
+ t || a(e ?? void 0);
144
+ }).catch((e) => {
145
+ t || l(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to find the delivery"));
146
+ }).finally(() => {
147
+ t || s(!1);
148
+ }), () => {
149
+ t = !0;
150
+ }) : (s(!1), () => {
151
+ t = !0;
152
+ });
153
+ }, [
154
+ n,
155
+ f,
156
+ e
157
+ ]);
158
+ let A = u(async () => {
159
+ if (!i) {
160
+ C(null), D(!1);
99
161
  return;
100
162
  }
101
- c(!0), f(null);
163
+ D(!0), k(null);
102
164
  try {
103
- let r = (await t(n, h, {
104
- deliveryJobId: e,
165
+ C(x([...(await t(n, _, {
166
+ deliveryJobId: i,
105
167
  pagination: {
106
- limit: 1,
168
+ limit: 50,
107
169
  offset: 0
108
170
  }
109
- })).deliveryJobTracking[0];
110
- o(r ? v(r, e) : null);
171
+ })).deliveryJobTracking].sort((e, t) => Date.parse(t.timestamp) - Date.parse(e.timestamp)), i));
111
172
  } catch (e) {
112
- f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load order tracking"));
173
+ k(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load order tracking"));
113
174
  } finally {
114
- c(!1);
175
+ D(!1);
115
176
  }
116
- }, [n, e]);
177
+ }, [n, i]);
117
178
  return d(() => {
118
- m();
119
- }, [m]), {
120
- tracking: a,
121
- order: i,
122
- isLoading: s,
123
- error: l,
124
- refetch: () => void m()
179
+ A();
180
+ }, [A]), w(A, !!i), {
181
+ tracking: b,
182
+ order: i ? h : null,
183
+ isLoading: o || g || T,
184
+ error: c ?? (i ? v ?? O : null),
185
+ refetch: () => {
186
+ m((e) => e + 1), i && (y(), A());
187
+ }
125
188
  };
126
189
  }
127
- function S(e) {
190
+ function O(e) {
128
191
  let { vehicle: t, isLoading: n, error: r, refetch: i } = c(e);
129
192
  return {
130
193
  tracking: f(() => !t || !t.currentLocation ? null : {
@@ -143,7 +206,7 @@ function S(e) {
143
206
  refetch: i
144
207
  };
145
208
  }
146
- function C(e) {
209
+ function k(e) {
147
210
  let { driver: t, isLoading: n, error: r, refetch: i } = o(e);
148
211
  return {
149
212
  tracking: f(() => !t || !t.currentLocation ? null : {
@@ -162,24 +225,22 @@ function C(e) {
162
225
  refetch: i
163
226
  };
164
227
  }
165
- function w() {
166
- let e = y(), [r, o] = p([]), [s, c] = p(!1), [l, f] = p(null), m = u(async () => {
228
+ function A() {
229
+ let e = S(), [r, o] = p([]), [s, c] = p(!1), [l, f] = p(null), m = u(async () => {
167
230
  c(!0), f(null);
168
231
  try {
169
- o(((await t(e, g, { pagination: {
232
+ o(((await t(e, v, { pagination: {
170
233
  limit: 100,
171
234
  offset: 0
172
235
  } })).activeDeliveries ?? []).map((e) => {
173
236
  let t = e.deliveryJob;
174
- if (!t) return null;
175
- let r = e.trackingEvents?.[0];
176
- return {
237
+ return t ? {
177
238
  order: n(t),
178
239
  driver: t.driver ? i(t.driver) : null,
179
240
  vehicle: t.vehicle ? a(t.vehicle) : null,
180
- tracking: r ? v(r, t.id) : null,
241
+ tracking: x(e.trackingEvents ?? [], t.id),
181
242
  estimatedArrival: e.estimatedDelivery ? new Date(e.estimatedDelivery) : void 0
182
- };
243
+ } : null;
183
244
  }).filter((e) => e !== null));
184
245
  } catch (e) {
185
246
  f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load live tracking"));
@@ -189,18 +250,18 @@ function w() {
189
250
  }, [e]);
190
251
  return d(() => {
191
252
  m();
192
- }, [m]), {
253
+ }, [m]), w(m, !0), {
193
254
  activeDeliveries: r,
194
255
  isLoading: s,
195
256
  error: l,
196
257
  refetch: () => void m()
197
258
  };
198
259
  }
199
- function T() {
200
- let e = y(), [n, r] = p([]), [i, a] = p(!1), [o, s] = p(null), c = u(async () => {
260
+ function j() {
261
+ let e = S(), [n, r] = p([]), [i, a] = p(!1), [o, s] = p(null), c = u(async () => {
201
262
  a(!0), s(null);
202
263
  try {
203
- r((await t(e, _)).trackingAlerts.map((e) => ({
264
+ r((await t(e, y)).trackingAlerts.map((e) => ({
204
265
  id: `${e.shipmentId}-${e.alertType}`,
205
266
  type: "delay",
206
267
  severity: "medium",
@@ -230,14 +291,14 @@ function T() {
230
291
  refetch: () => void c()
231
292
  };
232
293
  }
233
- function E(e, t) {
294
+ function M(e, t) {
234
295
  let { vehicles: n } = l(), { drivers: r } = s();
235
296
  return {
236
297
  entitiesInRange: f(() => {
237
298
  let i = [];
238
299
  return n.forEach((n) => {
239
300
  if (!n.currentLocation) return;
240
- let r = D(e.latitude, e.longitude, n.currentLocation.latitude, n.currentLocation.longitude);
301
+ let r = N(e.latitude, e.longitude, n.currentLocation.latitude, n.currentLocation.longitude);
241
302
  r <= t && i.push({
242
303
  type: "vehicle",
243
304
  entity: n,
@@ -245,7 +306,7 @@ function E(e, t) {
245
306
  });
246
307
  }), r.forEach((n) => {
247
308
  if (!n.currentLocation) return;
248
- let r = D(e.latitude, e.longitude, n.currentLocation.latitude, n.currentLocation.longitude);
309
+ let r = N(e.latitude, e.longitude, n.currentLocation.latitude, n.currentLocation.longitude);
249
310
  r <= t && i.push({
250
311
  type: "driver",
251
312
  entity: n,
@@ -263,12 +324,12 @@ function E(e, t) {
263
324
  error: null
264
325
  };
265
326
  }
266
- function D(e, t, n, r) {
267
- let i = O(n - e), a = O(r - t), o = Math.sin(i / 2) * Math.sin(i / 2) + Math.cos(O(e)) * Math.cos(O(n)) * Math.sin(a / 2) * Math.sin(a / 2);
327
+ function N(e, t, n, r) {
328
+ let i = P(n - e), a = P(r - t), o = Math.sin(i / 2) * Math.sin(i / 2) + Math.cos(P(e)) * Math.cos(P(n)) * Math.sin(a / 2) * Math.sin(a / 2);
268
329
  return 6371 * (2 * Math.atan2(Math.sqrt(o), Math.sqrt(1 - o)));
269
330
  }
270
- function O(e) {
331
+ function P(e) {
271
332
  return Math.PI / 180 * e;
272
333
  }
273
334
  //#endregion
274
- export { C as useDriverTracking, E as useGeofence, w as useLiveTracking, x as useOrderTracking, b as useTracking, T as useTrackingAlerts, S as useVehicleTracking };
335
+ export { k as useDriverTracking, M as useGeofence, A as useLiveTracking, D as useOrderTracking, T as useTracking, j as useTrackingAlerts, O as useVehicleTracking };
@@ -0,0 +1,12 @@
1
+ import { OrderItem, Product } from '../types';
2
+
3
+ interface OrderItemRowProps {
4
+ item: OrderItem;
5
+ index: number;
6
+ products: Product[];
7
+ productsLoading: boolean;
8
+ onUpdate: (index: number, field: string, value: unknown) => void;
9
+ onRemove: (index: number) => void;
10
+ }
11
+ export declare function OrderItemRow({ item, index, products, productsLoading, onUpdate, onRemove, }: OrderItemRowProps): import("react").JSX.Element;
12
+ export {};
@@ -106,6 +106,7 @@ export declare function useOrderStats(): {
106
106
  in_transit: number;
107
107
  out_for_delivery: number;
108
108
  delivered: number;
109
+ returned: number;
109
110
  cancelled: number;
110
111
  failed: number;
111
112
  };
@@ -19,12 +19,12 @@ interface LiveDelivery {
19
19
  estimatedArrival: Date | undefined;
20
20
  }
21
21
  export declare function useTracking(options?: UseTrackingOptions): UseTrackingResult;
22
- export declare function useOrderTracking(orderId: string | undefined): {
22
+ export declare function useOrderTracking(orderLookup: string | undefined): {
23
23
  tracking: Tracking | null;
24
24
  order: Order | null;
25
25
  isLoading: boolean;
26
26
  error: Error | null;
27
- refetch: () => undefined;
27
+ refetch: () => void;
28
28
  };
29
29
  export declare function useVehicleTracking(vehicleId: string | undefined): {
30
30
  tracking: Tracking | null;
@@ -199,7 +199,7 @@ export interface OrderPricing {
199
199
  paymentMethod: string;
200
200
  paymentStatus: 'pending' | 'paid' | 'failed' | 'refunded';
201
201
  }
202
- export type OrderStatus = 'pending' | 'confirmed' | 'assigned' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'cancelled' | 'failed';
202
+ export type OrderStatus = 'pending' | 'confirmed' | 'assigned' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'failed';
203
203
  export interface Order {
204
204
  id: string;
205
205
  orderNumber: string;