Use the JoinRuleSettings component for the guest link access prompt.
Co-authored-by: fkwp <fkwp@users.noreply.github.com>
This commit is contained in:
parent
d8ebc68aa8
commit
3633dbc5cb
5 changed files with 64 additions and 35 deletions
|
@ -36,6 +36,9 @@ export interface JoinRuleSettingsProps {
|
|||
onError(error: unknown): void;
|
||||
beforeChange?(joinRule: JoinRule): Promise<boolean>; // if returns false then aborts the change
|
||||
aliasWarning?: ReactNode;
|
||||
disabledOptions?: Set<JoinRule>;
|
||||
hiddenOptions?: Set<JoinRule>;
|
||||
recommendedOption?: JoinRule;
|
||||
}
|
||||
|
||||
const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
||||
|
@ -45,6 +48,9 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
onError,
|
||||
beforeChange,
|
||||
closeSettingsFn,
|
||||
disabledOptions,
|
||||
hiddenOptions,
|
||||
recommendedOption,
|
||||
}) => {
|
||||
const cli = room.client;
|
||||
|
||||
|
@ -147,7 +153,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
}
|
||||
});
|
||||
|
||||
closeSettingsFn();
|
||||
closeSettingsFn?.();
|
||||
|
||||
// switch to the new room in the background
|
||||
dis.dispatch<ViewRoomPayload>({
|
||||
|
@ -170,18 +176,26 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
{_t("room_settings|security|join_rule_upgrade_required")}
|
||||
</span>
|
||||
);
|
||||
const withRecommendLabel = (label: string, rule: JoinRule): React.ReactNode =>
|
||||
rule === recommendedOption ? (
|
||||
<>
|
||||
{label} (<span className="mx_JoinRuleSettings_recommended">{_t("common|recommended")}</span>)
|
||||
</>
|
||||
) : (
|
||||
label
|
||||
);
|
||||
|
||||
const definitions: IDefinition<JoinRule>[] = [
|
||||
{
|
||||
value: JoinRule.Invite,
|
||||
label: _t("room_settings|security|join_rule_invite"),
|
||||
label: withRecommendLabel(_t("room_settings|security|join_rule_invite"), JoinRule.Invite),
|
||||
description: _t("room_settings|security|join_rule_invite_description"),
|
||||
checked:
|
||||
joinRule === JoinRule.Invite || (joinRule === JoinRule.Restricted && !restrictedAllowRoomIds?.length),
|
||||
},
|
||||
{
|
||||
value: JoinRule.Public,
|
||||
label: _t("common|public"),
|
||||
label: withRecommendLabel(_t("common|public"), JoinRule.Public),
|
||||
description: (
|
||||
<>
|
||||
{_t("room_settings|security|join_rule_public_description")}
|
||||
|
@ -292,7 +306,7 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
value: JoinRule.Restricted,
|
||||
label: (
|
||||
<>
|
||||
{_t("room_settings|security|join_rule_restricted")}
|
||||
{withRecommendLabel(_t("room_settings|security|join_rule_restricted"), JoinRule.Restricted)}
|
||||
{preferredRestrictionVersion && upgradeRequiredPill}
|
||||
</>
|
||||
),
|
||||
|
@ -303,11 +317,11 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
}
|
||||
|
||||
if (askToJoinEnabled && (roomSupportsKnock || preferredKnockVersion)) {
|
||||
definitions.push({
|
||||
definitions.splice(Math.max(0, definitions.length - 1), 0, {
|
||||
value: JoinRule.Knock,
|
||||
label: (
|
||||
<>
|
||||
{_t("room_settings|security|join_rule_knock")}
|
||||
{withRecommendLabel(_t("room_settings|security|join_rule_knock"), JoinRule.Knock)}
|
||||
{preferredKnockVersion && upgradeRequiredPill}
|
||||
</>
|
||||
),
|
||||
|
@ -397,7 +411,9 @@ const JoinRuleSettings: React.FC<JoinRuleSettingsProps> = ({
|
|||
name="joinRule"
|
||||
value={joinRule}
|
||||
onChange={onChange}
|
||||
definitions={definitions}
|
||||
definitions={definitions
|
||||
.map((d) => (disabledOptions?.has(d.value) ? { ...d, disabled: true } : d))
|
||||
.filter((d) => !hiddenOptions?.has(d.value))}
|
||||
disabled={disabled}
|
||||
className="mx_JoinRuleSettings_radioButton"
|
||||
/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue