2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-03 02:43:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-08-20 01:56:39 +00:00
|
|
|
EmbeddedContactType,
|
2018-05-05 01:19:54 +00:00
|
|
|
Email,
|
2018-05-08 00:51:29 +00:00
|
|
|
Phone,
|
2018-05-05 01:19:54 +00:00
|
|
|
PostalAddress,
|
2021-08-20 01:56:39 +00:00
|
|
|
} from '../../types/EmbeddedContact';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { AddressType, ContactFormType } from '../../types/EmbeddedContact';
|
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,
|
2021-12-01 23:37:37 +00:00
|
|
|
} from './contactUtil';
|
2018-05-08 00:51:29 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type Props = {
|
2021-08-20 01:56:39 +00:00
|
|
|
contact: EmbeddedContactType;
|
2018-05-03 02:43:23 +00:00
|
|
|
hasSignalAccount: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2018-05-03 02:43:23 +00:00
|
|
|
onSendMessage: () => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
function getLabelForEmail(method: Email, i18n: LocalizerType): string {
|
2018-05-03 02:43:23 +00:00
|
|
|
switch (method.type) {
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.CUSTOM:
|
2018-05-08 23:52:51 +00:00
|
|
|
return method.label || i18n('email');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.HOME:
|
2018-05-03 02:43:23 +00:00
|
|
|
return i18n('home');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.MOBILE:
|
2018-05-03 02:43:23 +00:00
|
|
|
return i18n('mobile');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.WORK:
|
2018-05-03 02:43:23 +00:00
|
|
|
return i18n('work');
|
|
|
|
default:
|
2018-05-08 23:52:51 +00:00
|
|
|
throw missingCaseError(method.type);
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
function getLabelForPhone(method: Phone, i18n: LocalizerType): string {
|
2018-05-08 23:52:51 +00:00
|
|
|
switch (method.type) {
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.CUSTOM:
|
2018-05-08 23:52:51 +00:00
|
|
|
return method.label || i18n('phone');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.HOME:
|
2018-05-08 23:52:51 +00:00
|
|
|
return i18n('home');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.MOBILE:
|
2018-05-08 23:52:51 +00:00
|
|
|
return i18n('mobile');
|
2019-03-15 22:18:00 +00:00
|
|
|
case ContactFormType.WORK:
|
2018-05-08 23:52:51 +00:00
|
|
|
return i18n('work');
|
|
|
|
default:
|
|
|
|
throw missingCaseError(method.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
function getLabelForAddress(
|
|
|
|
address: PostalAddress,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): 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-06-27 20:53:49 +00:00
|
|
|
public renderSendMessage({
|
|
|
|
hasSignalAccount,
|
|
|
|
i18n,
|
|
|
|
onSendMessage,
|
|
|
|
}: {
|
|
|
|
hasSignalAccount: boolean;
|
|
|
|
i18n: (key: string, values?: Array<string>) => string;
|
|
|
|
onSendMessage: () => void;
|
2020-09-14 19:51:27 +00:00
|
|
|
}): JSX.Element | null {
|
2018-06-27 20:53:49 +00:00
|
|
|
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.
|
2020-09-14 19:51:27 +00:00
|
|
|
const onClick = (e: React.MouseEvent<HTMLButtonElement>): void => {
|
2018-06-27 20:53:49 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
onSendMessage();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-09-14 19:51:27 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="module-contact-detail__send-message"
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
2019-11-07 21:36:16 +00:00
|
|
|
<div className="module-contact-detail__send-message__inner">
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className="module-contact-detail__send-message__bubble-icon" />
|
|
|
|
{i18n('sendMessageToContact')}
|
2019-11-07 21:36:16 +00:00
|
|
|
</div>
|
|
|
|
</button>
|
2018-06-27 20:53:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderEmail(
|
|
|
|
items: Array<Email> | undefined,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): Array<JSX.Element> | undefined {
|
2018-05-08 23:52:51 +00:00
|
|
|
if (!items || items.length === 0) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return undefined;
|
2018-05-08 23:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return items.map((item: Email) => {
|
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
|
|
|
key={item.value}
|
|
|
|
className="module-contact-detail__additional-contact"
|
|
|
|
>
|
|
|
|
<div className="module-contact-detail__additional-contact__type">
|
|
|
|
{getLabelForEmail(item, i18n)}
|
|
|
|
</div>
|
2018-05-08 23:52:51 +00:00
|
|
|
{item.value}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderPhone(
|
|
|
|
items: Array<Phone> | undefined,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): Array<JSX.Element> | null | undefined {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!items || items.length === 0) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return undefined;
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 23:52:51 +00:00
|
|
|
return items.map((item: Phone) => {
|
2018-05-03 02:43:23 +00:00
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div
|
|
|
|
key={item.value}
|
|
|
|
className="module-contact-detail__additional-contact"
|
|
|
|
>
|
|
|
|
<div className="module-contact-detail__additional-contact__type">
|
|
|
|
{getLabelForPhone(item, i18n)}
|
|
|
|
</div>
|
2018-05-03 02:43:23 +00:00
|
|
|
{item.value}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAddressLine(value: string | undefined): JSX.Element | undefined {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!value) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return undefined;
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return <div>{value}</div>;
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderPOBox(
|
|
|
|
poBox: string | undefined,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): JSX.Element | null {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!poBox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{i18n('poBox')} {poBox}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderAddressLineTwo(address: PostalAddress): JSX.Element | null {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (address.city || address.region || address.postcode) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{address.city} {address.region} {address.postcode}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderAddresses(
|
|
|
|
addresses: Array<PostalAddress> | undefined,
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType
|
2020-09-14 19:51:27 +00:00
|
|
|
): Array<JSX.Element> | undefined {
|
2018-05-03 02:43:23 +00:00
|
|
|
if (!addresses || addresses.length === 0) {
|
2020-09-14 19:51:27 +00:00
|
|
|
return undefined;
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return addresses.map((address: PostalAddress, index: number) => {
|
|
|
|
return (
|
2020-09-14 19:51:27 +00:00
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
2018-06-27 20:53:49 +00:00
|
|
|
<div key={index} className="module-contact-detail__additional-contact">
|
|
|
|
<div className="module-contact-detail__additional-contact__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>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-12 23:44:20 +00:00
|
|
|
public override render(): JSX.Element {
|
2018-05-08 00:51:29 +00:00
|
|
|
const { contact, hasSignalAccount, i18n, onSendMessage } = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
const isIncoming = false;
|
|
|
|
const module = 'contact-detail';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
|
|
|
return (
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className="module-contact-detail">
|
2018-09-27 00:23:17 +00:00
|
|
|
<div className="module-contact-detail__avatar">
|
|
|
|
{renderAvatar({ contact, i18n, size: 80 })}
|
|
|
|
</div>
|
2018-06-27 20:53:49 +00:00
|
|
|
{renderName({ contact, isIncoming, module })}
|
|
|
|
{renderContactShorthand({ contact, isIncoming, module })}
|
|
|
|
{this.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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|