// Copyright 2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import type { ContactNameData } from './ContactName'; import { ContactName } from './ContactName'; import { ConfirmationDialog } from '../ConfirmationDialog'; import { Intl } from '../Intl'; import type { LocalizerType } from '../../types/Util'; export enum MessageRequestState { blocking, deleting, unblocking, reportingAndMaybeBlocking, acceptedOptions, default, } export type MessageRequestActionsConfirmationBaseProps = { addedByName: ContactNameData | null; conversationId: string; conversationType: 'group' | 'direct'; conversationName: ContactNameData; isBlocked: boolean; isReported: boolean; acceptConversation(conversationId: string): void; blockAndReportSpam(conversationId: string): void; blockConversation(conversationId: string): void; reportSpam(conversationId: string): void; deleteConversation(conversationId: string): void; }; export type MessageRequestActionsConfirmationProps = MessageRequestActionsConfirmationBaseProps & { i18n: LocalizerType; state: MessageRequestState; onChangeState(state: MessageRequestState): void; }; export function MessageRequestActionsConfirmation({ addedByName, conversationId, conversationType, conversationName, i18n, isBlocked, state, acceptConversation, blockAndReportSpam, blockConversation, reportSpam, deleteConversation, onChangeState, }: MessageRequestActionsConfirmationProps): JSX.Element | null { if (state === MessageRequestState.blocking) { return ( { onChangeState(MessageRequestState.default); }} title={ conversationType === 'direct' ? ( ), }} /> ) : ( ), }} /> ) } actions={[ { text: i18n('icu:MessageRequests--block'), action: () => blockConversation(conversationId), style: 'negative', }, ]} > {conversationType === 'direct' ? i18n('icu:MessageRequests--block-direct-confirm-body') : i18n('icu:MessageRequests--block-group-confirm-body')} ); } if (state === MessageRequestState.reportingAndMaybeBlocking) { return ( { onChangeState(MessageRequestState.default); }} title={i18n('icu:MessageRequests--ReportAndMaybeBlockModal-title')} actions={[ ...(!isBlocked ? ([ { text: i18n( 'icu:MessageRequests--ReportAndMaybeBlockModal-reportAndBlock' ), action: () => blockAndReportSpam(conversationId), style: 'negative', }, ] as const) : []), { text: i18n('icu:MessageRequests--ReportAndMaybeBlockModal-report'), action: () => reportSpam(conversationId), style: 'negative', }, ]} > {/* eslint-disable-next-line no-nested-ternary */} {conversationType === 'direct' ? ( i18n('icu:MessageRequests--ReportAndMaybeBlockModal-body--direct') ) : addedByName == null ? ( i18n( 'icu:MessageRequests--ReportAndMaybeBlockModal-body--group--unknown-contact' ) ) : ( , }} /> )} ); } if (state === MessageRequestState.unblocking) { return ( { onChangeState(MessageRequestState.default); }} title={ ), }} /> } actions={[ { text: i18n('icu:MessageRequests--unblock'), action: () => acceptConversation(conversationId), style: 'affirmative', }, ]} > {conversationType === 'direct' ? i18n('icu:MessageRequests--unblock-direct-confirm-body') : i18n('icu:MessageRequests--unblock-group-confirm-body')} ); } if (state === MessageRequestState.deleting) { return ( { onChangeState(MessageRequestState.default); }} title={ conversationType === 'direct' ? ( ) : ( ), }} /> ) } actions={[ { text: conversationType === 'direct' ? i18n('icu:MessageRequests--delete-direct') : i18n('icu:MessageRequests--delete-group'), action: () => deleteConversation(conversationId), style: 'negative', }, ]} > {conversationType === 'direct' ? i18n('icu:MessageRequests--delete-direct-confirm-body') : i18n('icu:MessageRequests--delete-group-confirm-body')} ); } if (state === MessageRequestState.acceptedOptions) { return ( { onChangeState(MessageRequestState.default); }} actions={[ { text: i18n('icu:MessageRequests--reportAndMaybeBlock'), action: () => onChangeState(MessageRequestState.reportingAndMaybeBlocking), style: 'negative', }, { text: i18n('icu:MessageRequests--block'), action: () => onChangeState(MessageRequestState.blocking), style: 'negative', }, ]} > ), }} /> ); } return null; }