RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/views/omnichannel/currentChats/hooks/useRemoveCurrentChatMutation.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { IRoom } from '@rocket.chat/core-typings';
import { useMethod } from '@rocket.chat/ui-contexts';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useQueryClient, useMutation } from '@tanstack/react-query';

export const useRemoveCurrentChatMutation = (
    options?: Omit<UseMutationOptions<void, Error, IRoom['_id']>, 'mutationFn'>,
): UseMutationResult<void, Error, IRoom['_id']> => {
    const removeRoom = useMethod('livechat:removeRoom');
    const queryClient = useQueryClient();

    return useMutation((rid) => removeRoom(rid), {
        ...options,
        onSuccess: (...args) => {
            queryClient.invalidateQueries(['current-chats']);
            options?.onSuccess?.(...args);
        },
    });
};