1
+ import { getErrorMessage } from "api/errors" ;
1
2
import { groupsByOrganization } from "api/queries/groups" ;
2
3
import {
3
4
groupIdpSyncSettings ,
5
+ patchGroupSyncSettings ,
6
+ patchRoleSyncSettings ,
4
7
roleIdpSyncSettings ,
5
8
} from "api/queries/organizations" ;
6
9
import { organizationRoles } from "api/queries/roles" ;
7
10
import { ChooseOne , Cond } from "components/Conditionals/ChooseOne" ;
8
11
import { EmptyState } from "components/EmptyState/EmptyState" ;
12
+ import { displayError } from "components/GlobalSnackbar/utils" ;
13
+ import { displaySuccess } from "components/GlobalSnackbar/utils" ;
9
14
import { Paywall } from "components/Paywall/Paywall" ;
10
15
import { SquareArrowOutUpRight } from "lucide-react" ;
11
16
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility" ;
12
17
import { useOrganizationSettings } from "modules/management/OrganizationSettingsLayout" ;
13
- import type { FC } from "react" ;
18
+ import { type FC , useEffect } from "react" ;
14
19
import { Helmet } from "react-helmet-async" ;
15
- import { useQueries } from "react-query" ;
20
+ import { useMutation , useQueries , useQueryClient } from "react-query" ;
16
21
import { useParams } from "react-router-dom" ;
17
22
import { docs } from "utils/docs" ;
18
23
import { pageTitle } from "utils/page" ;
19
24
import IdpSyncPageView from "./IdpSyncPageView" ;
20
25
21
26
export const IdpSyncPage : FC = ( ) => {
27
+ const queryClient = useQueryClient ( ) ;
22
28
const { organization : organizationName } = useParams ( ) as {
23
29
organization : string ;
24
30
} ;
@@ -45,10 +51,41 @@ export const IdpSyncPage: FC = () => {
45
51
return < EmptyState message = "Organization not found" /> ;
46
52
}
47
53
54
+ const patchGroupSyncSettingsMutation = useMutation (
55
+ patchGroupSyncSettings ( organizationName , queryClient ) ,
56
+ ) ;
57
+ const patchRoleSyncSettingsMutation = useMutation (
58
+ patchRoleSyncSettings ( organizationName , queryClient ) ,
59
+ ) ;
60
+
61
+ useEffect ( ( ) => {
62
+ if ( patchGroupSyncSettingsMutation . error ) {
63
+ displayError (
64
+ getErrorMessage (
65
+ patchGroupSyncSettingsMutation . error ,
66
+ "Error updating IdP group sync settings." ,
67
+ ) ,
68
+ ) ;
69
+ }
70
+ } , [ patchGroupSyncSettingsMutation . error ] ) ;
71
+
72
+ useEffect ( ( ) => {
73
+ if ( patchRoleSyncSettingsMutation . error ) {
74
+ displayError (
75
+ getErrorMessage (
76
+ patchRoleSyncSettingsMutation . error ,
77
+ "Error updating IdP role sync settings." ,
78
+ ) ,
79
+ ) ;
80
+ }
81
+ } , [ patchRoleSyncSettingsMutation . error ] ) ;
82
+
48
83
const error =
49
84
groupIdpSyncSettingsQuery . error ||
50
85
roleIdpSyncSettingsQuery . error ||
51
- groupsQuery . error ;
86
+ groupsQuery . error ||
87
+ patchGroupSyncSettingsMutation . error ||
88
+ patchRoleSyncSettingsMutation . error ;
52
89
53
90
const groupsMap = new Map < string , string > ( ) ;
54
91
if ( groupsQuery . data ) {
@@ -98,6 +135,32 @@ export const IdpSyncPage: FC = () => {
98
135
roles = { rolesQuery . data }
99
136
organization = { organization }
100
137
error = { error }
138
+ onSubmitGroupSyncSettings = { async ( data ) => {
139
+ try {
140
+ await patchGroupSyncSettingsMutation . mutateAsync ( data ) ;
141
+ displaySuccess ( "IdP Group sync settings updated." ) ;
142
+ } catch ( error ) {
143
+ displayError (
144
+ getErrorMessage (
145
+ error ,
146
+ "Failed to update IdP group sync settings" ,
147
+ ) ,
148
+ ) ;
149
+ }
150
+ } }
151
+ onSubmitRoleSyncSettings = { async ( data ) => {
152
+ try {
153
+ await patchRoleSyncSettingsMutation . mutateAsync ( data ) ;
154
+ displaySuccess ( "IdP Role sync settings updated." ) ;
155
+ } catch ( error ) {
156
+ displayError (
157
+ getErrorMessage (
158
+ error ,
159
+ "Failed to update IdP role sync settings" ,
160
+ ) ,
161
+ ) ;
162
+ }
163
+ } }
101
164
/>
102
165
</ Cond >
103
166
</ ChooseOne >
0 commit comments