@burdenoff/microfe-movethewheels 2026.930.2 → 2026.930.3
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
CHANGED
|
@@ -2,8 +2,8 @@ import { useMoveTheWheels as e } from "../providers/MoveTheWheelsProvider.js";
|
|
|
2
2
|
import { executeGraphQL as t } from "../utils/graphqlClient.js";
|
|
3
3
|
import { useCallback as n, useEffect as r, useMemo as i, useState as a } from "react";
|
|
4
4
|
//#region src/movethewheels/hooks/useFleet.ts
|
|
5
|
-
var o = "\n query ListVehicles($filter: VehicleFilterInput, $pagination: PaginationInput) {\n vehicles(filter: $filter, pagination: $pagination) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n vehiclesCount(filter: $filter)\n }\n", s = "\n query ListDrivers($filter: DriverFilterInput, $pagination: PaginationInput) {\n drivers(filter: $filter, pagination: $pagination) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n driversCount(filter: $filter)\n }\n", c = "\n query GetVehicle($id: ID!) {\n vehicle(id: $id) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n }\n", l = "\n query GetDriver($id: ID!) {\n driver(id: $id) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", u = "\n mutation DeleteVehicle($id: ID!) {\n deleteVehicle(id: $id)\n }\n",
|
|
6
|
-
function
|
|
5
|
+
var o = "\n query ListVehicles($filter: VehicleFilterInput, $pagination: PaginationInput) {\n vehicles(filter: $filter, pagination: $pagination) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n vehiclesCount(filter: $filter)\n }\n", s = "\n query ListDrivers($filter: DriverFilterInput, $pagination: PaginationInput) {\n drivers(filter: $filter, pagination: $pagination) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n driversCount(filter: $filter)\n }\n", c = "\n query GetVehicle($id: ID!) {\n vehicle(id: $id) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n lastServiceDate\n nextServiceDueDate\n nextServiceDueMileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n }\n", l = "\n query GetDriver($id: ID!) {\n driver(id: $id) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", u = "\n mutation DeleteDriver($id: ID!) {\n deleteDriver(id: $id)\n }\n", d = "\n mutation DeleteVehicle($id: ID!) {\n deleteVehicle(id: $id)\n }\n", f = "\n mutation UpdateVehicleStatus($id: ID!, $status: VehicleStatus!) {\n updateVehicleStatus(id: $id, status: $status) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n }\n", p = "\n mutation AssignDriverVehicle($id: ID!, $vehicleId: ID) {\n assignDriverVehicle(id: $id, vehicleId: $vehicleId) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", m = "\n mutation UpdateDriverStatus($id: ID!, $status: DriverStatus!) {\n updateDriverStatus(id: $id, status: $status) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", h = "\n mutation CreateVehicle($input: CreateVehicleInput!) {\n createVehicle(input: $input) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n }\n", g = "\n mutation CreateDriver($input: CreateDriverInput!) {\n createDriver(input: $input) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", _ = "\n mutation UpdateVehicle($id: ID!, $input: UpdateVehicleInput!) {\n updateVehicle(id: $id, input: $input) {\n id\n vehicleNumber\n type\n make\n model\n licensePlate\n ownershipType\n year\n capacity\n status\n currentLocation\n fuelType\n fuelEfficiencyLPer100Km\n fuelLevel\n mileage\n createdAt\n updatedAt\n drivers {\n id\n }\n }\n }\n", v = "\n mutation UpdateDriver($id: ID!, $input: UpdateDriverInput!) {\n updateDriver(id: $id, input: $input) {\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 notes\n hireDate\n baseSalary\n bonusYtd\n payCurrency\n onLeaveUntil\n terminatedAt\n terminationReason\n createdAt\n vehicles {\n id\n }\n }\n }\n", y = "\n query GetDriverStatusCounts {\n onBreak: driversCount(filter: { status: ON_BREAK })\n offDuty: driversCount(filter: { status: OFF_DUTY })\n inactive: driversCount(filter: { status: INACTIVE })\n }\n", b = "\n query GetFleetStats {\n fleetStats {\n totalVehicles\n activeVehicles\n inTransitVehicles\n maintenanceVehicles\n totalDrivers\n availableDrivers\n onDeliveryDrivers\n avgDriverRating\n }\n }\n";
|
|
6
|
+
function x(e) {
|
|
7
7
|
switch (e) {
|
|
8
8
|
case "ACTIVE": return "available";
|
|
9
9
|
case "IN_TRANSIT": return "assigned";
|
|
@@ -12,7 +12,7 @@ function b(e) {
|
|
|
12
12
|
default: return "out_of_service";
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function S(e) {
|
|
16
16
|
switch (e) {
|
|
17
17
|
case "available": return "ACTIVE";
|
|
18
18
|
case "assigned": return "IN_TRANSIT";
|
|
@@ -21,7 +21,7 @@ function x(e) {
|
|
|
21
21
|
default: return "INACTIVE";
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function C(e) {
|
|
25
25
|
switch (e) {
|
|
26
26
|
case "AVAILABLE": return "available";
|
|
27
27
|
case "ON_DELIVERY": return "busy";
|
|
@@ -30,7 +30,7 @@ function S(e) {
|
|
|
30
30
|
default: return "offline";
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function w(e) {
|
|
34
34
|
switch (e) {
|
|
35
35
|
case "available": return "AVAILABLE";
|
|
36
36
|
case "busy": return "ON_DELIVERY";
|
|
@@ -39,7 +39,7 @@ function C(e) {
|
|
|
39
39
|
default: return "OFF_DUTY";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function T(e) {
|
|
43
43
|
if (!e) return;
|
|
44
44
|
let t = e.lat, n = e.lng;
|
|
45
45
|
if (typeof t != "number" || typeof n != "number") return;
|
|
@@ -52,7 +52,7 @@ function w(e) {
|
|
|
52
52
|
timestamp: r ? new Date(r) : void 0
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function E(e) {
|
|
56
56
|
return {
|
|
57
57
|
id: e.id,
|
|
58
58
|
vehicleNumber: e.vehicleNumber,
|
|
@@ -67,10 +67,10 @@ function T(e) {
|
|
|
67
67
|
volume: typeof e.capacity?.volume == "number" ? e.capacity.volume : void 0,
|
|
68
68
|
pallets: typeof e.capacity?.pallets == "number" ? e.capacity.pallets : void 0
|
|
69
69
|
},
|
|
70
|
-
status:
|
|
70
|
+
status: x(e.status),
|
|
71
71
|
driverIds: (e.drivers ?? []).map((e) => e.id),
|
|
72
72
|
driverId: e.drivers?.[0]?.id,
|
|
73
|
-
currentLocation:
|
|
73
|
+
currentLocation: T(e.currentLocation),
|
|
74
74
|
lastMaintenance: e.lastServiceDate ? new Date(e.lastServiceDate) : void 0,
|
|
75
75
|
nextMaintenance: e.nextServiceDueDate ? new Date(e.nextServiceDueDate) : void 0,
|
|
76
76
|
nextMaintenanceMileage: e.nextServiceDueMileage ?? void 0,
|
|
@@ -82,7 +82,7 @@ function T(e) {
|
|
|
82
82
|
createdAt: new Date(e.createdAt)
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function D(e) {
|
|
86
86
|
return {
|
|
87
87
|
id: e.id,
|
|
88
88
|
userId: e.userId ?? e.id,
|
|
@@ -95,8 +95,8 @@ function E(e) {
|
|
|
95
95
|
licenseExpiry: e.licenseExpiry ? new Date(e.licenseExpiry) : void 0,
|
|
96
96
|
vehicleIds: e.vehicles && e.vehicles.length > 0 ? e.vehicles.map((e) => e.id) : e.vehicleId ? [e.vehicleId] : [],
|
|
97
97
|
assignedVehicle: e.vehicles?.[0]?.id ?? e.vehicleId ?? void 0,
|
|
98
|
-
status:
|
|
99
|
-
currentLocation:
|
|
98
|
+
status: C(e.status),
|
|
99
|
+
currentLocation: T(e.currentLocation),
|
|
100
100
|
rating: e.rating ?? void 0,
|
|
101
101
|
notes: e.notes ?? void 0,
|
|
102
102
|
hireDate: e.hireDate ? new Date(e.hireDate) : void 0,
|
|
@@ -110,7 +110,7 @@ function E(e) {
|
|
|
110
110
|
createdAt: new Date(e.createdAt)
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function O() {
|
|
114
114
|
let { apiGatewayUrl: t, authToken: n, workspaceToken: r, workspaceId: a, tenantId: o, currentUser: s } = e();
|
|
115
115
|
return i(() => ({
|
|
116
116
|
apiGatewayUrl: t,
|
|
@@ -128,62 +128,62 @@ function D() {
|
|
|
128
128
|
s?.id
|
|
129
129
|
]);
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
let { filters: c, limit: l = 20 } = e,
|
|
131
|
+
function k(e = {}) {
|
|
132
|
+
let { filters: c, limit: l = 20 } = e, f = i(() => c, [
|
|
133
133
|
c?.driverId,
|
|
134
134
|
c?.search,
|
|
135
135
|
c?.status,
|
|
136
136
|
c?.vehicleId,
|
|
137
137
|
c?.vehicleType
|
|
138
|
-
]),
|
|
139
|
-
|
|
138
|
+
]), p = O(), [m, y] = a([]), [b, x] = a([]), [C, w] = a(0), [T, k] = a(0), [A, j] = a(!1), [M, N] = a(null), P = n(async () => {
|
|
139
|
+
j(!0), N(null);
|
|
140
140
|
try {
|
|
141
|
-
let [e, n] = await Promise.all([t(
|
|
141
|
+
let [e, n] = await Promise.all([t(p, o, {
|
|
142
142
|
filter: {
|
|
143
|
-
search:
|
|
144
|
-
type:
|
|
145
|
-
status:
|
|
146
|
-
driverId:
|
|
143
|
+
search: f?.search,
|
|
144
|
+
type: f?.vehicleType?.toUpperCase(),
|
|
145
|
+
status: f?.status ? S(f.status) : void 0,
|
|
146
|
+
driverId: f?.driverId
|
|
147
147
|
},
|
|
148
148
|
pagination: {
|
|
149
149
|
limit: l,
|
|
150
150
|
offset: 0
|
|
151
151
|
}
|
|
152
|
-
}), t(
|
|
152
|
+
}), t(p, s, {
|
|
153
153
|
filter: {
|
|
154
|
-
search:
|
|
155
|
-
vehicleId:
|
|
154
|
+
search: f?.search,
|
|
155
|
+
vehicleId: f?.vehicleId
|
|
156
156
|
},
|
|
157
157
|
pagination: {
|
|
158
158
|
limit: l,
|
|
159
159
|
offset: 0
|
|
160
160
|
}
|
|
161
161
|
})]);
|
|
162
|
-
|
|
162
|
+
y(e.vehicles.map(E)), x(n.drivers.map(D)), w(e.vehiclesCount), k(n.driversCount);
|
|
163
163
|
} catch (e) {
|
|
164
|
-
|
|
164
|
+
N(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load fleet data"));
|
|
165
165
|
} finally {
|
|
166
|
-
|
|
166
|
+
j(!1);
|
|
167
167
|
}
|
|
168
168
|
}, [
|
|
169
|
-
d,
|
|
170
169
|
f,
|
|
170
|
+
p,
|
|
171
171
|
l
|
|
172
172
|
]);
|
|
173
173
|
return r(() => {
|
|
174
|
-
|
|
175
|
-
}, [
|
|
176
|
-
vehicles:
|
|
177
|
-
drivers:
|
|
178
|
-
totalVehicles:
|
|
179
|
-
totalDrivers:
|
|
180
|
-
isLoading:
|
|
181
|
-
error:
|
|
174
|
+
P();
|
|
175
|
+
}, [P]), {
|
|
176
|
+
vehicles: m,
|
|
177
|
+
drivers: b,
|
|
178
|
+
totalVehicles: C,
|
|
179
|
+
totalDrivers: T,
|
|
180
|
+
isLoading: A,
|
|
181
|
+
error: M,
|
|
182
182
|
refetch: n(() => {
|
|
183
|
-
|
|
184
|
-
}, [
|
|
183
|
+
P();
|
|
184
|
+
}, [P]),
|
|
185
185
|
createVehicle: n(async (e) => {
|
|
186
|
-
let n =
|
|
186
|
+
let n = E((await t(p, h, { input: {
|
|
187
187
|
vehicleNumber: e.vehicleNumber,
|
|
188
188
|
type: e.type,
|
|
189
189
|
make: e.make,
|
|
@@ -196,10 +196,10 @@ function O(e = {}) {
|
|
|
196
196
|
fuelEfficiencyLPer100Km: e.fuelEfficiencyLPer100Km,
|
|
197
197
|
capacity: e.capacity
|
|
198
198
|
} })).createVehicle);
|
|
199
|
-
return
|
|
200
|
-
}, [
|
|
199
|
+
return y((e) => [n, ...e]), n;
|
|
200
|
+
}, [p]),
|
|
201
201
|
createDriver: n(async (e) => {
|
|
202
|
-
let n =
|
|
202
|
+
let n = D((await t(p, g, { input: {
|
|
203
203
|
employeeId: e.employeeId,
|
|
204
204
|
firstName: e.firstName,
|
|
205
205
|
lastName: e.lastName,
|
|
@@ -218,10 +218,10 @@ function O(e = {}) {
|
|
|
218
218
|
bonusYtd: e.bonusYtd,
|
|
219
219
|
payCurrency: e.payCurrency
|
|
220
220
|
} })).createDriver);
|
|
221
|
-
return
|
|
222
|
-
}, [
|
|
221
|
+
return x((e) => [n, ...e]), n;
|
|
222
|
+
}, [p]),
|
|
223
223
|
updateVehicle: n(async (e, n) => {
|
|
224
|
-
let r =
|
|
224
|
+
let r = E((await t(p, _, {
|
|
225
225
|
id: e,
|
|
226
226
|
input: {
|
|
227
227
|
vehicleNumber: n.vehicleNumber,
|
|
@@ -237,10 +237,10 @@ function O(e = {}) {
|
|
|
237
237
|
capacity: n.capacity
|
|
238
238
|
}
|
|
239
239
|
})).updateVehicle);
|
|
240
|
-
return
|
|
241
|
-
}, [
|
|
240
|
+
return y((t) => t.map((t) => t.id === e ? r : t)), r;
|
|
241
|
+
}, [p]),
|
|
242
242
|
updateDriver: n(async (e, n) => {
|
|
243
|
-
let r =
|
|
243
|
+
let r = D((await t(p, v, {
|
|
244
244
|
id: e,
|
|
245
245
|
input: {
|
|
246
246
|
firstName: n.firstName,
|
|
@@ -264,25 +264,28 @@ function O(e = {}) {
|
|
|
264
264
|
terminationReason: n.terminationReason
|
|
265
265
|
}
|
|
266
266
|
})).updateDriver);
|
|
267
|
-
return
|
|
268
|
-
}, [
|
|
267
|
+
return x((t) => t.map((t) => t.id === e ? r : t)), r;
|
|
268
|
+
}, [p]),
|
|
269
269
|
deleteVehicle: n(async (e) => {
|
|
270
|
-
await t(
|
|
271
|
-
}, [
|
|
270
|
+
await t(p, d, { id: e }), y((t) => t.filter((t) => t.id !== e));
|
|
271
|
+
}, [p]),
|
|
272
|
+
deleteDriver: n(async (e) => {
|
|
273
|
+
await t(p, u, { id: e }), x((t) => t.filter((t) => t.id !== e));
|
|
274
|
+
}, [p])
|
|
272
275
|
};
|
|
273
276
|
}
|
|
274
|
-
function
|
|
275
|
-
let { limit: s = 20, offset: l = 0, search:
|
|
277
|
+
function A(e = {}) {
|
|
278
|
+
let { limit: s = 20, offset: l = 0, search: u, status: m, vehicleType: h, driverId: g, ids: _ } = e, v = O(), [y, b] = a([]), [x, C] = a(0), [w, T] = a(!1), [D, k] = a(!1), [A, j] = a(!1), [M, N] = a(null), P = _ ? [..._].sort().join(",") : "", F = _ === void 0 ? "none" : "exact", I = i(() => P ? P.split(",") : [], [P]), L = n(async () => {
|
|
276
279
|
if (F === "exact" && I.length === 0) {
|
|
277
|
-
b([]), C(0),
|
|
280
|
+
b([]), C(0), T(!1);
|
|
278
281
|
return;
|
|
279
282
|
}
|
|
280
283
|
k(!0), N(null);
|
|
281
284
|
try {
|
|
282
285
|
let e = await t(v, o, {
|
|
283
286
|
filter: {
|
|
284
|
-
search:
|
|
285
|
-
status: m ?
|
|
287
|
+
search: u || void 0,
|
|
288
|
+
status: m ? S(m) : void 0,
|
|
286
289
|
type: h?.toUpperCase(),
|
|
287
290
|
driverId: g || void 0,
|
|
288
291
|
ids: I.length > 0 ? I : void 0
|
|
@@ -292,7 +295,7 @@ function k(e = {}) {
|
|
|
292
295
|
offset: F === "exact" ? 0 : l
|
|
293
296
|
}
|
|
294
297
|
});
|
|
295
|
-
|
|
298
|
+
T(F === "none" && l + e.vehicles.length < e.vehiclesCount), C(e.vehiclesCount), b(e.vehicles.map(E));
|
|
296
299
|
} catch (e) {
|
|
297
300
|
N(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load vehicles"));
|
|
298
301
|
} finally {
|
|
@@ -302,21 +305,21 @@ function k(e = {}) {
|
|
|
302
305
|
v,
|
|
303
306
|
s,
|
|
304
307
|
l,
|
|
305
|
-
|
|
308
|
+
u,
|
|
306
309
|
m,
|
|
307
310
|
h,
|
|
308
311
|
g,
|
|
309
312
|
F,
|
|
310
313
|
I
|
|
311
314
|
]), R = n(async () => {
|
|
312
|
-
if (F === "exact" || !w ||
|
|
315
|
+
if (F === "exact" || !w || D || A) return;
|
|
313
316
|
let e = l + y.length;
|
|
314
317
|
j(!0), N(null);
|
|
315
318
|
try {
|
|
316
319
|
let n = await t(v, o, {
|
|
317
320
|
filter: {
|
|
318
|
-
search:
|
|
319
|
-
status: m ?
|
|
321
|
+
search: u || void 0,
|
|
322
|
+
status: m ? S(m) : void 0,
|
|
320
323
|
type: h?.toUpperCase(),
|
|
321
324
|
driverId: g || void 0
|
|
322
325
|
},
|
|
@@ -324,8 +327,8 @@ function k(e = {}) {
|
|
|
324
327
|
limit: s,
|
|
325
328
|
offset: e
|
|
326
329
|
}
|
|
327
|
-
}), r = n.vehicles.map(
|
|
328
|
-
C(n.vehiclesCount),
|
|
330
|
+
}), r = n.vehicles.map(E);
|
|
331
|
+
C(n.vehiclesCount), T(e + r.length < n.vehiclesCount), b((e) => {
|
|
329
332
|
let t = new Set(e.map((e) => e.id));
|
|
330
333
|
return [...e, ...r.filter((e) => !t.has(e.id))];
|
|
331
334
|
});
|
|
@@ -339,11 +342,11 @@ function k(e = {}) {
|
|
|
339
342
|
v,
|
|
340
343
|
w,
|
|
341
344
|
F,
|
|
342
|
-
|
|
345
|
+
D,
|
|
343
346
|
A,
|
|
344
347
|
s,
|
|
345
348
|
l,
|
|
346
|
-
|
|
349
|
+
u,
|
|
347
350
|
m,
|
|
348
351
|
h,
|
|
349
352
|
y.length
|
|
@@ -352,9 +355,9 @@ function k(e = {}) {
|
|
|
352
355
|
L();
|
|
353
356
|
}, [L]), {
|
|
354
357
|
vehicles: y,
|
|
355
|
-
totalVehicles:
|
|
358
|
+
totalVehicles: x,
|
|
356
359
|
hasMore: w,
|
|
357
|
-
isLoading:
|
|
360
|
+
isLoading: D,
|
|
358
361
|
isLoadingMore: A,
|
|
359
362
|
error: M,
|
|
360
363
|
refetch: n(() => {
|
|
@@ -362,29 +365,29 @@ function k(e = {}) {
|
|
|
362
365
|
}, [L]),
|
|
363
366
|
loadMore: R,
|
|
364
367
|
updateVehicleStatus: n(async (e, n) => {
|
|
365
|
-
let r =
|
|
368
|
+
let r = E((await t(v, f, {
|
|
366
369
|
id: e,
|
|
367
|
-
status:
|
|
370
|
+
status: S(n)
|
|
368
371
|
})).updateVehicleStatus);
|
|
369
372
|
return b((t) => t.map((t) => t.id === e ? r : t)), r;
|
|
370
373
|
}, [v]),
|
|
371
374
|
assignDriver: n(async (e, n) => {
|
|
372
|
-
await t(v,
|
|
375
|
+
await t(v, p, {
|
|
373
376
|
id: n,
|
|
374
377
|
vehicleId: e
|
|
375
378
|
});
|
|
376
379
|
let r = await t(v, c, { id: e });
|
|
377
380
|
if (!r.vehicle) throw Error("Vehicle not found");
|
|
378
|
-
let i =
|
|
381
|
+
let i = E(r.vehicle);
|
|
379
382
|
return b((t) => t.map((t) => t.id === e ? i : t)), i;
|
|
380
383
|
}, [v]),
|
|
381
384
|
deleteVehicle: n(async (e) => {
|
|
382
|
-
await t(v,
|
|
385
|
+
await t(v, d, { id: e }), b((t) => t.filter((t) => t.id !== e));
|
|
383
386
|
}, [v])
|
|
384
387
|
};
|
|
385
388
|
}
|
|
386
|
-
function
|
|
387
|
-
let i =
|
|
389
|
+
function j(e) {
|
|
390
|
+
let i = O(), [o, s] = a(null), [l, u] = a(!1), [d, f] = a(null), p = n(async () => {
|
|
388
391
|
if (!e) {
|
|
389
392
|
s(null);
|
|
390
393
|
return;
|
|
@@ -392,7 +395,7 @@ function A(e) {
|
|
|
392
395
|
u(!0), f(null);
|
|
393
396
|
try {
|
|
394
397
|
let n = await t(i, c, { id: e });
|
|
395
|
-
s(n.vehicle ?
|
|
398
|
+
s(n.vehicle ? E(n.vehicle) : null);
|
|
396
399
|
} catch (e) {
|
|
397
400
|
f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load vehicle"));
|
|
398
401
|
} finally {
|
|
@@ -410,13 +413,13 @@ function A(e) {
|
|
|
410
413
|
}, [p])
|
|
411
414
|
};
|
|
412
415
|
}
|
|
413
|
-
function
|
|
414
|
-
let { limit: i = 20, offset: o = 0, status: c, search: l, licenseClass: u, vehicleId: d } = e,
|
|
416
|
+
function M(e = {}) {
|
|
417
|
+
let { limit: i = 20, offset: o = 0, status: c, search: l, licenseClass: u, vehicleId: d } = e, f = O(), [h, g] = a([]), [_, v] = a(0), [y, b] = a(!1), [x, S] = a(!1), [C, T] = a(!1), [E, k] = a(null), A = n(async () => {
|
|
415
418
|
S(!0), k(null);
|
|
416
419
|
try {
|
|
417
|
-
let e = await t(
|
|
420
|
+
let e = await t(f, s, {
|
|
418
421
|
filter: {
|
|
419
|
-
status: c ?
|
|
422
|
+
status: c ? w(c) : void 0,
|
|
420
423
|
search: l || void 0,
|
|
421
424
|
licenseClass: u || void 0,
|
|
422
425
|
vehicleId: d || void 0
|
|
@@ -426,14 +429,14 @@ function j(e = {}) {
|
|
|
426
429
|
offset: o
|
|
427
430
|
}
|
|
428
431
|
});
|
|
429
|
-
b(o + e.drivers.length < e.driversCount), v(e.driversCount), g(e.drivers.map(
|
|
432
|
+
b(o + e.drivers.length < e.driversCount), v(e.driversCount), g(e.drivers.map(D));
|
|
430
433
|
} catch (e) {
|
|
431
434
|
k(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load drivers"));
|
|
432
435
|
} finally {
|
|
433
436
|
S(!1);
|
|
434
437
|
}
|
|
435
438
|
}, [
|
|
436
|
-
|
|
439
|
+
f,
|
|
437
440
|
i,
|
|
438
441
|
o,
|
|
439
442
|
c,
|
|
@@ -441,13 +444,13 @@ function j(e = {}) {
|
|
|
441
444
|
u,
|
|
442
445
|
d
|
|
443
446
|
]), j = n(async () => {
|
|
444
|
-
if (!y || x ||
|
|
447
|
+
if (!y || x || C) return;
|
|
445
448
|
let e = o + h.length;
|
|
446
449
|
T(!0), k(null);
|
|
447
450
|
try {
|
|
448
|
-
let n = await t(
|
|
451
|
+
let n = await t(f, s, {
|
|
449
452
|
filter: {
|
|
450
|
-
status: c ?
|
|
453
|
+
status: c ? w(c) : void 0,
|
|
451
454
|
search: l || void 0,
|
|
452
455
|
licenseClass: u || void 0,
|
|
453
456
|
vehicleId: d || void 0
|
|
@@ -456,7 +459,7 @@ function j(e = {}) {
|
|
|
456
459
|
limit: i,
|
|
457
460
|
offset: e
|
|
458
461
|
}
|
|
459
|
-
}), r = n.drivers.map(
|
|
462
|
+
}), r = n.drivers.map(D);
|
|
460
463
|
v(n.driversCount), b(e + r.length < n.driversCount), g((e) => {
|
|
461
464
|
let t = new Set(e.map((e) => e.id));
|
|
462
465
|
return [...e, ...r.filter((e) => !t.has(e.id))];
|
|
@@ -468,10 +471,10 @@ function j(e = {}) {
|
|
|
468
471
|
}
|
|
469
472
|
}, [
|
|
470
473
|
h.length,
|
|
471
|
-
|
|
474
|
+
f,
|
|
472
475
|
y,
|
|
473
476
|
x,
|
|
474
|
-
|
|
477
|
+
C,
|
|
475
478
|
i,
|
|
476
479
|
u,
|
|
477
480
|
o,
|
|
@@ -486,30 +489,30 @@ function j(e = {}) {
|
|
|
486
489
|
totalDrivers: _,
|
|
487
490
|
hasMore: y,
|
|
488
491
|
isLoading: x,
|
|
489
|
-
isLoadingMore:
|
|
490
|
-
error:
|
|
492
|
+
isLoadingMore: C,
|
|
493
|
+
error: E,
|
|
491
494
|
refetch: n(() => {
|
|
492
495
|
A();
|
|
493
496
|
}, [A]),
|
|
494
497
|
loadMore: j,
|
|
495
498
|
updateDriverStatus: n(async (e, n) => {
|
|
496
|
-
let r =
|
|
499
|
+
let r = D((await t(f, m, {
|
|
497
500
|
id: e,
|
|
498
|
-
status:
|
|
501
|
+
status: w(n)
|
|
499
502
|
})).updateDriverStatus);
|
|
500
503
|
return g((t) => t.map((t) => t.id === e ? r : t)), r;
|
|
501
|
-
}, [
|
|
504
|
+
}, [f]),
|
|
502
505
|
assignVehicle: n(async (e, n) => {
|
|
503
|
-
let r =
|
|
506
|
+
let r = D((await t(f, p, {
|
|
504
507
|
id: e,
|
|
505
508
|
vehicleId: n
|
|
506
509
|
})).assignDriverVehicle);
|
|
507
510
|
return g((t) => t.map((t) => t.id === e ? r : t)), r;
|
|
508
|
-
}, [
|
|
511
|
+
}, [f])
|
|
509
512
|
};
|
|
510
513
|
}
|
|
511
|
-
function
|
|
512
|
-
let i =
|
|
514
|
+
function N(e) {
|
|
515
|
+
let i = O(), [o, s] = a(null), [c, u] = a(!1), [d, f] = a(null), p = n(async () => {
|
|
513
516
|
if (!e) {
|
|
514
517
|
s(null);
|
|
515
518
|
return;
|
|
@@ -517,7 +520,7 @@ function M(e) {
|
|
|
517
520
|
u(!0), f(null);
|
|
518
521
|
try {
|
|
519
522
|
let n = await t(i, l, { id: e });
|
|
520
|
-
s(n.driver ?
|
|
523
|
+
s(n.driver ? D(n.driver) : null);
|
|
521
524
|
} catch (e) {
|
|
522
525
|
f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load driver"));
|
|
523
526
|
} finally {
|
|
@@ -535,15 +538,15 @@ function M(e) {
|
|
|
535
538
|
}, [p])
|
|
536
539
|
};
|
|
537
540
|
}
|
|
538
|
-
function
|
|
539
|
-
let e =
|
|
541
|
+
function P() {
|
|
542
|
+
let e = O(), [i, o] = a({
|
|
540
543
|
onBreak: 0,
|
|
541
544
|
offDuty: 0,
|
|
542
545
|
inactive: 0
|
|
543
546
|
}), [s, c] = a(!1), [l, u] = a(null), d = n(async () => {
|
|
544
547
|
c(!0), u(null);
|
|
545
548
|
try {
|
|
546
|
-
let n = await t(e,
|
|
549
|
+
let n = await t(e, y);
|
|
547
550
|
o({
|
|
548
551
|
onBreak: n.onBreak,
|
|
549
552
|
offDuty: n.offDuty,
|
|
@@ -566,8 +569,8 @@ function N() {
|
|
|
566
569
|
}, [d])
|
|
567
570
|
};
|
|
568
571
|
}
|
|
569
|
-
function
|
|
570
|
-
let i =
|
|
572
|
+
function F(e) {
|
|
573
|
+
let i = O(), [o, c] = a([]), [l, u] = a(!1), [d, f] = a(null), p = n(async () => {
|
|
571
574
|
if (!e) {
|
|
572
575
|
c([]);
|
|
573
576
|
return;
|
|
@@ -580,7 +583,7 @@ function P(e) {
|
|
|
580
583
|
limit: 25,
|
|
581
584
|
offset: 0
|
|
582
585
|
}
|
|
583
|
-
})).drivers.map(
|
|
586
|
+
})).drivers.map(D));
|
|
584
587
|
} catch (e) {
|
|
585
588
|
f(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load assigned driver"));
|
|
586
589
|
} finally {
|
|
@@ -598,8 +601,8 @@ function P(e) {
|
|
|
598
601
|
}, [p])
|
|
599
602
|
};
|
|
600
603
|
}
|
|
601
|
-
function
|
|
602
|
-
let e =
|
|
604
|
+
function I() {
|
|
605
|
+
let e = O(), [i, o] = a({
|
|
603
606
|
totalVehicles: 0,
|
|
604
607
|
totalDrivers: 0,
|
|
605
608
|
vehiclesByStatus: {
|
|
@@ -620,7 +623,7 @@ function F() {
|
|
|
620
623
|
}), [s, c] = a(!1), [l, u] = a(null), d = n(async () => {
|
|
621
624
|
c(!0), u(null);
|
|
622
625
|
try {
|
|
623
|
-
let n = await t(e,
|
|
626
|
+
let n = await t(e, b);
|
|
624
627
|
o({
|
|
625
628
|
totalVehicles: n.fleetStats.totalVehicles,
|
|
626
629
|
totalDrivers: n.fleetStats.totalDrivers,
|
|
@@ -658,4 +661,4 @@ function F() {
|
|
|
658
661
|
};
|
|
659
662
|
}
|
|
660
663
|
//#endregion
|
|
661
|
-
export {
|
|
664
|
+
export { D as mapDriver, E as mapVehicle, w as toApiDriverStatus, S as toApiVehicleStatus, N as useDriver, P as useDriverStatusCounts, M as useDrivers, k as useFleet, I as useFleetStats, j as useVehicle, F as useVehicleDrivers, A as useVehicles };
|
|
@@ -64,6 +64,7 @@ interface UseFleetResult {
|
|
|
64
64
|
updateVehicle: (id: string, input: CreateVehicleInput) => Promise<Vehicle>;
|
|
65
65
|
updateDriver: (id: string, input: UpdateDriverInput) => Promise<Driver>;
|
|
66
66
|
deleteVehicle: (id: string) => Promise<void>;
|
|
67
|
+
deleteDriver: (id: string) => Promise<void>;
|
|
67
68
|
}
|
|
68
69
|
export interface ApiVehicle {
|
|
69
70
|
id: string;
|