LdapGroupManagement.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. FC, useCallback, useEffect, useState,
  3. } from 'react';
  4. import { useTranslation } from 'react-i18next';
  5. import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client';
  6. import { toastError } from '~/client/util/toastr';
  7. import { ExternalGroupProviderType } from '~/features/external-user-group/interfaces/external-user-group';
  8. import { LdapGroupSyncSettingsForm } from './LdapGroupSyncSettingsForm';
  9. import { SyncExecution } from './SyncExecution';
  10. export const LdapGroupManagement: FC = () => {
  11. const [isUserBind, setIsUserBind] = useState(false);
  12. const { t } = useTranslation('admin');
  13. useEffect(() => {
  14. const getIsUserBind = async() => {
  15. try {
  16. const response = await apiv3Get('/security-setting/');
  17. const { ldapAuth } = response.data.securityParams;
  18. setIsUserBind(ldapAuth.isUserBind);
  19. }
  20. catch (e) {
  21. toastError(e);
  22. }
  23. };
  24. getIsUserBind();
  25. }, []);
  26. const requestSyncAPI = useCallback(async(e) => {
  27. if (isUserBind) {
  28. const password = e.target.password.value;
  29. await apiv3Put('/external-user-groups/ldap/sync', { password });
  30. }
  31. else {
  32. await apiv3Put('/external-user-groups/ldap/sync');
  33. }
  34. }, [isUserBind]);
  35. const AdditionalForm = (): JSX.Element => {
  36. return isUserBind ? (
  37. <div className="row form-group">
  38. <label htmlFor="ldapGroupSyncPassword" className="text-left text-md-right col-md-3 col-form-label">{t('external_user_group.ldap.password')}</label>
  39. <div className="col-md-6">
  40. <input
  41. className="form-control"
  42. type="password"
  43. name="password"
  44. id="ldapGroupSyncPassword"
  45. />
  46. <p className="form-text text-muted">
  47. <small>{t('external_user_group.ldap.password_detail')}</small>
  48. </p>
  49. </div>
  50. </div>
  51. ) : <></>;
  52. };
  53. return (
  54. <>
  55. <LdapGroupSyncSettingsForm />
  56. <SyncExecution provider={ExternalGroupProviderType.ldap} requestSyncAPI={requestSyncAPI} AdditionalForm={AdditionalForm} />
  57. </>
  58. );
  59. };