@@ -10,7 +10,11 @@ import { Button, Span } from 'honorable'
10
10
import { useContext , useMemo , useState } from 'react'
11
11
12
12
import CurrentUserContext from '../../contexts/CurrentUserContext'
13
- import { Permission , useUpdateUserMutation } from '../../generated/graphql'
13
+ import {
14
+ Permission ,
15
+ useImpersonateServiceAccountMutation ,
16
+ useUpdateUserMutation ,
17
+ } from '../../generated/graphql'
14
18
import {
15
19
fetchToken ,
16
20
setPreviousUserData ,
@@ -25,6 +29,7 @@ import { EditServiceAccount } from './CreateServiceAccount'
25
29
import { MoreMenu } from './MoreMenu'
26
30
import { IMPERSONATE_SERVICE_ACCOUNT } from './queries'
27
31
import { hasRbac } from './utils'
32
+ import useImpersonatedServiceAccount from '../../hooks/useImpersonatedServiceAccount'
28
33
29
34
export function UserInfo ( {
30
35
user : { email, name, avatar } ,
@@ -185,21 +190,11 @@ export function User({ user, update }: any) {
185
190
export function ServiceAccount ( { user, update } : any ) {
186
191
const me = useContext ( CurrentUserContext )
187
192
const editable = canEdit ( me , me . account ) || hasRbac ( me , Permission . Users )
188
- const [ mutation , { error } ] = useMutation ( IMPERSONATE_SERVICE_ACCOUNT , {
193
+ const [ mutation , { error } ] = useImpersonateServiceAccountMutation ( {
189
194
variables : { id : user . id } ,
190
- update : (
191
- _cache ,
192
- {
193
- data : {
194
- impersonateServiceAccount : { jwt } ,
195
- } ,
196
- }
197
- ) => {
198
- setPreviousUserData ( {
199
- me,
200
- jwt : fetchToken ( ) ,
201
- } )
202
- setToken ( jwt )
195
+ update : ( _cache , { data } ) => {
196
+ setPreviousUserData ( { me, jwt : fetchToken ( ) } )
197
+ setToken ( data ?. impersonateServiceAccount ?. jwt )
203
198
; ( window as Window ) . location = '/'
204
199
} ,
205
200
} )
0 commit comments