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

116 lines
3.4 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 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 type { PropsType as ContactNameProps } from './ContactName';
import { ContactName } from './ContactName';
import { Button, ButtonVariant } from '../Button';
import type { Props as MessageRequestActionsConfirmationProps } from './MessageRequestActionsConfirmation';
2020-05-27 21:37:06 +00:00
import {
MessageRequestActionsConfirmation,
MessageRequestState,
} from './MessageRequestActionsConfirmation';
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
2020-05-27 21:37:06 +00:00
export type Props = {
i18n: LocalizerType;
} & Omit<ContactNameProps, 'module'> &
2020-05-27 21:37:06 +00:00
Omit<
MessageRequestActionsConfirmationProps,
'i18n' | 'state' | 'onChangeState'
>;
2022-11-18 00:45:19 +00:00
export function MessageRequestActions({
2022-12-06 19:03:09 +00:00
acceptConversation,
blockAndReportSpam,
blockConversation,
conversationId,
2020-05-27 21:37:06 +00:00
conversationType,
2022-12-06 19:03:09 +00:00
deleteConversation,
firstName,
i18n,
2020-05-27 21:37:06 +00:00
isBlocked,
title,
2022-11-18 00:45:19 +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
2022-12-06 19:03:09 +00:00
acceptConversation={acceptConversation}
blockAndReportSpam={blockAndReportSpam}
blockConversation={blockConversation}
conversationId={conversationId}
2020-05-27 21:37:06 +00:00
conversationType={conversationType}
2022-12-06 19:03:09 +00:00
deleteConversation={deleteConversation}
i18n={i18n}
2020-05-27 21:37:06 +00:00
onChangeState={setMrState}
2022-12-06 19:03:09 +00:00
state={mrState}
title={title}
2020-05-27 21:37:06 +00:00
/>
) : 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
firstName={firstName}
title={title}
preferFirstName
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
2022-12-06 19:03:09 +00:00
onClick={() => acceptConversation(conversationId)}
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>
</>
);
2022-11-18 00:45:19 +00:00
}