import React from 'react'; import { Contact, getName } from '../../types/Contact'; interface Props { contact: Contact; hasSignalAccount: boolean; i18n: (key: string, values?: Array) => string; onSendMessage: () => void; onOpenContact: () => void; } export class EmbeddedContact extends React.Component { public render() { const { contact, hasSignalAccount, i18n, onOpenContact, onSendMessage, } = this.props; return (
{renderAvatar(contact)}
{renderName(contact)} {renderContactShorthand(contact)}
{renderSendMessage({ hasSignalAccount, i18n, onSendMessage })}
); } } // Note: putting these below the main component so style guide picks up EmbeddedContact function getInitials(name: string): string { return name.trim()[0] || '#'; } export function renderAvatar(contact: Contact) { const { avatar } = contact; const path = avatar && avatar.avatar && avatar.avatar.path; if (!path) { const name = getName(contact); const initials = getInitials(name || ''); return (
{initials}
); } return (
); } export function renderName(contact: Contact) { return
{getName(contact)}
; } export function renderContactShorthand(contact: Contact) { const { number: phoneNumber, email } = contact; const firstNumber = phoneNumber && phoneNumber[0] && phoneNumber[0].value; const firstEmail = email && email[0] && email[0].value; return
{firstNumber || firstEmail}
; } export function renderSendMessage(props: { hasSignalAccount: boolean; i18n: (key: string, values?: Array) => string; onSendMessage: () => void; }) { const { hasSignalAccount, i18n, onSendMessage } = props; if (!hasSignalAccount) { return null; } // 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(); }; return (
); }