2018-05-03 02:43:23 +00:00
|
|
|
import React from 'react';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2018-05-07 22:44:19 +00:00
|
|
|
import { Contact, getName } from '../../types/Contact';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
import { Localizer } from '../../types/Util';
|
|
|
|
|
2018-05-03 02:43:23 +00:00
|
|
|
interface Props {
|
|
|
|
contact: Contact;
|
|
|
|
hasSignalAccount: boolean;
|
2018-05-22 19:31:43 +00:00
|
|
|
i18n: Localizer;
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming: boolean;
|
|
|
|
withContentAbove: boolean;
|
|
|
|
withContentBelow: boolean;
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick?: () => void;
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
export class EmbeddedContact extends React.Component<Props> {
|
2018-05-08 00:51:29 +00:00
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
contact,
|
|
|
|
i18n,
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming,
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick,
|
2018-06-27 20:53:49 +00:00
|
|
|
withContentAbove,
|
|
|
|
withContentBelow,
|
2018-05-08 00:51:29 +00:00
|
|
|
} = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
const module = 'embedded-contact';
|
2018-05-08 00:51:29 +00:00
|
|
|
|
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-embedded-contact',
|
|
|
|
withContentAbove
|
|
|
|
? 'module-embedded-contact--with-content-above'
|
|
|
|
: null,
|
|
|
|
withContentBelow
|
|
|
|
? 'module-embedded-contact--with-content-below'
|
|
|
|
: null
|
|
|
|
)}
|
|
|
|
role="button"
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick={onClick}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
|
|
|
{renderAvatar({ contact, i18n, module })}
|
|
|
|
<div className="module-embedded-contact__text-container">
|
|
|
|
{renderName({ contact, isIncoming, module })}
|
|
|
|
{renderContactShorthand({ contact, isIncoming, module })}
|
2018-05-08 00:51:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: putting these below the main component so style guide picks up EmbeddedContact
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
function getInitial(name: string): string {
|
2018-05-03 02:43:23 +00:00
|
|
|
return name.trim()[0] || '#';
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
export function renderAvatar({
|
|
|
|
contact,
|
|
|
|
i18n,
|
|
|
|
module,
|
|
|
|
}: {
|
|
|
|
contact: Contact;
|
|
|
|
i18n: Localizer;
|
|
|
|
module: string;
|
|
|
|
}) {
|
2018-05-08 00:51:29 +00:00
|
|
|
const { avatar } = contact;
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-05-08 00:51:29 +00:00
|
|
|
const path = avatar && avatar.avatar && avatar.avatar.path;
|
2018-06-27 20:53:49 +00:00
|
|
|
const name = getName(contact) || '';
|
|
|
|
|
2018-05-08 00:51:29 +00:00
|
|
|
if (!path) {
|
2018-06-27 20:53:49 +00:00
|
|
|
const initials = getInitial(name);
|
2018-05-22 19:31:43 +00:00
|
|
|
|
2018-05-03 02:43:23 +00:00
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className={`module-${module}__image-container`}>
|
|
|
|
<div className={`module-${module}__image-container__default-avatar`}>
|
|
|
|
{initials}
|
|
|
|
</div>
|
2018-05-03 02:43:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:51:29 +00:00
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className={`module-${module}__image-container`}>
|
|
|
|
<img src={path} alt={i18n('contactAvatarAlt', [name])} />
|
2018-05-08 00:51:29 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
export function renderName({
|
|
|
|
contact,
|
|
|
|
isIncoming,
|
|
|
|
module,
|
|
|
|
}: {
|
|
|
|
contact: Contact;
|
|
|
|
isIncoming: boolean;
|
|
|
|
module: string;
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
`module-${module}__contact-name`,
|
|
|
|
isIncoming ? `module-${module}__contact-name--incoming` : null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{getName(contact)}
|
|
|
|
</div>
|
|
|
|
);
|
2018-05-08 00:51:29 +00:00
|
|
|
}
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-06-27 20:53:49 +00:00
|
|
|
export function renderContactShorthand({
|
|
|
|
contact,
|
|
|
|
isIncoming,
|
|
|
|
module,
|
|
|
|
}: {
|
|
|
|
contact: Contact;
|
|
|
|
isIncoming: boolean;
|
|
|
|
module: string;
|
|
|
|
}) {
|
2018-05-08 00:51:29 +00:00
|
|
|
const { number: phoneNumber, email } = contact;
|
|
|
|
const firstNumber = phoneNumber && phoneNumber[0] && phoneNumber[0].value;
|
|
|
|
const firstEmail = email && email[0] && email[0].value;
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-05-08 00:51:29 +00:00
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
`module-${module}__contact-method`,
|
|
|
|
isIncoming ? `module-${module}__contact-method--incoming` : null
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{firstNumber || firstEmail}
|
2018-05-08 00:51:29 +00:00
|
|
|
</div>
|
|
|
|
);
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|