Skip to content

Commit e429457

Browse files
committed
fix(admin): confirm the role change the admin chose, not the live row's inverse
1 parent a639664 commit e429457

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/settings/components/admin

apps/sim/app/workspace/[workspaceId]/settings/components/admin/admin.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ const USER_TABLE_HEADER = (
5656
)
5757

5858
/**
59-
* The row action awaiting confirmation in {@link ChipConfirmModal}. Holds only
60-
* the id so the modal reads the live row — a background refetch while it is
61-
* open must not leave the confirm acting on a stale role.
59+
* The row action awaiting confirmation in {@link ChipConfirmModal}. Carries the
60+
* id plus, for a role change, the role the admin chose to apply — never the
61+
* whole user row. A refetch while the modal is open therefore refreshes the
62+
* name it shows without ever redirecting the action the admin committed to.
6263
*/
63-
interface PendingUserAction {
64-
type: 'ban' | 'role'
65-
userId: string
66-
}
64+
type PendingUserAction =
65+
| { type: 'ban'; userId: string }
66+
| { type: 'role'; userId: string; nextRole: 'admin' | 'user' }
6767

6868
const MOTHERSHIP_ENV_OPTIONS: { value: MothershipEnvironment; label: string }[] = [
6969
{ value: 'default', label: 'Default' },
@@ -184,7 +184,7 @@ export function Admin() {
184184
recentUsers?.find((u) => u.id === pendingAction.userId) ??
185185
null)
186186
: null
187-
const isDemotion = pendingUser?.role === 'admin'
187+
const isDemotion = pendingAction?.type === 'role' && pendingAction.nextRole === 'user'
188188

189189
const closePendingAction = () => {
190190
setPendingAction(null)
@@ -204,9 +204,9 @@ export function Admin() {
204204
}
205205

206206
const handleConfirmRoleChange = () => {
207-
if (pendingAction?.type !== 'role' || !pendingUser) return
207+
if (pendingAction?.type !== 'role') return
208208
setUserRole.mutate(
209-
{ userId: pendingUser.id, role: isDemotion ? 'user' : 'admin' },
209+
{ userId: pendingAction.userId, role: pendingAction.nextRole },
210210
{ onSuccess: closePendingAction }
211211
)
212212
}
@@ -258,7 +258,11 @@ export function Admin() {
258258
label: u.role === 'admin' ? 'Demote' : 'Promote',
259259
onSelect: () => {
260260
setUserRole.reset()
261-
setPendingAction({ type: 'role', userId: u.id })
261+
setPendingAction({
262+
type: 'role',
263+
userId: u.id,
264+
nextRole: u.role === 'admin' ? 'user' : 'admin',
265+
})
262266
},
263267
disabled: pendingUserIds.has(u.id),
264268
},

0 commit comments

Comments
 (0)