1
- import { Fragment , useState } from 'react' ;
1
+ import { Fragment , useCallback , useState } from 'react' ;
2
2
import styled from '@emotion/styled' ;
3
3
import trimEnd from 'lodash/trimEnd' ;
4
4
@@ -148,7 +148,7 @@ function SudoModal({
148
148
}
149
149
} ;
150
150
151
- const handleSuccess = ( ) => {
151
+ const handleSuccess = useCallback ( ( ) => {
152
152
if ( isSuperuser ) {
153
153
navigate (
154
154
{ pathname : location . pathname , state : { forceUpdate : new Date ( ) } } ,
@@ -169,9 +169,9 @@ function SudoModal({
169
169
setState ( prevState => ( { ...prevState , showAccessForms : true } ) ) ;
170
170
closeModal ( ) ;
171
171
} ) ;
172
- } ;
172
+ } , [ closeModal , isSuperuser , location . pathname , navigate , needsReload , retryRequest ] ) ;
173
173
174
- const handleError = ( err : any ) => {
174
+ const handleError = useCallback ( ( err : any ) => {
175
175
let newErrorType = '' ; // Create a new variable to store the error type
176
176
177
177
if ( err . status === 403 ) {
@@ -196,16 +196,25 @@ function SudoModal({
196
196
errorType : newErrorType ,
197
197
showAccessForms : true ,
198
198
} ) ) ;
199
- } ;
200
-
201
- const handleWebAuthn = async ( data : WebAuthnParams ) => {
202
- data . isSuperuserModal = isSuperuser ;
203
- data . superuserAccessCategory = state . superuserAccessCategory ;
204
- data . superuserReason = state . superuserReason ;
205
- // It's ok to throw from here, u2fInterface will handle it.
206
- await api . requestPromise ( '/auth/' , { method : 'PUT' , data} ) ;
207
- handleSuccess ( ) ;
208
- } ;
199
+ } , [ ] ) ;
200
+
201
+ const handleWebAuthn = useCallback (
202
+ async ( data : WebAuthnParams ) => {
203
+ data . isSuperuserModal = isSuperuser ;
204
+ data . superuserAccessCategory = state . superuserAccessCategory ;
205
+ data . superuserReason = state . superuserReason ;
206
+ // It's ok to throw from here, u2fInterface will handle it.
207
+ await api . requestPromise ( '/auth/' , { method : 'PUT' , data} ) ;
208
+ handleSuccess ( ) ;
209
+ } ,
210
+ [
211
+ api ,
212
+ handleSuccess ,
213
+ isSuperuser ,
214
+ state . superuserAccessCategory ,
215
+ state . superuserReason ,
216
+ ]
217
+ ) ;
209
218
210
219
const getAuthLoginPath = ( ) : string => {
211
220
const authLoginPath = `/auth/login/?next=${ encodeURIComponent ( window . location . href ) } ` ;
0 commit comments