feat(useAuthenticateApp): use REST API endpoint to reset connection

This commit is contained in:
Ali BARIN
2024-09-24 11:40:35 +00:00
parent bc0e18d074
commit 5e6f4bfb88
4 changed files with 34 additions and 59 deletions

View File

@@ -11,6 +11,7 @@ import useAppAuth from './useAppAuth';
import useCreateConnection from './useCreateConnection';
import useCreateConnectionAuthUrl from './useCreateConnectionAuthUrl';
import useUpdateConnection from './useUpdateConnection';
import useResetConnection from './useResetConnection';
function getSteps(auth, hasConnection, useShared) {
if (hasConnection) {
@@ -33,6 +34,7 @@ export default function useAuthenticateApp(payload) {
const { mutateAsync: createConnection } = useCreateConnection(appKey);
const { mutateAsync: createConnectionAuthUrl } = useCreateConnectionAuthUrl();
const { mutateAsync: updateConnection } = useUpdateConnection();
const { mutateAsync: resetConnection } = useResetConnection();
const [authenticationInProgress, setAuthenticationInProgress] =
React.useState(false);
const formatMessage = useFormatMessage();
@@ -48,9 +50,7 @@ export default function useAuthenticateApp(payload) {
const response = {
key: appKey,
appAuthClientId: appAuthClientId || payload.appAuthClientId,
connection: {
id: connectionId,
},
connectionId,
fields,
};
let stepIndex = 0;
@@ -73,19 +73,24 @@ export default function useAuthenticateApp(payload) {
if (step.type === 'mutation') {
if (step.name === 'createConnection') {
const stepResponse = await createConnection(variables);
response[step.name] = stepResponse?.data;
response[step.name] = stepResponse.data;
response.connectionId = stepResponse.data.id;
} else if (step.name === 'generateAuthUrl') {
const stepResponse = await createConnectionAuthUrl(
response.createConnection.id,
response.connectionId,
);
response[step.name] = stepResponse?.data;
response[step.name] = stepResponse.data;
} else if (step.name === 'updateConnection') {
const stepResponse = await updateConnection({
...variables,
connectionId: response.createConnection.id,
connectionId: response.connectionId,
});
response[step.name] = stepResponse?.data;
response[step.name] = stepResponse.data;
} else if (step.name === 'resetConnection') {
const stepResponse = await resetConnection(response.connectionId);
response[step.name] = stepResponse.data;
} else {
const stepResponse = await processMutation(step.name, variables);
response[step.name] = stepResponse;
@@ -116,6 +121,7 @@ export default function useAuthenticateApp(payload) {
createConnection,
createConnectionAuthUrl,
updateConnection,
resetConnection,
]);
return {

View File

@@ -0,0 +1,15 @@
import { useMutation } from '@tanstack/react-query';
import api from 'helpers/api';
export default function useResetConnection() {
const query = useMutation({
mutationFn: async (connectionId) => {
const { data } = await api.post(`/v1/connections/${connectionId}/reset`);
return data;
},
});
return query;
}