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

173 lines
4.9 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 { ConfirmationDialog } from '../ConfirmationDialog';
2020-05-27 21:37:06 +00:00
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
2020-05-27 21:37:06 +00:00
export enum MessageRequestState {
blocking,
deleting,
unblocking,
default,
}
export type Props = {
2022-12-06 19:03:09 +00:00
acceptConversation(conversationId: string): unknown;
blockAndReportSpam(conversationId: string): unknown;
blockConversation(conversationId: string): unknown;
conversationId: string;
2020-05-27 21:37:06 +00:00
conversationType: 'group' | 'direct';
2022-12-06 19:03:09 +00:00
deleteConversation(conversationId: string): unknown;
i18n: LocalizerType;
2020-05-27 21:37:06 +00:00
isBlocked?: boolean;
onChangeState(state: MessageRequestState): unknown;
2022-12-06 19:03:09 +00:00
state: MessageRequestState;
} & Omit<ContactNameProps, 'module'>;
2020-05-27 21:37:06 +00:00
2022-11-18 00:45:19 +00:00
export function MessageRequestActionsConfirmation({
2022-12-06 19:03:09 +00:00
acceptConversation,
blockAndReportSpam,
blockConversation,
conversationId,
conversationType,
2022-12-06 19:03:09 +00:00
deleteConversation,
2020-05-27 21:37:06 +00:00
i18n,
onChangeState,
2020-05-27 21:37:06 +00:00
state,
title,
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element | null {
2020-05-27 21:37:06 +00:00
if (state === MessageRequestState.blocking) {
return (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.blocking"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
id="MessageRequests--block-direct-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
) : (
<Intl
i18n={i18n}
id="MessageRequests--block-group-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
)
2020-05-27 21:37:06 +00:00
}
actions={[
...(conversationType === 'direct'
? [
{
text: i18n('MessageRequests--block-and-report-spam'),
2022-12-06 19:03:09 +00:00
action: () => blockAndReportSpam(conversationId),
style: 'negative' as const,
},
]
: []),
2020-05-27 21:37:06 +00:00
{
text: i18n('MessageRequests--block'),
2022-12-06 19:03:09 +00:00
action: () => blockConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
? i18n('MessageRequests--block-direct-confirm-body')
: i18n('MessageRequests--block-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
if (state === MessageRequestState.unblocking) {
return (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.unblocking"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
2022-11-09 03:40:23 +00:00
id="MessageRequests--unblock-direct-confirm-title"
components={{
name: <ContactName key="name" title={title} />,
}}
2020-05-27 21:37:06 +00:00
/>
}
actions={[
{
text: i18n('MessageRequests--unblock'),
2022-12-06 19:03:09 +00:00
action: () => acceptConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'affirmative',
},
]}
>
{conversationType === 'direct'
? i18n('MessageRequests--unblock-direct-confirm-body')
: i18n('MessageRequests--unblock-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
if (state === MessageRequestState.deleting) {
return (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="messageRequestActionsConfirmation.deleting"
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
id="MessageRequests--delete-direct-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
) : (
<Intl
i18n={i18n}
id="MessageRequests--delete-group-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
)
2020-05-27 21:37:06 +00:00
}
actions={[
{
text:
conversationType === 'direct'
? i18n('MessageRequests--delete-direct')
: i18n('MessageRequests--delete-group'),
2022-12-06 19:03:09 +00:00
action: () => deleteConversation(conversationId),
2020-05-27 21:37:06 +00:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
? i18n('MessageRequests--delete-direct-confirm-body')
: i18n('MessageRequests--delete-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
return null;
2022-11-18 00:45:19 +00:00
}