2021-04-05 17:44:13 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
2021-04-05 17:44:13 +00:00
|
|
|
import classNames from 'classnames';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { LocalizerType } from '../../../types/Util';
|
2021-04-27 19:29:59 +00:00
|
|
|
import { ConfirmationDialog } from '../../ConfirmationDialog';
|
2021-04-05 17:44:13 +00:00
|
|
|
import { Tooltip, TooltipPlacement } from '../../Tooltip';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { PanelRow } from './PanelRow';
|
|
|
|
import { PanelSection } from './PanelSection';
|
|
|
|
import { ConversationDetailsIcon } from './ConversationDetailsIcon';
|
|
|
|
|
|
|
|
export type Props = {
|
2021-04-05 17:44:13 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin: boolean;
|
2021-01-29 21:19:24 +00:00
|
|
|
conversationTitle: string;
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock: () => void;
|
|
|
|
onLeave: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
i18n: LocalizerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ConversationDetailsActions: React.ComponentType<Props> = ({
|
2021-04-05 17:44:13 +00:00
|
|
|
cannotLeaveBecauseYouAreLastAdmin,
|
2021-01-29 21:19:24 +00:00
|
|
|
conversationTitle,
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock,
|
|
|
|
onLeave,
|
2021-01-29 21:19:24 +00:00
|
|
|
i18n,
|
|
|
|
}) => {
|
|
|
|
const [confirmingLeave, setConfirmingLeave] = React.useState<boolean>(false);
|
|
|
|
const [confirmingBlock, setConfirmingBlock] = React.useState<boolean>(false);
|
|
|
|
|
2021-04-05 17:44:13 +00:00
|
|
|
let leaveGroupNode = (
|
|
|
|
<PanelRow
|
|
|
|
disabled={cannotLeaveBecauseYouAreLastAdmin}
|
|
|
|
onClick={() => setConfirmingLeave(true)}
|
|
|
|
icon={
|
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={i18n('ConversationDetailsActions--leave-group')}
|
|
|
|
disabled={cannotLeaveBecauseYouAreLastAdmin}
|
|
|
|
icon="leave"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-conversation-details__leave-group',
|
|
|
|
cannotLeaveBecauseYouAreLastAdmin &&
|
|
|
|
'module-conversation-details__leave-group--disabled'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--leave-group')}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
if (cannotLeaveBecauseYouAreLastAdmin) {
|
|
|
|
leaveGroupNode = (
|
|
|
|
<Tooltip
|
|
|
|
content={i18n(
|
|
|
|
'ConversationDetailsActions--leave-group-must-choose-new-admin'
|
|
|
|
)}
|
|
|
|
direction={TooltipPlacement.Top}
|
|
|
|
>
|
|
|
|
{leaveGroupNode}
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PanelSection>
|
2021-04-05 17:44:13 +00:00
|
|
|
{leaveGroupNode}
|
2021-01-29 21:19:24 +00:00
|
|
|
<PanelRow
|
|
|
|
onClick={() => setConfirmingBlock(true)}
|
|
|
|
icon={
|
|
|
|
<ConversationDetailsIcon
|
|
|
|
ariaLabel={i18n('ConversationDetailsActions--block-group')}
|
|
|
|
icon="block"
|
|
|
|
/>
|
|
|
|
}
|
2021-02-01 22:57:42 +00:00
|
|
|
label={
|
|
|
|
<div className="module-conversation-details__block-group">
|
|
|
|
{i18n('ConversationDetailsActions--block-group')}
|
|
|
|
</div>
|
|
|
|
}
|
2021-01-29 21:19:24 +00:00
|
|
|
/>
|
|
|
|
</PanelSection>
|
|
|
|
|
|
|
|
{confirmingLeave && (
|
2021-04-27 19:29:59 +00:00
|
|
|
<ConfirmationDialog
|
2021-01-29 21:19:24 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n(
|
|
|
|
'ConversationDetailsActions--leave-group-modal-confirm'
|
|
|
|
),
|
2021-04-28 20:27:16 +00:00
|
|
|
action: onLeave,
|
2021-01-29 21:19:24 +00:00
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => setConfirmingLeave(false)}
|
|
|
|
title={i18n('ConversationDetailsActions--leave-group-modal-title')}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--leave-group-modal-content')}
|
2021-04-27 19:29:59 +00:00
|
|
|
</ConfirmationDialog>
|
2021-01-29 21:19:24 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
{confirmingBlock && (
|
2021-04-27 19:29:59 +00:00
|
|
|
<ConfirmationDialog
|
2021-01-29 21:19:24 +00:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n(
|
|
|
|
'ConversationDetailsActions--block-group-modal-confirm'
|
|
|
|
),
|
2021-04-28 20:27:16 +00:00
|
|
|
action: onBlock,
|
2021-01-29 21:19:24 +00:00
|
|
|
style: 'affirmative',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => setConfirmingBlock(false)}
|
|
|
|
title={i18n('ConversationDetailsActions--block-group-modal-title', [
|
|
|
|
conversationTitle,
|
|
|
|
])}
|
|
|
|
>
|
|
|
|
{i18n('ConversationDetailsActions--block-group-modal-content')}
|
2021-04-27 19:29:59 +00:00
|
|
|
</ConfirmationDialog>
|
2021-01-29 21:19:24 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|