// Copyright 2018 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import type { EmbeddedContactType, Email, Phone, PostalAddress, } from '../../types/EmbeddedContact'; import { AddressType, ContactFormType } from '../../types/EmbeddedContact'; import { missingCaseError } from '../../util/missingCaseError'; import { renderAvatar, renderContactShorthand, renderName, } from './contactUtil'; import type { LocalizerType } from '../../types/Util'; export type Props = { contact: EmbeddedContactType; hasSignalAccount: boolean; i18n: LocalizerType; onSendMessage: () => void; }; function getLabelForEmail(method: Email, i18n: LocalizerType): string { switch (method.type) { case ContactFormType.CUSTOM: return method.label || i18n('icu:email'); case ContactFormType.HOME: return i18n('icu:home'); case ContactFormType.MOBILE: return i18n('icu:mobile'); case ContactFormType.WORK: return i18n('icu:work'); default: throw missingCaseError(method.type); } } function getLabelForPhone(method: Phone, i18n: LocalizerType): string { switch (method.type) { case ContactFormType.CUSTOM: return method.label || i18n('icu:phone'); case ContactFormType.HOME: return i18n('icu:home'); case ContactFormType.MOBILE: return i18n('icu:mobile'); case ContactFormType.WORK: return i18n('icu:work'); default: throw missingCaseError(method.type); } } function getLabelForAddress( address: PostalAddress, i18n: LocalizerType ): string { switch (address.type) { case AddressType.CUSTOM: return address.label || i18n('icu:address'); case AddressType.HOME: return i18n('icu:home'); case AddressType.WORK: return i18n('icu:work'); default: throw missingCaseError(address.type); } } export function ContactDetail({ contact, hasSignalAccount, i18n, onSendMessage, }: Props): JSX.Element { // We don't want the overall click handler for this element to fire, so we stop // propagation before handing control to the caller's callback. const onClick = (e: React.MouseEvent): void => { e.stopPropagation(); onSendMessage(); }; const isIncoming = false; const module = 'contact-detail'; return (
{renderAvatar({ contact, i18n, size: 80 })}
{renderName({ contact, isIncoming, module })} {renderContactShorthand({ contact, isIncoming, module })} {hasSignalAccount && ( )} {contact.number?.map((phone: Phone) => { return (
{getLabelForPhone(phone, i18n)}
{phone.value}
); })} {contact.email?.map((email: Email) => { return (
{getLabelForEmail(email, i18n)}
{email.value}
); })} {contact.address?.map((address: PostalAddress, index: number) => { return (
{getLabelForAddress(address, i18n)}
{address.street &&
{address.street}
} {address.pobox && (
{i18n('icu:poBox')} {address.pobox}
)} {address.neighborhood &&
{address.neighborhood}
} {(address.city || address.region || address.postcode) && (
{address.city} {address.region} {address.postcode}
)} {address.country &&
{address.country}
}
); })}
); }