2021-04-06 22:14:18 +00:00
|
|
|
// 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';
|
2020-07-29 23:20:05 +00:00
|
|
|
import { ContactName, PropsType as ContactNameProps } from './ContactName';
|
2021-04-06 22:14:18 +00:00
|
|
|
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;
|
2020-07-29 23:20:05 +00:00
|
|
|
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,
|
2020-07-29 23:20:05 +00:00
|
|
|
firstName,
|
|
|
|
i18n,
|
2020-05-27 21:37:06 +00:00
|
|
|
isBlocked,
|
2020-07-29 23:20:05 +00:00
|
|
|
name,
|
|
|
|
onAccept,
|
2020-05-27 21:37:06 +00:00
|
|
|
onBlock,
|
2021-05-27 20:17:05 +00:00
|
|
|
onBlockAndReportSpam,
|
2020-05-27 21:37:06 +00:00
|
|
|
onDelete,
|
2020-07-29 23:20:05 +00:00
|
|
|
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}
|
2021-05-27 20:17:05 +00:00
|
|
|
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}
|
2020-07-29 23:20:05 +00:00
|
|
|
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">
|
2021-04-06 22:14:18 +00:00
|
|
|
<Button
|
2020-09-01 18:20:29 +00:00
|
|
|
onClick={() => {
|
|
|
|
setMrState(MessageRequestState.deleting);
|
|
|
|
}}
|
2021-04-06 22:14:18 +00:00
|
|
|
variant={ButtonVariant.SecondaryDestructive}
|
2020-09-01 18:20:29 +00:00
|
|
|
>
|
|
|
|
{i18n('MessageRequests--delete')}
|
2021-04-06 22:14:18 +00:00
|
|
|
</Button>
|
2020-05-27 21:37:06 +00:00
|
|
|
{isBlocked ? (
|
2021-04-06 22:14:18 +00:00
|
|
|
<Button
|
2020-05-27 21:37:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
setMrState(MessageRequestState.unblocking);
|
|
|
|
}}
|
2021-04-06 22:14:18 +00:00
|
|
|
variant={ButtonVariant.SecondaryAffirmative}
|
2020-05-27 21:37:06 +00:00
|
|
|
>
|
|
|
|
{i18n('MessageRequests--unblock')}
|
2021-04-06 22:14:18 +00:00
|
|
|
</Button>
|
2020-05-27 21:37:06 +00:00
|
|
|
) : (
|
2021-04-06 22:14:18 +00:00
|
|
|
<Button
|
2020-05-27 21:37:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
setMrState(MessageRequestState.blocking);
|
|
|
|
}}
|
2021-04-06 22:14:18 +00:00
|
|
|
variant={ButtonVariant.SecondaryDestructive}
|
2020-05-27 21:37:06 +00:00
|
|
|
>
|
|
|
|
{i18n('MessageRequests--block')}
|
2021-04-06 22:14:18 +00:00
|
|
|
</Button>
|
2020-05-27 21:37:06 +00:00
|
|
|
)}
|
|
|
|
{!isBlocked ? (
|
2021-04-06 22:14:18 +00:00
|
|
|
<Button
|
2020-05-27 21:37:06 +00:00
|
|
|
onClick={onAccept}
|
2021-04-06 22:14:18 +00:00
|
|
|
variant={ButtonVariant.SecondaryAffirmative}
|
2020-05-27 21:37:06 +00:00
|
|
|
>
|
|
|
|
{i18n('MessageRequests--accept')}
|
2021-04-06 22:14:18 +00:00
|
|
|
</Button>
|
2020-05-27 21:37:06 +00:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|