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

feat(edge): show correct heartbeat and sync aeec changes [EE-2876] (#6769)

This commit is contained in:
Chaim Lev-Ari 2022-04-19 21:43:36 +03:00 committed by GitHub
parent 76d1b70644
commit e217ac7121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 1099 additions and 307 deletions

View file

@ -0,0 +1,33 @@
import { useMutation, useQueryClient } from 'react-query';
import { EnvironmentId } from '@/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');
}
}