11import React , { useEffect , useState , useMemo , useCallback , useRef } from 'react'
22import { useTranslation } from 'react-i18next'
3- import { useDispatch , useSelector } from 'react-redux'
3+ import { useDispatch , useSelector , useStore } from 'react-redux'
44import { useQueryClient } from '@tanstack/react-query'
55import { useFormik , setIn } from 'formik'
66import * as Yup from 'yup'
@@ -29,12 +29,7 @@ import { CEDAR_RESOURCE_SCOPES } from '@/cedarling/constants/resourceScopes'
2929import { ADMIN_UI_RESOURCES } from '@/cedarling/utility'
3030import { useAppNavigation , ROUTES } from '@/helpers/navigation'
3131import { useAcrAudit } from '../AuthN/hooks'
32- import {
33- generateLabel ,
34- isRenamedKey ,
35- renamedFieldFromObject ,
36- useAuthServerPropertiesActions ,
37- } from './Properties/utils'
32+ import { generateLabel , isRenamedKey , renamedFieldFromObject } from './Properties/utils'
3833import { createAppConfigurationSchema } from './Properties/utils/validations'
3934import type { AppConfiguration , RootState , JsonPatch , AcrPutOperation , Script } from './types'
4035import type { GluuCommitDialogOperation , JsonValue } from 'Routes/Apps/Gluu/types/index'
@@ -45,12 +40,13 @@ const AuthPage: React.FC = () => {
4540 SetTitle ( t ( 'titles.jans_json_property' ) )
4641
4742 const dispatch = useDispatch ( )
43+ const store = useStore ( )
4844 const queryClient = useQueryClient ( )
4945 const { navigateBack } = useAppNavigation ( )
5046 const { hasCedarWritePermission, authorizeHelper } = useCedarling ( )
51- const { logAuthServerPropertiesUpdate } = useAuthServerPropertiesActions ( )
5247 const { logAcrUpdate } = useAcrAudit ( )
5348 const configuration = useSelector ( ( state : RootState ) => state . jsonConfigReducer . configuration )
49+ const jsonConfigLoading = useSelector ( ( state : RootState ) => state . jsonConfigReducer . loading )
5450 const scripts = useSelector ( ( state : RootState ) => state . initReducer . scripts )
5551 const { data : acrs , isLoading : acrLoading } = useGetAcrs ( {
5652 query : { staleTime : 30000 } ,
@@ -294,6 +290,16 @@ const AuthPage: React.FC = () => {
294290 } as unknown as ActionData
295291 buildPayload ( userAction , message , postBody )
296292 dispatch ( patchJsonConfig ( { action : userAction } ) )
293+ await new Promise < void > ( ( resolve ) => {
294+ const unsub = store . subscribe ( ( ) => {
295+ const loading = ( store . getState ( ) as { jsonConfigReducer ?: { loading ?: boolean } } )
296+ ?. jsonConfigReducer ?. loading
297+ if ( ! loading ) {
298+ unsub ( )
299+ resolve ( )
300+ }
301+ } )
302+ } )
297303 }
298304 if ( put && put . value ) {
299305 const newAcr = { defaultAcr : put . value || acrs ?. defaultAcr }
@@ -304,21 +310,8 @@ const AuthPage: React.FC = () => {
304310 console . error ( 'Error updating ACR:' , error )
305311 }
306312 }
307- let auditSuccess = true
308- try {
309- const auditPayload = {
310- requestBody : patches ,
311- ...( put && put . value ? { defaultAcr : put . value } : { } ) ,
312- }
313- auditSuccess = await logAuthServerPropertiesUpdate ( message , auditPayload )
314- } catch ( auditError ) {
315- console . error ( 'Error logging audit:' , auditError )
316- auditSuccess = false
317- }
318- if ( auditSuccess ) {
313+ if ( patches . length === 0 ) {
319314 toast . success ( t ( 'messages.success_in_saving' ) )
320- } else {
321- toast . warning ( t ( 'messages.success_in_saving_audit_failed' ) )
322315 }
323316 } catch ( err ) {
324317 console . error ( 'Error updating auth server properties:' , err )
@@ -327,18 +320,19 @@ const AuthPage: React.FC = () => {
327320 toast . error ( errorMsg )
328321 }
329322 } ,
330- [ patches , put , acrs , dispatch , putAcrsMutation , logAcrUpdate , logAuthServerPropertiesUpdate , t ] ,
323+ [ patches , put , acrs , dispatch , store , putAcrsMutation , logAcrUpdate , t ] ,
331324 )
332325 const submitForm = useCallback (
333326 async ( message : string ) => {
334- toggle ( )
335327 await handleSubmit ( message )
336328 } ,
337- [ toggle , handleSubmit ] ,
329+ [ handleSubmit ] ,
338330 )
339331
340332 return (
341- < GluuLoader blocking = { isConfigEmpty || acrLoading || putAcrsMutation . isPending } >
333+ < GluuLoader
334+ blocking = { isConfigEmpty || acrLoading || putAcrsMutation . isPending || jsonConfigLoading }
335+ >
342336 < Card style = { { borderRadius : 24 } } >
343337 < CardHeader >
344338 < div style = { { display : 'flex' } } >
0 commit comments