mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
Stage the ban and put the user switches on one row
The Banned switch is now a staged edit like the roles and ban reason, so Apply sends one ban that includes the reason. The ban reason only shows while Banned is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6b44e78d6
commit
555f444447
1 file changed
+43
-39
@@ -67,10 +67,13 @@ export default function UserViewPage() {
|
|||||||
});
|
});
|
||||||
// Local edits on top of the live user
|
// Local edits on top of the live user
|
||||||
const [rolesEdit, setRolesEdit] = useState<number[]>();
|
const [rolesEdit, setRolesEdit] = useState<number[]>();
|
||||||
|
const [bannedEdit, setBannedEdit] = useState<boolean>();
|
||||||
const [banReasonEdit, setBanReasonEdit] = useState<string>();
|
const [banReasonEdit, setBanReasonEdit] = useState<string>();
|
||||||
const [applying, setApplying] = useState(false);
|
const [applying, setApplying] = useState(false);
|
||||||
const canUpdateRoles = account.hasPermission("core.user.update_roles");
|
const canUpdateRoles = account.hasPermission("core.user.update_roles");
|
||||||
const canBan = account.hasPermission("core.user.set_banned");
|
const canBan = account.hasPermission("core.user.set_banned");
|
||||||
|
const canSetAdmin = account.hasPermission("core.user.set_admin");
|
||||||
|
const canSetWhitelisted = account.hasPermission("core.user.set_whitelisted");
|
||||||
|
|
||||||
// Drop edits that now match the user, and roles deleted since
|
// Drop edits that now match the user, and roles deleted since
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -81,11 +84,13 @@ export default function UserViewPage() {
|
|||||||
const next = prev?.filter(id => !rolesSynced || roles.has(id));
|
const next = prev?.filter(id => !rolesSynced || roles.has(id));
|
||||||
return next && sameIds(next, user.roleIds) ? undefined : next;
|
return next && sameIds(next, user.roleIds) ? undefined : next;
|
||||||
});
|
});
|
||||||
|
setBannedEdit(prev => (prev === user.isBanned ? undefined : prev));
|
||||||
setBanReasonEdit(prev => (prev === user.banReason ? undefined : prev));
|
setBanReasonEdit(prev => (prev === user.banReason ? undefined : prev));
|
||||||
}, [user, roles, rolesSynced]);
|
}, [user, roles, rolesSynced]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRolesEdit(undefined);
|
setRolesEdit(undefined);
|
||||||
|
setBannedEdit(undefined);
|
||||||
setBanReasonEdit(undefined);
|
setBanReasonEdit(undefined);
|
||||||
}, [userName]);
|
}, [userName]);
|
||||||
|
|
||||||
@@ -95,13 +100,14 @@ export default function UserViewPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roleIds = rolesEdit ?? [...user.roleIds];
|
const roleIds = rolesEdit ?? [...user.roleIds];
|
||||||
const banReason = banReasonEdit ?? user.banReason;
|
const banned = bannedEdit ?? user.isBanned;
|
||||||
|
const banReason = banned ? banReasonEdit ?? user.banReason : "";
|
||||||
const rolesChanged = rolesEdit !== undefined && !sameIds(rolesEdit, user.roleIds);
|
const rolesChanged = rolesEdit !== undefined && !sameIds(rolesEdit, user.roleIds);
|
||||||
// Only a banned user has a ban reason to update, otherwise it is used by the Banned switch
|
const banChanged = banned !== user.isBanned || banReason !== user.banReason;
|
||||||
const banReasonChanged = user.isBanned && banReason !== user.banReason;
|
|
||||||
|
|
||||||
function revertChanges() {
|
function revertChanges() {
|
||||||
setRolesEdit(undefined);
|
setRolesEdit(undefined);
|
||||||
|
setBannedEdit(undefined);
|
||||||
setBanReasonEdit(undefined);
|
setBanReasonEdit(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +116,9 @@ export default function UserViewPage() {
|
|||||||
await control.send(new lib.UserUpdateRolesRequest(userName, roleIds));
|
await control.send(new lib.UserUpdateRolesRequest(userName, roleIds));
|
||||||
setRolesEdit(undefined);
|
setRolesEdit(undefined);
|
||||||
}
|
}
|
||||||
if (banReasonChanged) {
|
if (banChanged) {
|
||||||
await control.send(new lib.UserSetBannedRequest(userName, false, true, banReason));
|
await control.send(new lib.UserSetBannedRequest(userName, false, banned, banReason));
|
||||||
|
setBannedEdit(undefined);
|
||||||
setBanReasonEdit(undefined);
|
setBanReasonEdit(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +187,7 @@ export default function UserViewPage() {
|
|||||||
<UserPluginActions user={user} />
|
<UserPluginActions user={user} />
|
||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
{(rolesChanged || banReasonChanged) && <UnsavedChangesBar
|
{(rolesChanged || banChanged) && <UnsavedChangesBar
|
||||||
applying={applying}
|
applying={applying}
|
||||||
onRevert={revertChanges}
|
onRevert={revertChanges}
|
||||||
onApply={() => {
|
onApply={() => {
|
||||||
@@ -201,43 +208,40 @@ export default function UserViewPage() {
|
|||||||
options={[...roles.values()].map(r => ({ value: r.id, label: r.name }))}
|
options={[...roles.values()].map(r => ({ value: r.id, label: r.name }))}
|
||||||
/>
|
/>
|
||||||
</FieldRow>
|
</FieldRow>
|
||||||
{account.hasPermission("core.user.set_admin") && <FieldRow label="In-game Admin">
|
{(canSetAdmin || canSetWhitelisted || canBan) && <FieldRow label="Status">
|
||||||
<Switch
|
<Space size="large" wrap>
|
||||||
checked={user.isAdmin}
|
{canSetAdmin && <label><Space>
|
||||||
onClick={() => {
|
In-game Admin
|
||||||
control.send(
|
<Switch
|
||||||
new lib.UserSetAdminRequest(userName, false, !user.isAdmin)
|
checked={user.isAdmin}
|
||||||
).catch(notifyErrorHandler("Error toggling user admin status"));
|
onClick={() => {
|
||||||
}}
|
control.send(
|
||||||
/>
|
new lib.UserSetAdminRequest(userName, false, !user.isAdmin)
|
||||||
|
).catch(notifyErrorHandler("Error toggling user admin status"));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space></label>}
|
||||||
|
{canSetWhitelisted && <label><Space>
|
||||||
|
Whitelisted
|
||||||
|
<Switch
|
||||||
|
checked={user.isWhitelisted}
|
||||||
|
onClick={() => {
|
||||||
|
control.send(
|
||||||
|
new lib.UserSetWhitelistedRequest(userName, false, !user.isWhitelisted)
|
||||||
|
).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Space></label>}
|
||||||
|
{canBan && <label><Space>
|
||||||
|
Banned
|
||||||
|
<Switch checked={banned} onClick={() => setBannedEdit(!banned)} />
|
||||||
|
</Space></label>}
|
||||||
|
</Space>
|
||||||
</FieldRow>}
|
</FieldRow>}
|
||||||
{account.hasPermission("core.user.set_whitelisted") && <FieldRow label="Whitelisted">
|
{banned && <FieldRow label="Ban reason">
|
||||||
<Switch
|
|
||||||
checked={user.isWhitelisted}
|
|
||||||
onClick={() => {
|
|
||||||
control.send(
|
|
||||||
new lib.UserSetWhitelistedRequest(userName, false, !user.isWhitelisted)
|
|
||||||
).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FieldRow>}
|
|
||||||
{canBan && <FieldRow label="Banned">
|
|
||||||
<Switch
|
|
||||||
checked={user.isBanned}
|
|
||||||
onClick={() => {
|
|
||||||
control.send(new lib.UserSetBannedRequest(
|
|
||||||
userName, false, !user.isBanned, user.isBanned ? "" : banReason
|
|
||||||
)).then(() => {
|
|
||||||
setBanReasonEdit(undefined);
|
|
||||||
}).catch(notifyErrorHandler(user.isBanned ? "Error unbanning user" : "Error banning user"));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FieldRow>}
|
|
||||||
{(canBan || user.isBanned) && <FieldRow label="Ban reason">
|
|
||||||
<Input
|
<Input
|
||||||
value={banReason}
|
value={banReason}
|
||||||
disabled={!canBan}
|
disabled={!canBan}
|
||||||
placeholder={user.isBanned ? undefined : "Reason given when the user is banned"}
|
|
||||||
onChange={e => setBanReasonEdit(e.target.value)}
|
onChange={e => setBanReasonEdit(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</FieldRow>}
|
</FieldRow>}
|
||||||
|
|||||||
Reference in new issue
Block a user