// Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { noop } from 'lodash'; import { Avatar } from './Avatar'; import { ConfirmationDialog } from './ConfirmationDialog'; import { InContactsIcon } from './InContactsIcon'; import { Modal } from './Modal'; import { ConversationType } from '../state/ducks/conversations'; import { LocalizerType } from '../types/Util'; import { isInSystemContacts } from '../util/isInSystemContacts'; export type SafetyNumberProps = { contactID: string; onClose?: () => void; }; export type Props = { readonly confirmText?: string; readonly contacts: Array; readonly i18n: LocalizerType; readonly onCancel: () => void; readonly onConfirm: () => void; readonly renderSafetyNumber: (props: SafetyNumberProps) => JSX.Element; }; export const SafetyNumberChangeDialog = ({ confirmText, contacts, i18n, onCancel, onConfirm, renderSafetyNumber, }: Props): JSX.Element => { const [selectedContact, setSelectedContact] = React.useState< ConversationType | undefined >(undefined); const cancelButtonRef = React.createRef(); React.useEffect(() => { if (cancelButtonRef && cancelButtonRef.current) { cancelButtonRef.current.focus(); } }, [cancelButtonRef, contacts]); const onClose = selectedContact ? () => { setSelectedContact(undefined); } : onCancel; if (selectedContact) { return ( {renderSafetyNumber({ contactID: selectedContact.id, onClose })} ); } return (
{i18n('changedVerificationWarning')}
    {contacts.map((contact: ConversationType) => { const shouldShowNumber = Boolean(contact.name || contact.profileName); return (
  • {contact.title} {isInSystemContacts(contact) ? ( {' '} ) : null}
    {shouldShowNumber ? (
    {contact.phoneNumber}
    ) : null}
  • ); })}
); };