import { FC, useCallback, useEffect, useState, } from 'react'; import { useTranslation } from 'react-i18next'; import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client'; import { toastError, toastSuccess } from '~/client/util/toastr'; import { LdapGroupSyncSettingsForm } from './LdapGroupSyncSettingsForm'; export const LdapGroupManagement: FC = () => { const [isUserBind, setIsUserBind] = useState(false); const { t } = useTranslation('admin'); useEffect(() => { const getIsUserBind = async() => { try { const response = await apiv3Get('/security-setting/'); const { ldapAuth } = response.data.securityParams; setIsUserBind(ldapAuth.isUserBind); } catch (e) { toastError(e); } }; getIsUserBind(); }, []); const onSyncBtnClick = useCallback(async(e) => { e.preventDefault(); try { if (isUserBind) { const password = e.target.password.value; await apiv3Put('/external-user-groups/ldap/sync', { password }); } else { await apiv3Put('/external-user-groups/ldap/sync'); } toastSuccess(t('external_user_group.ldap.sync_succeeded')); } catch (errs) { toastError(t(errs[0]?.message)); } }, [t, isUserBind]); return ( <>

{t('external_user_group.execute_sync')}

{isUserBind && (

{t('external_user_group.ldap.password_detail')}

)}
); };