CEC-4594: add bulk actions to fleet (#368)

* CEC-4594: add bulk actions to fleet

* add reject case
This commit is contained in:
Tristan Timblin
2023-06-21 23:28:53 -04:00
committed by GitHub
parent 9972eed5dd
commit f73b5125a3
9 changed files with 281 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import { useState } from "react";
import TaskRunner from "../../utils/taskRunner";
import vehiclesAPI from "../../services/vehiclesAPI";
export default function useUpdateConfig() {
const [config, setConfig] = useState({
force: {
label: "Force Push",
type: "boolean",
value: false,
},
});
const submit = async (vins, token) => {
return new Promise((resolve, reject) => {
const taskRunner = new TaskRunner(5);
const task = (vin, isLast) => {
return async () => vehiclesAPI.updateConfig(vin, config.force.value, token)
.then((response) => {
if (isLast) {
if (response.error) {
reject(response);
}
resolve(response)
}
})
.catch((error) => reject(error));
}
vins.forEach((vin, index) => taskRunner.push(task(vin, index === vins.length - 1)));
});
}
return {
data: config,
setData: setConfig,
submit,
};
}