// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactNode } from 'react'; import React, { useState } from 'react'; import classNames from 'classnames'; import type { LocalizerType } from '../../../types/Util'; import { ConfirmationDialog } from '../../ConfirmationDialog'; import { Tooltip, TooltipPlacement } from '../../Tooltip'; import { PanelRow } from './PanelRow'; import { PanelSection } from './PanelSection'; import { ConversationDetailsIcon, IconType } from './ConversationDetailsIcon'; export type Props = { cannotLeaveBecauseYouAreLastAdmin: boolean; conversationTitle: string; i18n: LocalizerType; isBlocked: boolean; isGroup: boolean; left: boolean; onBlock: () => void; onLeave: () => void; onUnblock: () => void; }; export const ConversationDetailsActions: React.ComponentType = ({ cannotLeaveBecauseYouAreLastAdmin, conversationTitle, i18n, isBlocked, isGroup, left, onBlock, onLeave, onUnblock, }) => { const [confirmLeave, gLeave] = useState(false); const [confirmGroupBlock, gGroupBlock] = useState(false); const [confirmDirectBlock, gDirectBlock] = useState(false); const [confirmDirectUnblock, gDirectUnblock] = useState(false); let leaveGroupNode: ReactNode; if (isGroup && !left) { leaveGroupNode = ( gLeave(true)} icon={ } label={
{i18n('ConversationDetailsActions--leave-group')}
} /> ); if (cannotLeaveBecauseYouAreLastAdmin) { leaveGroupNode = ( {leaveGroupNode} ); } } let blockNode: ReactNode; if (isGroup) { blockNode = ( gGroupBlock(true)} icon={ } label={
{i18n('ConversationDetailsActions--block-group')}
} /> ); } else { const label = isBlocked ? i18n('MessageRequests--unblock') : i18n('MessageRequests--block'); blockNode = ( (isBlocked ? gDirectUnblock(true) : gDirectBlock(true))} icon={ } label={
{label}
} /> ); } if (cannotLeaveBecauseYouAreLastAdmin) { blockNode = ( {blockNode} ); } return ( <> {leaveGroupNode} {blockNode} {confirmLeave && ( gLeave(false)} title={i18n('ConversationDetailsActions--leave-group-modal-title')} > {i18n('ConversationDetailsActions--leave-group-modal-content')} )} {confirmGroupBlock && ( gGroupBlock(false)} title={i18n('ConversationDetailsActions--block-group-modal-title', [ conversationTitle, ])} > {i18n('ConversationDetailsActions--block-group-modal-content')} )} {confirmDirectBlock && ( gDirectBlock(false)} title={i18n('MessageRequests--block-direct-confirm-title', [ conversationTitle, ])} > {i18n('MessageRequests--block-direct-confirm-body')} )} {confirmDirectUnblock && ( gDirectUnblock(false)} title={i18n('MessageRequests--unblock-direct-confirm-title', [ conversationTitle, ])} > {i18n('MessageRequests--unblock-direct-confirm-body')} )} ); };