Skip to content

Commit fec89ef

Browse files
committed
fix(admin): fix stale pendingUserId, add isPending guard and error feedback
- Only read mutation.variables when mutation isPending (prevents stale ID) - Add isPending guard to super user mode toggle (prevents concurrent mutations) - Show inline error message when setRole/ban/unban mutations fail
1 parent ea6b1f8 commit fec89ef

File tree

1 file changed

+11
-5
lines changed
  • apps/sim/app/workspace/[workspaceId]/settings/components/admin

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function Admin() {
4949
const currentPage = useMemo(() => Math.floor(usersOffset / PAGE_SIZE) + 1, [usersOffset])
5050

5151
const handleSuperUserModeToggle = async (checked: boolean) => {
52-
if (checked !== settings?.superUserModeEnabled) {
52+
if (checked !== settings?.superUserModeEnabled && !updateSetting.isPending) {
5353
await updateSetting.mutateAsync({ key: 'superUserModeEnabled', value: checked })
5454
}
5555
}
@@ -72,11 +72,10 @@ export function Admin() {
7272

7373
const actionPending = setUserRole.isPending || banUser.isPending || unbanUser.isPending
7474
const pendingUserId =
75-
(setUserRole.variables as { userId?: string })?.userId ??
76-
(banUser.variables as { userId?: string })?.userId ??
77-
(unbanUser.variables as { userId?: string })?.userId ??
75+
(setUserRole.isPending ? (setUserRole.variables as { userId?: string })?.userId : undefined) ??
76+
(banUser.isPending ? (banUser.variables as { userId?: string })?.userId : undefined) ??
77+
(unbanUser.isPending ? (unbanUser.variables as { userId?: string })?.userId : undefined) ??
7878
null
79-
8079
return (
8180
<div className='flex h-full flex-col gap-[24px]'>
8281
<div className='flex items-center justify-between'>
@@ -139,6 +138,13 @@ export function Admin() {
139138
</p>
140139
)}
141140

141+
{(setUserRole.error || banUser.error || unbanUser.error) && (
142+
<p className='text-[13px] text-[var(--text-error)]'>
143+
{(setUserRole.error || banUser.error || unbanUser.error)?.message ??
144+
'Action failed. Please try again.'}
145+
</p>
146+
)}
147+
142148
{usersLoading && !usersData && (
143149
<div className='flex flex-col gap-[8px]'>
144150
{Array.from({ length: 5 }).map((_, i) => (

0 commit comments

Comments
 (0)