You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/edge/edge-devices/open-amt/useActivateDevicesMutation.ts

23 lines
808 B

import { useMutation } from 'react-query';
import { promiseSequence } from '@/portainer/helpers/promise-utils';
import { mutationOptions, withError } from '@/react-tools/react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import axios, { parseAxiosError } from '@/portainer/services/axios';
export function useActivateDevicesMutation() {
return useMutation(
(environmentIds: EnvironmentId[]) =>
promiseSequence(environmentIds.map((id) => () => activateDevice(id))),
mutationOptions(withError('Unable to associate with OpenAMT'))
);
}
async function activateDevice(environmentId: EnvironmentId) {
try {
await axios.post(`/open_amt/${environmentId}/activate`);
} catch (e) {
throw parseAxiosError(e as Error, 'Unable to activate device');
}
}