signal-desktop/ts/components/conversation/MessageRequestActions.tsx

124 lines
3.5 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-05-27 21:37:06 +00:00
import * as React from 'react';
import { ContactName, PropsType as ContactNameProps } from './ContactName';
import { Button, ButtonVariant } from '../Button';
2020-05-27 21:37:06 +00:00
import {
MessageRequestActionsConfirmation,
MessageRequestState,
Props as MessageRequestActionsConfirmationProps,
} from './MessageRequestActionsConfirmation';
import { Intl } from '../Intl';
import { LocalizerType } from '../../types/Util';
export type Props = {
i18n: LocalizerType;
firstName?: string;
2020-05-27 21:37:06 +00:00
onAccept(): unknown;
2020-07-24 01:35:32 +00:00
} & Omit<ContactNameProps, 'module' | 'i18n'> &
2020-05-27 21:37:06 +00:00
Omit<
MessageRequestActionsConfirmationProps,
'i18n' | 'state' | 'onChangeState'
>;
export const MessageRequestActions = ({
conversationType,
firstName,
i18n,
2020-05-27 21:37:06 +00:00
isBlocked,
name,
onAccept,
2020-05-27 21:37:06 +00:00
onBlock,
onBlockAndReportSpam,
2020-05-27 21:37:06 +00:00
onDelete,
onUnblock,
phoneNumber,
profileName,
title,
2020-09-14 19:51:27 +00:00
}: Props): JSX.Element => {
2020-05-27 21:37:06 +00:00
const [mrState, setMrState] = React.useState(MessageRequestState.default);
return (
<>
{mrState !== MessageRequestState.default ? (
<MessageRequestActionsConfirmation
i18n={i18n}
onBlock={onBlock}
onBlockAndReportSpam={onBlockAndReportSpam}
2020-05-27 21:37:06 +00:00
onUnblock={onUnblock}
onDelete={onDelete}
name={name}
profileName={profileName}
phoneNumber={phoneNumber}
2020-07-24 01:35:32 +00:00
title={title}
2020-05-27 21:37:06 +00:00
conversationType={conversationType}
state={mrState}
onChangeState={setMrState}
/>
) : null}
<div className="module-message-request-actions">
<p className="module-message-request-actions__message">
<Intl
i18n={i18n}
id={`MessageRequests--message-${conversationType}${
isBlocked ? '-blocked' : ''
}`}
components={[
<strong
key="name"
className="module-message-request-actions__message__name"
>
<ContactName
name={name}
profileName={profileName}
phoneNumber={phoneNumber}
title={firstName || title}
2020-07-24 01:35:32 +00:00
i18n={i18n}
2020-05-27 21:37:06 +00:00
/>
</strong>,
]}
/>
</p>
<div className="module-message-request-actions__buttons">
<Button
onClick={() => {
setMrState(MessageRequestState.deleting);
}}
variant={ButtonVariant.SecondaryDestructive}
>
{i18n('MessageRequests--delete')}
</Button>
2020-05-27 21:37:06 +00:00
{isBlocked ? (
<Button
2020-05-27 21:37:06 +00:00
onClick={() => {
setMrState(MessageRequestState.unblocking);
}}
variant={ButtonVariant.SecondaryAffirmative}
2020-05-27 21:37:06 +00:00
>
{i18n('MessageRequests--unblock')}
</Button>
2020-05-27 21:37:06 +00:00
) : (
<Button
2020-05-27 21:37:06 +00:00
onClick={() => {
setMrState(MessageRequestState.blocking);
}}
variant={ButtonVariant.SecondaryDestructive}
2020-05-27 21:37:06 +00:00
>
{i18n('MessageRequests--block')}
</Button>
2020-05-27 21:37:06 +00:00
)}
{!isBlocked ? (
<Button
2020-05-27 21:37:06 +00:00
onClick={onAccept}
variant={ButtonVariant.SecondaryAffirmative}
2020-05-27 21:37:06 +00:00
>
{i18n('MessageRequests--accept')}
</Button>
2020-05-27 21:37:06 +00:00
) : null}
</div>
</div>
</>
);
};