Show dialog if any non-admin labels when changing group info permission

This commit is contained in:
Scott Nonnenberg
2026-02-07 07:36:56 +10:00
committed by GitHub
parent ef071ccb36
commit a56698f480
7 changed files with 184 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import { SignalService as Proto } from '../../../protobuf/index.std.js';
import { PanelRow } from './PanelRow.dom.js';
import { PanelSection } from './PanelSection.dom.js';
import { Select } from '../../Select.dom.js';
import { AxoAlertDialog } from '../../../axo/AxoAlertDialog.dom.js';
export type PropsDataType = {
conversation?: ConversationType;
@@ -29,6 +30,10 @@ export function GroupV2Permissions({
setAccessControlMembersSetting,
setAnnouncementsOnly,
}: PropsType): React.JSX.Element {
const AccessControlEnum = Proto.AccessControl.AccessRequired;
const [isWarningAboutClearingLabels, setIsWarningAboutClearingLabels] =
React.useState(false);
const addMembersSelectId = useId();
const groupInfoSelectId = useId();
const announcementSelectId = useId();
@@ -36,14 +41,22 @@ export function GroupV2Permissions({
if (conversation === undefined) {
throw new Error('GroupV2Permissions rendered without a conversation');
}
const nonAdminsHaveLabels = conversation.memberships?.some(
membership => !membership.isAdmin && membership.labelString
);
const updateAccessControlAttributes = (value: string) => {
const newValue = Number(value);
if (newValue === AccessControlEnum.ADMINISTRATOR && nonAdminsHaveLabels) {
setIsWarningAboutClearingLabels(true);
return;
}
setAccessControlAttributesSetting(conversation.id, Number(value));
};
const updateAccessControlMembers = (value: string) => {
setAccessControlMembersSetting(conversation.id, Number(value));
};
const AccessControlEnum = Proto.AccessControl.AccessRequired;
const updateAnnouncementsOnly = (value: string) => {
setAnnouncementsOnly(
conversation.id,
@@ -113,6 +126,51 @@ export function GroupV2Permissions({
}
/>
)}
<AxoAlertDialog.Root
open={isWarningAboutClearingLabels}
onOpenChange={value => {
if (!value) {
setIsWarningAboutClearingLabels(false);
}
}}
>
<AxoAlertDialog.Content escape="cancel-is-noop">
<AxoAlertDialog.Body>
<AxoAlertDialog.Title>
{i18n('icu:ConversationDetails--label-clear-warning--title')}
</AxoAlertDialog.Title>
<AxoAlertDialog.Description>
{i18n(
'icu:ConversationDetails--label-clear-warning--description'
)}
</AxoAlertDialog.Description>
</AxoAlertDialog.Body>
<AxoAlertDialog.Footer>
<AxoAlertDialog.Action
variant="secondary"
arrow={false}
onClick={() => {
setIsWarningAboutClearingLabels(false);
}}
>
{i18n('icu:cancel')}
</AxoAlertDialog.Action>
<AxoAlertDialog.Action
variant="primary"
arrow={false}
onClick={() => {
setAccessControlAttributesSetting(
conversation.id,
AccessControlEnum.ADMINISTRATOR
);
setIsWarningAboutClearingLabels(false);
}}
>
{i18n('icu:ConversationDetails--label-clear-warning--continue')}
</AxoAlertDialog.Action>
</AxoAlertDialog.Footer>
</AxoAlertDialog.Content>
</AxoAlertDialog.Root>
</PanelSection>
);
}