RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/sidebarv2/footer/voip/hooks/useOmnichannelContactLabel.ts

Summary

Maintainability
B
5 hrs
Test Coverage
import type { ICallerInfo } from '@rocket.chat/core-typings';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';

import { parseOutboundPhoneNumber } from '../../../../lib/voip/parseOutboundPhoneNumber';

export const useOmnichannelContactLabel = (caller: ICallerInfo): string => {
    const getContactBy = useEndpoint('GET', '/v1/omnichannel/contact.search');
    const phone = parseOutboundPhoneNumber(caller.callerId);

    const { data } = useQuery(['getContactsByPhone', phone], async () => getContactBy({ phone }).then(({ contact }) => contact), {
        enabled: !!phone,
    });

    return data?.name || caller.callerName || phone;
};