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

123 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { ConversationType } from '../../../state/ducks/conversations';
import type { LocalizerType } from '../../../types/Util';
import { getAccessControlOptions } from '../../../util/getAccessControlOptions';
2021-07-20 20:18:35 +00:00
import { SignalService as Proto } from '../../../protobuf';
import { PanelRow } from './PanelRow';
import { PanelSection } from './PanelSection';
import { Select } from '../../Select';
import { useUniqueId } from '../../../hooks/useUniqueId';
export type PropsDataType = {
conversation?: ConversationType;
i18n: LocalizerType;
};
type PropsActionType = {
setAccessControlAttributesSetting: (id: string, value: number) => void;
setAccessControlMembersSetting: (id: string, value: number) => void;
setAnnouncementsOnly: (id: string, value: boolean) => void;
};
export type PropsType = PropsDataType & PropsActionType;
2022-11-18 00:45:19 +00:00
export function GroupV2Permissions({
conversation,
i18n,
setAccessControlAttributesSetting,
setAccessControlMembersSetting,
2021-07-20 20:18:35 +00:00
setAnnouncementsOnly,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
const addMembersSelectId = useUniqueId();
const groupInfoSelectId = useUniqueId();
const announcementSelectId = useUniqueId();
if (conversation === undefined) {
throw new Error('GroupV2Permissions rendered without a conversation');
}
const updateAccessControlAttributes = (value: string) => {
setAccessControlAttributesSetting(conversation.id, Number(value));
};
const updateAccessControlMembers = (value: string) => {
setAccessControlMembersSetting(conversation.id, Number(value));
};
2021-07-20 20:18:35 +00:00
const AccessControlEnum = Proto.AccessControl.AccessRequired;
const updateAnnouncementsOnly = (value: string) => {
setAnnouncementsOnly(
conversation.id,
Number(value) === AccessControlEnum.ADMINISTRATOR
);
2021-07-20 20:18:35 +00:00
};
2021-07-09 19:36:10 +00:00
const accessControlOptions = getAccessControlOptions(i18n);
2021-07-20 20:18:35 +00:00
const announcementsOnlyValue = String(
conversation.announcementsOnly
? AccessControlEnum.ADMINISTRATOR
: AccessControlEnum.MEMBER
);
const showAnnouncementsOnlyPermission =
conversation.areWeAdmin &&
(conversation.announcementsOnly || conversation.announcementsOnlyReady);
return (
<PanelSection>
<PanelRow
label={
<label htmlFor={addMembersSelectId}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ConversationDetails--add-members-label')}
</label>
}
2023-03-30 00:03:25 +00:00
info={i18n('icu:ConversationDetails--add-members-info')}
right={
<Select
id={addMembersSelectId}
onChange={updateAccessControlMembers}
options={accessControlOptions}
value={String(conversation.accessControlMembers)}
/>
}
/>
<PanelRow
label={
<label htmlFor={groupInfoSelectId}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ConversationDetails--group-info-label')}
</label>
}
2023-03-30 00:03:25 +00:00
info={i18n('icu:ConversationDetails--group-info-info')}
right={
<Select
id={groupInfoSelectId}
onChange={updateAccessControlAttributes}
options={accessControlOptions}
value={String(conversation.accessControlAttributes)}
/>
}
/>
{showAnnouncementsOnlyPermission && (
2021-07-20 20:18:35 +00:00
<PanelRow
label={
<label htmlFor={announcementSelectId}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ConversationDetails--announcement-label')}
</label>
}
2023-03-30 00:03:25 +00:00
info={i18n('icu:ConversationDetails--announcement-info')}
2021-07-20 20:18:35 +00:00
right={
<Select
id={announcementSelectId}
2021-07-20 20:18:35 +00:00
onChange={updateAnnouncementsOnly}
options={accessControlOptions}
value={announcementsOnlyValue}
/>
}
/>
)}
</PanelSection>
);
2022-11-18 00:45:19 +00:00
}