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