@@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next';
99
1010import BaseGroupPage from './BaseGroupPage' ;
1111import { useExternalLink } from '../../../../hooks/useExternalLink' ;
12+ import { useLdapSync } from '../../../../hooks/useLdapSync' ;
1213import { links } from '../../../../lib/links' ;
1314import { useEditableSettings } from '../../EditableSettingsContext' ;
1415
@@ -20,11 +21,11 @@ function LDAPGroupPage({ _id, i18nLabel, onClickBack, ...group }: LDAPGroupPageP
2021 const { t } = useTranslation ( ) ;
2122 const dispatchToastMessage = useToastMessageDispatch ( ) ;
2223 const testConnection = useEndpoint ( 'POST' , '/v1/ldap.testConnection' ) ;
23- const syncNow = useEndpoint ( 'POST' , '/v1/ldap.syncNow' ) ;
2424 const testSearch = useEndpoint ( 'POST' , '/v1/ldap.testSearch' ) ;
2525 const ldapEnabled = useSetting ( 'LDAP_Enable' ) ;
2626 const setModal = useSetModal ( ) ;
2727 const closeModal = useEffectEvent ( ( ) => setModal ( ) ) ;
28+ const handleSyncNow = useLdapSync ( ) ;
2829
2930 const handleLinkClick = useExternalLink ( ) ;
3031
@@ -48,37 +49,6 @@ function LDAPGroupPage({ _id, i18nLabel, onClickBack, ...group }: LDAPGroupPageP
4849 }
4950 } ;
5051
51- const handleSyncNowButtonClick = async ( ) : Promise < void > => {
52- try {
53- await testConnection ( ) ;
54- const confirmSync = async ( ) : Promise < void > => {
55- closeModal ( ) ;
56-
57- try {
58- const { message } = await syncNow ( ) ;
59- dispatchToastMessage ( { type : 'success' , message : t ( message as Parameters < typeof t > [ 0 ] ) } ) ;
60- } catch ( error ) {
61- error instanceof Error && dispatchToastMessage ( { type : 'error' , message : error } ) ;
62- }
63- } ;
64-
65- setModal (
66- < GenericModal
67- variant = 'info'
68- confirmText = { t ( 'Sync' ) }
69- cancelText = { t ( 'Cancel' ) }
70- title = { t ( 'Execute_Synchronization_Now' ) }
71- onConfirm = { confirmSync }
72- onClose = { closeModal }
73- >
74- { t ( 'LDAP_Sync_Now_Description' ) }
75- </ GenericModal > ,
76- ) ;
77- } catch ( error ) {
78- error instanceof Error && dispatchToastMessage ( { type : 'error' , message : error } ) ;
79- }
80- } ;
81-
8252 const handleSearchTestButtonClick = async ( ) : Promise < void > => {
8353 try {
8454 await testConnection ( ) ;
@@ -144,7 +114,7 @@ function LDAPGroupPage({ _id, i18nLabel, onClickBack, ...group }: LDAPGroupPageP
144114 < Button disabled = { ! ldapEnabled || changed } onClick = { handleSearchTestButtonClick } >
145115 { t ( 'Test_LDAP_Search' ) }
146116 </ Button >
147- < Button disabled = { ! ldapEnabled || changed } onClick = { handleSyncNowButtonClick } >
117+ < Button disabled = { ! ldapEnabled || changed } onClick = { handleSyncNow } >
148118 { t ( 'LDAP_Sync_Now' ) }
149119 </ Button >
150120 < Button role = 'link' onClick = { ( ) => handleLinkClick ( links . go . ldapDocs ) } >
0 commit comments