LdapGroupManagement.tsx 1.9 KB

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