feat: refactor verify connection mutation with the REST API endpoint

This commit is contained in:
kasia.oczkowska
2024-09-20 13:05:21 +01:00
committed by Ali BARIN
parent dc0273148c
commit 4d5fc50f1a
8 changed files with 37 additions and 92 deletions

View File

@@ -0,0 +1,28 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useVerifyConnection() {
const queryClient = useQueryClient();
const query = useMutation({
mutationFn: async (connectionId) => {
try {
const { data } = await api.post(
`/v1/connections/${connectionId}/verify`,
);
return data;
} catch {
throw new Error('Failed while verifying connection!');
}
},
onSuccess: (data) => {
const appKey = data?.data.key;
queryClient.invalidateQueries({
queryKey: ['apps', appKey, 'connections'],
});
},
});
return query;
}