signal-desktop/ts/components/conversation/conversation-details/GroupLinkManagement.tsx

144 lines
4.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { ConversationDetailsIcon } from './ConversationDetailsIcon';
2021-07-09 19:36:10 +00:00
import { SignalService as Proto } from '../../../protobuf';
import { ConversationType } from '../../../state/ducks/conversations';
import { LocalizerType } from '../../../types/Util';
import { PanelRow } from './PanelRow';
import { PanelSection } from './PanelSection';
import { Select } from '../../Select';
2021-07-09 19:36:10 +00:00
const AccessControlEnum = Proto.AccessControl.AccessRequired;
export type PropsType = {
changeHasGroupLink: (value: boolean) => void;
conversation?: ConversationType;
copyGroupLink: (groupLink: string) => void;
generateNewGroupLink: () => void;
i18n: LocalizerType;
2021-03-02 16:27:11 +00:00
isAdmin: boolean;
setAccessControlAddFromInviteLinkSetting: (value: boolean) => void;
};
export const GroupLinkManagement: React.ComponentType<PropsType> = ({
changeHasGroupLink,
conversation,
copyGroupLink,
generateNewGroupLink,
i18n,
2021-03-02 16:27:11 +00:00
isAdmin,
setAccessControlAddFromInviteLinkSetting,
}) => {
if (conversation === undefined) {
throw new Error('GroupLinkManagement rendered without a conversation');
}
const createEventHandler = (handleEvent: (x: boolean) => void) => {
return (value: string) => {
handleEvent(value === 'true');
};
};
const membersNeedAdminApproval =
2021-07-09 19:36:10 +00:00
conversation.accessControlAddFromInviteLink ===
AccessControlEnum.ADMINISTRATOR;
const hasGroupLink =
conversation.groupLink &&
2021-07-09 19:36:10 +00:00
conversation.accessControlAddFromInviteLink !==
AccessControlEnum.UNSATISFIABLE;
const groupLinkInfo = hasGroupLink ? conversation.groupLink : '';
return (
<>
<PanelSection>
<PanelRow
info={groupLinkInfo}
label={i18n('ConversationDetails--group-link')}
right={
2021-03-02 16:27:11 +00:00
isAdmin ? (
<Select
onChange={createEventHandler(changeHasGroupLink)}
options={[
{
text: i18n('on'),
value: 'true',
},
{
text: i18n('off'),
value: 'false',
},
]}
value={String(Boolean(hasGroupLink))}
/>
2021-03-02 16:27:11 +00:00
) : null
}
/>
</PanelSection>
{hasGroupLink ? (
<>
<PanelSection>
<PanelRow
icon={
<ConversationDetailsIcon
ariaLabel={i18n('GroupLinkManagement--share')}
icon="share"
/>
}
label={i18n('GroupLinkManagement--share')}
onClick={() => {
if (conversation.groupLink) {
copyGroupLink(conversation.groupLink);
}
}}
/>
2021-03-02 16:27:11 +00:00
{isAdmin ? (
<PanelRow
icon={
<ConversationDetailsIcon
ariaLabel={i18n('GroupLinkManagement--reset')}
icon="reset"
/>
}
label={i18n('GroupLinkManagement--reset')}
onClick={generateNewGroupLink}
/>
) : null}
</PanelSection>
2021-03-02 16:27:11 +00:00
{isAdmin ? (
<PanelSection>
<PanelRow
info={i18n('GroupLinkManagement--approve-info')}
label={i18n('GroupLinkManagement--approve-label')}
right={
<Select
onChange={createEventHandler(
setAccessControlAddFromInviteLinkSetting
)}
options={[
{
text: i18n('on'),
value: 'true',
},
{
text: i18n('off'),
value: 'false',
},
]}
value={String(membersNeedAdminApproval)}
/>
2021-03-02 16:27:11 +00:00
}
/>
</PanelSection>
) : null}
</>
) : null}
</>
);
};