@@ -91,13 +91,15 @@ export function Admin() {
9191
9292 const [ workflowId , setWorkflowId ] = useState ( '' )
9393 const [ targetWorkspaceId , setTargetWorkspaceId ] = useState ( '' )
94+ const [ impersonatingUserId , setImpersonatingUserId ] = useState < string | null > ( null )
95+ const isImpersonating = impersonatingUserId !== null || impersonateUser . isPending
9496 const discardImport = ( ) => {
9597 setWorkflowId ( '' )
9698 setTargetWorkspaceId ( '' )
9799 }
98100 const importGuard = useSettingsUnsavedGuard ( {
99101 isDirty : Boolean ( workflowId . trim ( ) || targetWorkspaceId . trim ( ) ) ,
100- navigationBlocked : importWorkflow . isPending ,
102+ navigationBlocked : importWorkflow . isPending || isImpersonating ,
101103 onDiscard : discardImport ,
102104 } )
103105
@@ -109,7 +111,6 @@ export function Admin() {
109111 const [ searchInput , setSearchInput ] = useState ( searchQuery )
110112 const [ pendingAction , setPendingAction ] = useState < PendingUserAction | null > ( null )
111113 const [ banReason , setBanReason ] = useState ( '' )
112- const [ impersonatingUserId , setImpersonatingUserId ] = useState < string | null > ( null )
113114 const [ impersonationGuardError , setImpersonationGuardError ] = useState < string | null > ( null )
114115 const [ isAddUserOpen , setIsAddUserOpen ] = useState ( false )
115116 const [ provisionWarning , setProvisionWarning ] = useState < string | null > ( null )
@@ -151,6 +152,7 @@ export function Admin() {
151152 }
152153
153154 const handleImpersonate = ( userId : string , email : string ) => {
155+ if ( isImpersonating || importWorkflow . isPending ) return
154156 setImpersonationGuardError ( null )
155157 if ( session ?. user ?. role !== 'admin' ) {
156158 setImpersonatingUserId ( null )
@@ -180,7 +182,7 @@ export function Admin() {
180182 const handleImport = ( ) => {
181183 const sourceId = workflowId . trim ( )
182184 const targetId = targetWorkspaceId . trim ( )
183- if ( ! sourceId || ! targetId || importWorkflow . isPending || impersonateUser . isPending ) return
185+ if ( ! sourceId || ! targetId || importWorkflow . isPending || isImpersonating ) return
184186 importWorkflow . mutate (
185187 { workflowId : sourceId , targetWorkspaceId : targetId } ,
186188 {
@@ -244,7 +246,7 @@ export function Admin() {
244246 < Chip
245247 aria-label = { `Impersonate ${ u . email } ` }
246248 onClick = { ( ) => handleImpersonate ( u . id , u . email ) }
247- disabled = { importWorkflow . isPending || pendingUserIds . has ( u . id ) }
249+ disabled = { importWorkflow . isPending || isImpersonating || pendingUserIds . has ( u . id ) }
248250 >
249251 { impersonatingUserId === u . id ? 'Switching...' : 'Impersonate' }
250252 </ Chip >
@@ -359,7 +361,7 @@ export function Admin() {
359361 importWorkflow . reset ( )
360362 } }
361363 placeholder = 'Source workflow ID'
362- disabled = { importWorkflow . isPending || impersonateUser . isPending }
364+ disabled = { importWorkflow . isPending || isImpersonating }
363365 />
364366 < ChipInput
365367 value = { targetWorkspaceId }
@@ -368,14 +370,14 @@ export function Admin() {
368370 importWorkflow . reset ( )
369371 } }
370372 placeholder = 'Target workspace ID'
371- disabled = { importWorkflow . isPending || impersonateUser . isPending }
373+ disabled = { importWorkflow . isPending || isImpersonating }
372374 />
373375 < Button
374376 variant = 'primary'
375377 onClick = { handleImport }
376378 disabled = {
377379 importWorkflow . isPending ||
378- impersonateUser . isPending ||
380+ isImpersonating ||
379381 ! workflowId . trim ( ) ||
380382 ! targetWorkspaceId . trim ( )
381383 }
0 commit comments