signal-desktop/ts/state/smart/ContactName.tsx
Jamie Kyle 27b55e472d
Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
2024-03-13 13:44:13 -07:00

39 lines
1.2 KiB
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import { ContactName } from '../../components/conversation/ContactName';
import { getIntl } from '../selectors/user';
import {
getConversationSelector,
getSelectedConversationId,
} from '../selectors/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
type ExternalProps = {
contactId: string;
};
export const SmartContactName = memo(function SmartContactName(
props: ExternalProps
) {
const { contactId } = props;
const i18n = useSelector(getIntl);
const getConversation = useSelector(getConversationSelector);
const contact = getConversation(contactId) || {
title: i18n('icu:unknownContact'),
};
const currentConversationId = useSelector(getSelectedConversationId);
const currentConversation = getConversation(currentConversationId);
const { showContactModal } = useGlobalModalActions();
return (
<ContactName
firstName={contact.firstName}
title={contact.title}
onClick={() => showContactModal(contact.id, currentConversation.id)}
/>
);
});