signal-desktop/ts/components/conversationList/ContactCheckbox.tsx

127 lines
3 KiB
TypeScript
Raw Normal View History

2022-03-04 19:48:44 +00:00
// Copyright 2021-2022 Signal Messenger, LLC
2021-03-03 20:09:58 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import type { FunctionComponent, ReactNode } from 'react';
import React from 'react';
2021-03-03 20:09:58 +00:00
2021-10-14 15:48:48 +00:00
import {
BaseConversationListItem,
HEADER_CONTACT_NAME_CLASS_NAME,
} from './BaseConversationListItem';
import type { ConversationType } from '../../state/ducks/conversations';
2021-11-17 21:11:21 +00:00
import type { BadgeType } from '../../badges/types';
import type { LocalizerType, ThemeType } from '../../types/Util';
2021-03-03 20:09:58 +00:00
import { ContactName } from '../conversation/ContactName';
import { About } from '../conversation/About';
export enum ContactCheckboxDisabledReason {
// We start the enum at 1 because the default starting value of 0 is falsy.
2021-03-11 21:29:31 +00:00
AlreadyAdded = 1,
MaximumContactsSelected,
2021-03-03 20:09:58 +00:00
}
export type PropsDataType = {
2021-11-17 21:11:21 +00:00
badge: undefined | BadgeType;
2021-03-03 20:09:58 +00:00
disabledReason?: ContactCheckboxDisabledReason;
isChecked: boolean;
} & Pick<
ConversationType,
| 'about'
| 'acceptedMessageRequest'
| 'avatarPath'
| 'color'
| 'id'
| 'isMe'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
| 'type'
| 'unblurredAvatarPath'
>;
2021-03-03 20:09:58 +00:00
type PropsHousekeepingType = {
i18n: LocalizerType;
onClick: (
id: string,
disabledReason: undefined | ContactCheckboxDisabledReason
) => void;
2021-11-17 21:11:21 +00:00
theme: ThemeType;
2021-03-03 20:09:58 +00:00
};
type PropsType = PropsDataType & PropsHousekeepingType;
export const ContactCheckbox: FunctionComponent<PropsType> = React.memo(
2021-08-11 19:29:07 +00:00
function ContactCheckbox({
2021-03-03 20:09:58 +00:00
about,
acceptedMessageRequest,
2021-03-03 20:09:58 +00:00
avatarPath,
2021-11-17 21:11:21 +00:00
badge,
2021-03-03 20:09:58 +00:00
color,
disabledReason,
i18n,
id,
isChecked,
2021-04-27 22:35:35 +00:00
isMe,
2021-03-03 20:09:58 +00:00
name,
onClick,
phoneNumber,
profileName,
sharedGroupNames,
2021-11-17 21:11:21 +00:00
theme,
2021-03-03 20:09:58 +00:00
title,
type,
unblurredAvatarPath,
2021-08-11 19:29:07 +00:00
}) {
2021-03-03 20:09:58 +00:00
const disabled = Boolean(disabledReason);
2021-04-27 22:35:35 +00:00
const headerName = isMe ? (
2021-10-14 15:48:48 +00:00
<span className={HEADER_CONTACT_NAME_CLASS_NAME}>
{i18n('noteToSelf')}
</span>
2021-04-27 22:35:35 +00:00
) : (
2021-10-14 15:48:48 +00:00
<ContactName module={HEADER_CONTACT_NAME_CLASS_NAME} title={title} />
2021-03-03 20:09:58 +00:00
);
2021-03-11 21:29:31 +00:00
let messageText: ReactNode;
if (disabledReason === ContactCheckboxDisabledReason.AlreadyAdded) {
messageText = i18n('alreadyAMember');
} else if (about) {
messageText = <About className="" text={about} />;
} else {
messageText = null;
}
2021-03-03 20:09:58 +00:00
const onClickItem = () => {
onClick(id, disabledReason);
};
return (
<BaseConversationListItem
acceptedMessageRequest={acceptedMessageRequest}
2021-03-03 20:09:58 +00:00
avatarPath={avatarPath}
2021-11-17 21:11:21 +00:00
badge={badge}
2021-03-03 20:09:58 +00:00
checked={isChecked}
color={color}
conversationType={type}
2021-03-03 20:09:58 +00:00
disabled={disabled}
headerName={headerName}
i18n={i18n}
id={id}
2021-04-27 22:35:35 +00:00
isMe={isMe}
2021-03-03 20:09:58 +00:00
isSelected={false}
messageText={messageText}
name={name}
onClick={onClickItem}
phoneNumber={phoneNumber}
profileName={profileName}
sharedGroupNames={sharedGroupNames}
2021-11-17 21:11:21 +00:00
theme={theme}
2021-03-03 20:09:58 +00:00
title={title}
unblurredAvatarPath={unblurredAvatarPath}
2021-03-03 20:09:58 +00:00
/>
);
}
);