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

133 lines
3.4 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 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 = {
i18n: LocalizerType;
conversationType: 'group' | 'direct';
isBlocked?: boolean;
onBlock(): unknown;
onBlockAndReportSpam(): unknown;
2020-05-27 21:37:06 +00:00
onUnblock(): unknown;
onDelete(): unknown;
state: MessageRequestState;
onChangeState(state: MessageRequestState): unknown;
} & Omit<ContactNameProps, 'module'>;
2020-05-27 21:37:06 +00:00
export const MessageRequestActionsConfirmation = ({
conversationType,
2020-05-27 21:37:06 +00:00
i18n,
onBlock,
onBlockAndReportSpam,
onChangeState,
2020-05-27 21:37:06 +00:00
onDelete,
onUnblock,
2020-05-27 21:37:06 +00:00
state,
title,
2020-09-14 19:51:27 +00:00
}: Props): JSX.Element | null => {
2020-05-27 21:37:06 +00:00
if (state === MessageRequestState.blocking) {
return (
<ConfirmationDialog
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
id={`MessageRequests--block-${conversationType}-confirm-title`}
components={[<ContactName key="name" title={title} />]}
2020-05-27 21:37:06 +00:00
/>
}
actions={[
...(conversationType === 'direct'
? [
{
text: i18n('MessageRequests--block-and-report-spam'),
action: onBlockAndReportSpam,
style: 'negative' as const,
},
]
: []),
2020-05-27 21:37:06 +00:00
{
text: i18n('MessageRequests--block'),
action: onBlock,
style: 'negative',
},
]}
>
{i18n(`MessageRequests--block-${conversationType}-confirm-body`)}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
if (state === MessageRequestState.unblocking) {
return (
<ConfirmationDialog
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
2020-09-14 19:51:27 +00:00
id="MessageRequests--unblock-confirm-title"
components={[<ContactName key="name" title={title} />]}
2020-05-27 21:37:06 +00:00
/>
}
actions={[
{
text: i18n('MessageRequests--unblock'),
action: onUnblock,
style: 'affirmative',
},
]}
>
{i18n(`MessageRequests--unblock-${conversationType}-confirm-body`)}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
if (state === MessageRequestState.deleting) {
return (
<ConfirmationDialog
2020-05-27 21:37:06 +00:00
i18n={i18n}
onClose={() => {
onChangeState(MessageRequestState.default);
}}
title={
<Intl
i18n={i18n}
id={`MessageRequests--delete-${conversationType}-confirm-title`}
components={[<ContactName key="name" title={title} />]}
2020-05-27 21:37:06 +00:00
/>
}
actions={[
{
text: i18n(`MessageRequests--delete-${conversationType}`),
action: onDelete,
style: 'negative',
},
]}
>
{i18n(`MessageRequests--delete-${conversationType}-confirm-body`)}
</ConfirmationDialog>
2020-05-27 21:37:06 +00:00
);
}
return null;
};