1
- import React , { useEffect } from ' react'
2
- import { useDispatch , useSelector } from ' react-redux'
3
- import { useNavigate } from ' react-router-dom'
4
- import { CardBody , Card } from ' Components'
5
- import ScopeForm from ' ./ScopeForm'
6
- import { addScope } from ' Plugins/auth-server/redux/features/scopeSlice'
7
- import { buildPayload } from ' Utils/PermChecker'
8
- import GluuLoader from ' Routes/Apps/Gluu/GluuLoader'
9
- import { getAttributes , getScripts } from ' Redux/features/initSlice'
10
- import GluuAlert from ' Routes/Apps/Gluu/GluuAlert'
11
- import { useTranslation } from ' react-i18next'
12
- import applicationStyle from ' Routes/Apps/Gluu/styles/applicationstyle'
1
+ import React , { useEffect } from " react" ;
2
+ import { useDispatch , useSelector } from " react-redux" ;
3
+ import { useNavigate } from " react-router-dom" ;
4
+ import { CardBody , Card } from " Components" ;
5
+ import ScopeForm from " ./ScopeForm" ;
6
+ import { addScope } from " Plugins/auth-server/redux/features/scopeSlice" ;
7
+ import { buildPayload } from " Utils/PermChecker" ;
8
+ import GluuLoader from " Routes/Apps/Gluu/GluuLoader" ;
9
+ import { getAttributes , getScripts } from " Redux/features/initSlice" ;
10
+ import GluuAlert from " Routes/Apps/Gluu/GluuAlert" ;
11
+ import { useTranslation } from " react-i18next" ;
12
+ import applicationStyle from " Routes/Apps/Gluu/styles/applicationstyle" ;
13
13
14
14
function ScopeAddPage ( ) {
15
- const loading = useSelector ( ( state ) => state . scopeReducer . loading )
16
- const scripts = useSelector ( ( state ) => state . initReducer . scripts )
17
- const attributes = useSelector ( ( state ) => state . initReducer . attributes )
18
- const saveOperationFlag = useSelector ( ( state ) => state . scopeReducer . saveOperationFlag )
19
- const errorInSaveOperationFlag = useSelector ( ( state ) => state . scopeReducer . errorInSaveOperationFlag )
15
+ const loading = useSelector ( ( state ) => state . scopeReducer . loading ) ;
16
+ const scripts = useSelector ( ( state ) => state . initReducer . scripts ) ;
17
+ const attributes = useSelector ( ( state ) => state . initReducer . attributes ) ;
18
+ const saveOperationFlag = useSelector (
19
+ ( state ) => state . scopeReducer . saveOperationFlag
20
+ ) ;
21
+ const errorInSaveOperationFlag = useSelector (
22
+ ( state ) => state . scopeReducer . errorInSaveOperationFlag
23
+ ) ;
20
24
21
- const dispatch = useDispatch ( )
25
+ const dispatch = useDispatch ( ) ;
22
26
23
- const userAction = { }
24
- const navigate = useNavigate ( )
25
- const { t } = useTranslation ( )
27
+ const userAction = { } ;
28
+ const navigate = useNavigate ( ) ;
29
+ const { t } = useTranslation ( ) ;
26
30
useEffect ( ( ) => {
27
31
if ( attributes . length === 0 ) {
28
- buildPayload ( userAction , 'Fetch attributes' , { limit : 100 } )
29
- dispatch ( getAttributes ( { options : userAction } ) )
32
+ buildPayload ( userAction , "Fetch attributes" , { limit : 100 } ) ;
33
+ console . log ( "userAction" , userAction ) ;
34
+ dispatch ( getAttributes ( { options : userAction } ) ) ;
30
35
}
31
36
if ( scripts . length === 0 ) {
32
- buildPayload ( userAction , ' Fetch custom scripts' , { } )
33
- dispatch ( getScripts ( { action : userAction } ) )
37
+ buildPayload ( userAction , " Fetch custom scripts" , { } ) ;
38
+ dispatch ( getScripts ( { action : userAction } ) ) ;
34
39
}
35
- } , [ ] )
40
+ } , [ ] ) ;
36
41
37
42
useEffect ( ( ) => {
38
43
if ( saveOperationFlag && ! errorInSaveOperationFlag )
39
- navigate ( ' /auth-server/scopes' )
40
- } , [ saveOperationFlag ] )
44
+ navigate ( " /auth-server/scopes" ) ;
45
+ } , [ saveOperationFlag ] ) ;
41
46
42
47
function handleSubmit ( data ) {
43
48
if ( data ) {
44
- const postBody = { }
45
- data = JSON . parse ( data )
46
- const message = data . action_message
47
- delete data . action_message
48
- postBody [ ' scope' ] = data
49
- buildPayload ( userAction , message , postBody )
50
- dispatch ( addScope ( { action : userAction } ) )
49
+ const postBody = { } ;
50
+ data = JSON . parse ( data ) ;
51
+ const message = data . action_message ;
52
+ delete data . action_message ;
53
+ postBody [ " scope" ] = data ;
54
+ buildPayload ( userAction , message , postBody ) ;
55
+ dispatch ( addScope ( { action : userAction } ) ) ;
51
56
}
52
57
}
53
58
59
+ const handleSearch = ( value ) => {
60
+ const option = {
61
+ pattern :value
62
+ }
63
+ dispatch ( getAttributes ( { options : option } ) ) ;
64
+ } ;
65
+
54
66
const scope = {
55
67
claims : [ ] ,
56
68
dynamicScopeScripts : [ ] ,
@@ -60,13 +72,13 @@ function ScopeAddPage() {
60
72
spontaneousClientScopes : [ ] ,
61
73
showInConfigurationEndpoint : false ,
62
74
} ,
63
- }
75
+ } ;
64
76
65
77
return (
66
78
< GluuLoader blocking = { loading } >
67
79
< GluuAlert
68
- severity = { t ( ' titles.error' ) }
69
- message = { t ( ' messages.error_in_saving' ) }
80
+ severity = { t ( " titles.error" ) }
81
+ message = { t ( " messages.error_in_saving" ) }
70
82
show = { errorInSaveOperationFlag }
71
83
/>
72
84
< Card className = "mb-3" style = { applicationStyle . mainCard } >
@@ -76,11 +88,12 @@ function ScopeAddPage() {
76
88
scripts = { scripts }
77
89
attributes = { attributes }
78
90
handleSubmit = { handleSubmit }
91
+ onSearch = { handleSearch }
79
92
/>
80
93
</ CardBody >
81
94
</ Card >
82
95
</ GluuLoader >
83
- )
96
+ ) ;
84
97
}
85
98
86
- export default ScopeAddPage
99
+ export default ScopeAddPage ;
0 commit comments