@@ -17,7 +17,7 @@ import { Link } from "components/Link/Link";
17
17
import { Paywall } from "components/Paywall/Paywall" ;
18
18
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility" ;
19
19
import { useOrganizationSettings } from "modules/management/OrganizationSettingsLayout" ;
20
- import { type FC , useState } from "react" ;
20
+ import { type FC , useEffect , useState } from "react" ;
21
21
import { Helmet } from "react-helmet-async" ;
22
22
import { useMutation , useQueries , useQuery , useQueryClient } from "react-query" ;
23
23
import { useParams , useSearchParams } from "react-router-dom" ;
@@ -27,15 +27,15 @@ import IdpSyncPageView from "./IdpSyncPageView";
27
27
28
28
export const IdpSyncPage : FC = ( ) => {
29
29
const queryClient = useQueryClient ( ) ;
30
+ // IdP sync does not have its own entitlement and is based on templace_rbac
31
+ const { template_rbac : isIdpSyncEnabled } = useFeatureVisibility ( ) ;
30
32
const { organization : organizationName } = useParams ( ) as {
31
33
organization : string ;
32
34
} ;
33
- const [ groupClaimField , setGroupClaimField ] = useState ( "" ) ;
34
- const [ roleClaimField , setRoleClaimField ] = useState ( "" ) ;
35
- // IdP sync does not have its own entitlement and is based on templace_rbac
36
- const { template_rbac : isIdpSyncEnabled } = useFeatureVisibility ( ) ;
37
35
const { organizations } = useOrganizationSettings ( ) ;
38
36
const organization = organizations ?. find ( ( o ) => o . name === organizationName ) ;
37
+ const [ groupField , setGroupField ] = useState ( "" ) ;
38
+ const [ roleField , setRoleField ] = useState ( "" ) ;
39
39
40
40
const [
41
41
groupIdpSyncSettingsQuery ,
@@ -48,15 +48,15 @@ export const IdpSyncPage: FC = () => {
48
48
...groupIdpSyncSettings ( organizationName ) ,
49
49
onSuccess : ( data : GroupSyncSettings ) => {
50
50
if ( data ?. field ) {
51
- setGroupClaimField ( data . field ) ;
51
+ setGroupField ( data . field ) ;
52
52
}
53
53
} ,
54
54
} ,
55
55
{
56
56
...roleIdpSyncSettings ( organizationName ) ,
57
57
onSuccess : ( data : RoleSyncSettings ) => {
58
58
if ( data ?. field ) {
59
- setRoleClaimField ( data . field ) ;
59
+ setRoleField ( data . field ) ;
60
60
}
61
61
} ,
62
62
} ,
@@ -65,12 +65,25 @@ export const IdpSyncPage: FC = () => {
65
65
] ,
66
66
} ) ;
67
67
68
+ useEffect ( ( ) => {
69
+ if ( ! groupIdpSyncSettingsQuery . data ) {
70
+ return ;
71
+ }
72
+
73
+ setGroupField ( groupIdpSyncSettingsQuery . data . field ) ;
74
+ } , [ groupIdpSyncSettingsQuery . data ] ) ;
75
+
76
+ useEffect ( ( ) => {
77
+ if ( ! roleIdpSyncSettingsQuery . data ) {
78
+ return ;
79
+ }
80
+
81
+ setRoleField ( roleIdpSyncSettingsQuery . data . field ) ;
82
+ } , [ roleIdpSyncSettingsQuery . data ] ) ;
83
+
68
84
const [ searchParams ] = useSearchParams ( ) ;
69
85
const tab = searchParams . get ( "tab" ) || "groups" ;
70
- const field =
71
- tab === "groups"
72
- ? groupIdpSyncSettingsQuery . data ?. field
73
- : roleIdpSyncSettingsQuery . data ?. field ;
86
+ const field = tab === "groups" ? groupField : roleField ;
74
87
75
88
const fieldValuesQuery = useQuery (
76
89
field
@@ -103,14 +116,6 @@ export const IdpSyncPage: FC = () => {
103
116
}
104
117
}
105
118
106
- const handleGroupSyncFieldChange = ( value : string ) => {
107
- setGroupClaimField ( value ) ;
108
- } ;
109
-
110
- const handleRoleSyncFieldChange = ( value : string ) => {
111
- setRoleClaimField ( value ) ;
112
- } ;
113
-
114
119
return (
115
120
< >
116
121
< Helmet >
@@ -146,8 +151,8 @@ export const IdpSyncPage: FC = () => {
146
151
groupsMap = { groupsMap }
147
152
roles = { rolesQuery . data }
148
153
organization = { organization }
149
- onGroupSyncFieldChange = { handleGroupSyncFieldChange }
150
- onRoleSyncFieldChange = { handleRoleSyncFieldChange }
154
+ onGroupSyncFieldChange = { setGroupField }
155
+ onRoleSyncFieldChange = { setRoleField }
151
156
error = { error }
152
157
onSubmitGroupSyncSettings = { async ( data ) => {
153
158
try {
0 commit comments