CEC-4595 - show online status of cars in fleet (#374)

* CEC-4595 - show online status of cars in fleet

* fix mocking
This commit is contained in:
Paul Adamsen
2023-06-26 11:55:38 -04:00
committed by GitHub
parent ff7b7abadf
commit 787bb12260
8 changed files with 79 additions and 126 deletions

View File

@@ -1,5 +1,6 @@
import React, { useContext, useState } from "react";
import api from "../../services/fleetsAPI";
import vehiclesAPI from "../../services/vehiclesAPI";
import { validateCANID, validateFilter, validateVIN } from "../../utils/validationSupplier";
const FleetContext = React.createContext();
@@ -112,7 +113,22 @@ export const FleetProvider = ({ children }) => {
throw new Error(`Get fleet vehicles error. ${result.message}`);
}
setFleetVehicles(result.data)
const connectionsResult = await vehiclesAPI.getConnections(result.data, token)
if (result.error) {
setFleetVehicles([])
throw new Error(`Get vehicles connections error. ${result.message}`);
}
var cars = []
result.data.forEach((vin) => {
cars.push({
vin: vin,
connected: connectionsResult[vin] || false,
connectedHMI: connectionsResult[`2:${vin}`] || false
})
})
setFleetVehicles(cars)
if (result.total) {
setTotalFleetVehicles(result.total);
}