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

170 lines
4.9 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-05-27 17:37:06 -04:00
import * as React from 'react';
import type { PropsType as ContactNameProps } from './ContactName';
import { ContactName } from './ContactName';
import { ConfirmationDialog } from '../ConfirmationDialog';
2020-05-27 17:37:06 -04:00
import { Intl } from '../Intl';
import type { LocalizerType } from '../../types/Util';
2020-05-27 17:37:06 -04:00
export enum MessageRequestState {
blocking,
deleting,
unblocking,
default,
}
export type Props = {
2022-12-06 14:03:09 -05:00
acceptConversation(conversationId: string): unknown;
blockAndReportSpam(conversationId: string): unknown;
blockConversation(conversationId: string): unknown;
conversationId: string;
2020-05-27 17:37:06 -04:00
conversationType: 'group' | 'direct';
2022-12-06 14:03:09 -05:00
deleteConversation(conversationId: string): unknown;
i18n: LocalizerType;
2020-05-27 17:37:06 -04:00
isBlocked?: boolean;
onChangeState(state: MessageRequestState): unknown;
2022-12-06 14:03:09 -05:00
state: MessageRequestState;
} & Omit<ContactNameProps, 'module'>;
2020-05-27 17:37:06 -04:00
2022-11-17 16:45:19 -08:00
export function MessageRequestActionsConfirmation({
2022-12-06 14:03:09 -05:00
acceptConversation,
blockAndReportSpam,
blockConversation,
conversationId,
conversationType,
2022-12-06 14:03:09 -05:00
deleteConversation,
2020-05-27 17:37:06 -04:00
i18n,
onChangeState,
2020-05-27 17:37:06 -04:00
state,
title,
2022-11-17 16:45:19 -08:00
}: Props): JSX.Element | null {
2020-05-27 17:37:06 -04:00
if (state === MessageRequestState.blocking) {
return (
<ConfirmationDialog
2022-09-27 13:24:21 -07:00
dialogName="messageRequestActionsConfirmation.blocking"
2020-05-27 17:37:06 -04:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
2023-03-29 17:03:25 -07:00
id="icu:MessageRequests--block-direct-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
) : (
<Intl
i18n={i18n}
2023-03-29 17:03:25 -07:00
id="icu:MessageRequests--block-group-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
)
2020-05-27 17:37:06 -04:00
}
actions={[
...(conversationType === 'direct'
? [
{
2023-03-29 17:03:25 -07:00
text: i18n('icu:MessageRequests--block-and-report-spam'),
2022-12-06 14:03:09 -05:00
action: () => blockAndReportSpam(conversationId),
style: 'negative' as const,
},
]
: []),
2020-05-27 17:37:06 -04:00
{
2023-03-29 17:03:25 -07:00
text: i18n('icu:MessageRequests--block'),
2022-12-06 14:03:09 -05:00
action: () => blockConversation(conversationId),
2020-05-27 17:37:06 -04:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
2023-03-29 17:03:25 -07:00
? i18n('icu:MessageRequests--block-direct-confirm-body')
: i18n('icu:MessageRequests--block-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 17:37:06 -04:00
);
}
if (state === MessageRequestState.unblocking) {
return (
<ConfirmationDialog
2022-09-27 13:24:21 -07:00
dialogName="messageRequestActionsConfirmation.unblocking"
2020-05-27 17:37:06 -04:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
2023-03-29 17:03:25 -07:00
id="icu:MessageRequests--unblock-direct-confirm-title"
2022-11-08 19:40:23 -08:00
components={{
name: <ContactName key="name" title={title} />,
}}
2020-05-27 17:37:06 -04:00
/>
}
actions={[
{
2023-03-29 17:03:25 -07:00
text: i18n('icu:MessageRequests--unblock'),
2022-12-06 14:03:09 -05:00
action: () => acceptConversation(conversationId),
2020-05-27 17:37:06 -04:00
style: 'affirmative',
},
]}
>
{conversationType === 'direct'
2023-03-29 17:03:25 -07:00
? i18n('icu:MessageRequests--unblock-direct-confirm-body')
: i18n('icu:MessageRequests--unblock-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 17:37:06 -04:00
);
}
if (state === MessageRequestState.deleting) {
return (
<ConfirmationDialog
2022-09-27 13:24:21 -07:00
dialogName="messageRequestActionsConfirmation.deleting"
2020-05-27 17:37:06 -04:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
conversationType === 'direct' ? (
<Intl
i18n={i18n}
2023-03-29 17:03:25 -07:00
id="icu:MessageRequests--delete-direct-confirm-title"
/>
) : (
<Intl
i18n={i18n}
2023-03-29 17:03:25 -07:00
id="icu:MessageRequests--delete-group-confirm-title"
components={{
title: <ContactName key="name" title={title} />,
}}
/>
)
2020-05-27 17:37:06 -04:00
}
actions={[
{
text:
conversationType === 'direct'
2023-03-29 17:03:25 -07:00
? i18n('icu:MessageRequests--delete-direct')
: i18n('icu:MessageRequests--delete-group'),
2022-12-06 14:03:09 -05:00
action: () => deleteConversation(conversationId),
2020-05-27 17:37:06 -04:00
style: 'negative',
},
]}
>
{conversationType === 'direct'
2023-03-29 17:03:25 -07:00
? i18n('icu:MessageRequests--delete-direct-confirm-body')
: i18n('icu:MessageRequests--delete-group-confirm-body')}
</ConfirmationDialog>
2020-05-27 17:37:06 -04:00
);
}
return null;
2022-11-17 16:45:19 -08:00
}