1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

refactor(edge): move edge codebase to react (#7781)

This commit is contained in:
Chaim Lev-Ari 2022-11-21 09:51:55 +02:00 committed by GitHub
parent 75f40fe485
commit 1e4c4e2616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 254 additions and 187 deletions

View file

@ -0,0 +1,33 @@
import { useMutation, useQueryClient } from 'react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { promiseSequence } from '@/portainer/helpers/promise-utils';
export function useAssociateDeviceMutation() {
const queryClient = useQueryClient();
return useMutation(
(ids: EnvironmentId[]) =>
promiseSequence(ids.map((id) => () => associateDevice(id))),
{
onSuccess: () => {
queryClient.invalidateQueries(['environments']);
},
meta: {
error: {
title: 'Failure',
message: 'Failed to associate devices',
},
},
}
);
}
async function associateDevice(environmentId: EnvironmentId) {
try {
await axios.post(`/endpoints/${environmentId}/edge/trust`);
} catch (e) {
throw parseAxiosError(e as Error, 'Failed to associate device');
}
}