Delete connection from frontend (#4880)

This PR:
- creates the query to delete a connection
- creates the hook that triggers the query
- triggers the hook function when clicking on remove + get back to
connection page

---------

Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
Thomas Trompette
2024-04-08 17:27:14 +02:00
committed by GitHub
parent 97f9fc3f81
commit d4a9a26069
6 changed files with 82 additions and 4 deletions

View File

@ -0,0 +1,9 @@
import { gql } from '@apollo/client';
export const DELETE_ONE_DATABASE_CONNECTION = gql`
mutation deleteServer($input: RemoteServerIdInput!) {
deleteOneRemoteServer(input: $input) {
id
}
}
`;

View File

@ -0,0 +1,36 @@
import { ApolloClient, useMutation } from '@apollo/client';
import { getOperationName } from '@apollo/client/utilities';
import { DELETE_ONE_DATABASE_CONNECTION } from '@/databases/graphql/mutations/deleteOneDatabaseConnection';
import { GET_MANY_DATABASE_CONNECTIONS } from '@/databases/graphql/queries/findManyDatabaseConnections';
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import {
DeleteServerMutation,
DeleteServerMutationVariables,
RemoteServerIdInput,
} from '~/generated-metadata/graphql';
export const useDeleteOneDatabaseConnection = () => {
const apolloMetadataClient = useApolloMetadataClient();
const [mutate] = useMutation<
DeleteServerMutation,
DeleteServerMutationVariables
>(DELETE_ONE_DATABASE_CONNECTION, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
const deleteOneDatabaseConnection = async (input: RemoteServerIdInput) => {
return await mutate({
variables: {
input,
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(GET_MANY_DATABASE_CONNECTIONS) ?? ''],
});
};
return {
deleteOneDatabaseConnection,
};
};