Skip to content

Commit

Permalink
Hide "leave group" button if you've already left
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal authored Sep 1, 2021
1 parent 0cb340f commit ce922ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export const ConversationDetails: React.ComponentType<Props> = ({
i18n={i18n}
cannotLeaveBecauseYouAreLastAdmin={cannotLeaveBecauseYouAreLastAdmin}
conversationTitle={conversation.title}
left={Boolean(conversation.left)}
onLeave={onLeave}
onBlock={onBlock}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
? overrideProps.cannotLeaveBecauseYouAreLastAdmin
: false,
conversationTitle: overrideProps.conversationTitle || '',
left: isBoolean(overrideProps.left) ? overrideProps.left : false,
onBlock: action('onBlock'),
onLeave: action('onLeave'),
i18n,
Expand All @@ -39,6 +40,12 @@ story.add('Basic', () => {
return <ConversationDetailsActions {...props} />;
});

story.add('Left the group', () => {
const props = createProps({ left: true });

return <ConversationDetailsActions {...props} />;
});

story.add('Cannot leave because you are the last admin', () => {
const props = createProps({ cannotLeaveBecauseYouAreLastAdmin: true });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import React from 'react';
import React, { ReactNode } from 'react';
import classNames from 'classnames';

import { LocalizerType } from '../../../types/Util';
Expand All @@ -15,6 +15,7 @@ import { ConversationDetailsIcon } from './ConversationDetailsIcon';
export type Props = {
cannotLeaveBecauseYouAreLastAdmin: boolean;
conversationTitle: string;
left: boolean;
onBlock: () => void;
onLeave: () => void;
i18n: LocalizerType;
Expand All @@ -23,48 +24,52 @@ export type Props = {
export const ConversationDetailsActions: React.ComponentType<Props> = ({
cannotLeaveBecauseYouAreLastAdmin,
conversationTitle,
left,
onBlock,
onLeave,
i18n,
}) => {
const [confirmingLeave, setConfirmingLeave] = React.useState<boolean>(false);
const [confirmingBlock, setConfirmingBlock] = React.useState<boolean>(false);

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) {
let leaveGroupNode: ReactNode;
if (!left) {
leaveGroupNode = (
<Tooltip
content={i18n(
'ConversationDetailsActions--leave-group-must-choose-new-admin'
)}
direction={TooltipPlacement.Top}
>
{leaveGroupNode}
</Tooltip>
<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>
);
}
}

return (
Expand Down

0 comments on commit ce922ee

Please sign in to comment.