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:
@ -0,0 +1,9 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const DELETE_ONE_DATABASE_CONNECTION = gql`
|
||||
mutation deleteServer($input: RemoteServerIdInput!) {
|
||||
deleteOneRemoteServer(input: $input) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user