signal-desktop/ts/state/smart/ContactName.tsx

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-09-08 19:25:05 -07:00
import * as React from 'react';
import { useSelector } from 'react-redux';
import type { StateType } from '../reducer';
2020-09-08 19:25:05 -07:00
import { ContactName } from '../../components/conversation/ContactName';
import { getIntl } from '../selectors/user';
import type { GetConversationByIdType } from '../selectors/conversations';
import {
getConversationSelector,
getSelectedConversationId,
} from '../selectors/conversations';
2020-09-08 19:25:05 -07:00
import type { LocalizerType } from '../../types/Util';
import { useGlobalModalActions } from '../ducks/globalModals';
2020-09-08 19:25:05 -07:00
type ExternalProps = {
contactId: string;
2020-09-08 19:25:05 -07:00
};
2022-11-17 16:45:19 -08:00
export function SmartContactName(props: ExternalProps): JSX.Element {
const { contactId } = props;
2020-09-08 19:25:05 -07:00
const i18n = useSelector<StateType, LocalizerType>(getIntl);
const getConversation = useSelector<StateType, GetConversationByIdType>(
getConversationSelector
);
const contact = getConversation(contactId) || {
2023-03-29 17:03:25 -07:00
title: i18n('icu:unknownContact'),
};
const currentConversationId = useSelector(getSelectedConversationId);
const currentConversation = getConversation(currentConversationId);
const { showContactModal } = useGlobalModalActions();
2020-09-08 19:25:05 -07:00
2021-05-28 12:15:17 -04:00
return (
<ContactName
firstName={contact.firstName}
title={contact.title}
onClick={() => showContactModal(contact.id, currentConversation.id)}
2021-05-28 12:15:17 -04:00
/>
);
2022-11-17 16:45:19 -08:00
}