// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import type { FunctionComponent } from 'react'; import { HEADER_CONTACT_NAME_CLASS_NAME } from './BaseConversationListItem'; import type { ConversationType } from '../../state/ducks/conversations'; import type { BadgeType } from '../../badges/types'; import type { LocalizerType, ThemeType } from '../../types/Util'; import { ContactName } from '../conversation/ContactName'; import { About } from '../conversation/About'; import { ListTile } from '../ListTile'; import { Avatar, AvatarSize } from '../Avatar'; export enum ContactCheckboxDisabledReason { // We start the enum at 1 because the default starting value of 0 is falsy. AlreadyAdded = 1, MaximumContactsSelected, } export type PropsDataType = { badge: undefined | BadgeType; disabledReason?: ContactCheckboxDisabledReason; isChecked: boolean; } & Pick< ConversationType, | 'about' | 'acceptedMessageRequest' | 'avatarPath' | 'color' | 'groupId' | 'id' | 'isMe' | 'phoneNumber' | 'profileName' | 'sharedGroupNames' | 'title' | 'type' | 'unblurredAvatarPath' | 'serviceId' >; type PropsHousekeepingType = { i18n: LocalizerType; onClick: ( id: string, disabledReason: undefined | ContactCheckboxDisabledReason ) => void; theme: ThemeType; }; type PropsType = PropsDataType & PropsHousekeepingType; export const ContactCheckbox: FunctionComponent = React.memo( function ContactCheckbox({ about, acceptedMessageRequest, avatarPath, badge, color, disabledReason, i18n, id, isChecked, isMe, onClick, phoneNumber, profileName, sharedGroupNames, theme, title, type, unblurredAvatarPath, }) { const disabled = Boolean(disabledReason); const headerName = isMe ? ( ) : ( ); let messageText: undefined | string | JSX.Element; if (disabledReason === ContactCheckboxDisabledReason.AlreadyAdded) { messageText = i18n('icu:alreadyAMember'); } else if (about) { messageText = ; } const onClickItem = () => { onClick(id, disabledReason); }; return ( } title={headerName} subtitle={isMe ? undefined : messageText} subtitleMaxLines={1} onClick={onClickItem} /> ); } );