CEC-4594: add bulk actions to fleet (#368)
* CEC-4594: add bulk actions to fleet * add reject case
This commit is contained in:
40
src/components/BulkActions/useUpdateConfig.js
Normal file
40
src/components/BulkActions/useUpdateConfig.js
Normal 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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user