2018-05-03 02:43:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2018-05-05 01:19:54 +00:00
|
|
|
import {
|
2018-05-08 00:51:29 +00:00
|
|
|
AddressType,
|
2018-05-05 01:19:54 +00:00
|
|
|
Contact,
|
|
|
|
ContactType,
|
|
|
|
Email,
|
2018-05-08 00:51:29 +00:00
|
|
|
Phone,
|
2018-05-05 01:19:54 +00:00
|
|
|
PostalAddress,
|
|
|
|
} from '../../types/Contact';
|
2018-05-03 02:43:23 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
|
|
|
|
2018-05-08 00:51:29 +00:00
|
|
|
import {
|
|
|
|
renderAvatar,
|
|
|
|
renderContactShorthand,
|
|
|
|
renderName,
|
|
|
|
renderSendMessage,
|
|
|
|
} from './EmbeddedContact';
|
|
|
|
|
2018-05-18 21:48:20 +00:00
|
|
|
import { Localizer } from '../../types/Util';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
contact: Contact;
|
|
|
|
hasSignalAccount: boolean;
|
|
|
|
i18n: Localizer;
|
|
|
|
onSendMessage: () => void;
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:52:51 +00:00
|
|
|
function getLabelForEmail(method: Email, i18n: Localizer): string {
|
2018-05-03 02:43:23 +00:00
|
|
|
switch (method.type) {
|
|
|
|
case ContactType.CUSTOM:
|
2018-05-08 23:52:51 +00:00
|
|
|
return method.label || i18n('email');
|
2018-05-03 02:43:23 +00:00
|
|
|
case ContactType.HOME:
|
|
|
|
return i18n('home');
|
|
|
|
case ContactType.MOBILE:
|
|
|
|
return i18n('mobile');
|
|
|
|
case ContactType.WORK:
|
|
|
|
return i18n('work');
|
|
|
|
default:
|
2018-05-08 23:52:51 +00:00
|
|
|
throw missingCaseError(method.type);
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 15:55:18 +00:00
|
|
|
function getLabelForPhone(method: Phone, i18n: Localizer): string {
|
2018-05-08 23:52:51 +00:00
|
|
|
switch (method.type) {
|
|
|
|
case ContactType.CUSTOM:
|
|
|
|
return method.label || i18n('phone');
|
|
|
|
case ContactType.HOME:
|
|
|
|
return i18n('home');
|
|
|
|
case ContactType.MOBILE:
|
|
|
|
return i18n('mobile');
|
|
|
|
case ContactType.WORK:
|
|
|
|
return i18n('work');
|
|
|
|
default:
|
|
|
|
throw missingCaseError(method.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLabelForAddress(address: PostalAddress, i18n: Localizer): string {
|
2018-05-03 02:43:23 +00:00
|
|
|
switch (address.type) {
|
|
|
|
case AddressType.CUSTOM:
|
2018-05-08 23:52:51 +00:00
|
|
|
return address.label || i18n('address');
|
2018-05-03 02:43:23 +00:00
|
|
|
case AddressType.HOME:
|
|
|
|
return i18n('home');
|
|
|
|
case AddressType.WORK:
|
|
|
|
return i18n('work');
|
|
|
|
default:
|
2018-05-08 23:52:51 +00:00
|
|
|
throw missingCaseError(address.type);
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
export class ContactDetail extends React.Component<Props> {
|
2018-05-08 23:52:51 +00:00
|
|
|
public renderEmail(items: Array<Email> | undefined, i18n: Localizer) {
|
|
|
|
if (!items || items.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return items.map((item: Email) => {
|
|
|
|
return (
|
|
|
|
<div key={item.value} className="additional-contact">
|
|
|
|
<div className="type">{getLabelForEmail(item, i18n)}</div>
|
|
|
|
{item.value}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderPhone(items: Array<Phone> | undefined, i18n: Localizer) {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!items || items.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:52:51 +00:00
|
|
|
return items.map((item: Phone) => {
|
2018-05-03 02:43:23 +00:00
|
|
|
return (
|
|
|
|
<div key={item.value} className="additional-contact">
|
2018-05-08 23:52:51 +00:00
|
|
|
<div className="type">{getLabelForPhone(item, i18n)}</div>
|
2018-05-03 02:43:23 +00:00
|
|
|
{item.value}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-08 16:54:28 +00:00
|
|
|
public renderAddressLine(value: string | undefined) {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div>{value}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderPOBox(poBox: string | undefined, i18n: Localizer) {
|
|
|
|
if (!poBox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{i18n('poBox')} {poBox}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAddressLineTwo(address: PostalAddress) {
|
|
|
|
if (address.city || address.region || address.postcode) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{address.city} {address.region} {address.postcode}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAddresses(
|
|
|
|
addresses: Array<PostalAddress> | undefined,
|
|
|
|
i18n: Localizer
|
|
|
|
) {
|
|
|
|
if (!addresses || addresses.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return addresses.map((address: PostalAddress, index: number) => {
|
|
|
|
return (
|
|
|
|
<div key={index} className="additional-contact">
|
|
|
|
<div className="type">{getLabelForAddress(address, i18n)}</div>
|
2018-05-08 16:54:28 +00:00
|
|
|
{this.renderAddressLine(address.street)}
|
2018-05-03 02:43:23 +00:00
|
|
|
{this.renderPOBox(address.pobox, i18n)}
|
2018-05-08 16:54:28 +00:00
|
|
|
{this.renderAddressLine(address.neighborhood)}
|
2018-05-03 02:43:23 +00:00
|
|
|
{this.renderAddressLineTwo(address)}
|
2018-05-08 16:54:28 +00:00
|
|
|
{this.renderAddressLine(address.country)}
|
2018-05-03 02:43:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2018-05-08 00:51:29 +00:00
|
|
|
const { contact, hasSignalAccount, i18n, onSendMessage } = this.props;
|
2018-05-03 02:43:23 +00:00
|
|
|
|
|
|
|
return (
|
2018-06-21 19:02:50 +00:00
|
|
|
<div className="contact-detail-component">
|
2018-05-22 19:31:43 +00:00
|
|
|
{renderAvatar(contact, i18n)}
|
2018-05-08 00:51:29 +00:00
|
|
|
{renderName(contact)}
|
|
|
|
{renderContactShorthand(contact)}
|
|
|
|
{renderSendMessage({ hasSignalAccount, i18n, onSendMessage })}
|
2018-05-08 23:52:51 +00:00
|
|
|
{this.renderPhone(contact.number, i18n)}
|
|
|
|
{this.renderEmail(contact.email, i18n)}
|
2018-05-03 02:43:23 +00:00
|
|
|
{this.renderAddresses(contact.address, i18n)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|