LdapGroupManagement.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type { FC } from 'react';
  2. import { type JSX, useCallback, useEffect, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { apiv3Get, apiv3Put } from '~/client/util/apiv3-client';
  5. import { toastError } from '~/client/util/toastr';
  6. import { ExternalGroupProviderType } from '~/features/external-user-group/interfaces/external-user-group';
  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. } catch (e) {
  19. toastError(e);
  20. }
  21. };
  22. getIsUserBind();
  23. }, []);
  24. const requestSyncAPI = useCallback(
  25. async (e) => {
  26. if (isUserBind) {
  27. const password = e.target.password?.value;
  28. await apiv3Put('/external-user-groups/ldap/sync', { password });
  29. } else {
  30. await apiv3Put('/external-user-groups/ldap/sync');
  31. }
  32. },
  33. [isUserBind],
  34. );
  35. const AdditionalForm = (): JSX.Element => {
  36. return isUserBind ? (
  37. <div className="row form-group">
  38. <label
  39. htmlFor="ldapGroupSyncPassword"
  40. className="text-left text-md-right col-md-3 col-form-label"
  41. >
  42. {t('external_user_group.ldap.password')}
  43. </label>
  44. <div className="col-md-6">
  45. <input
  46. className="form-control"
  47. type="password"
  48. name="password"
  49. id="ldapGroupSyncPassword"
  50. />
  51. <p className="form-text text-muted">
  52. <small>{t('external_user_group.ldap.password_detail')}</small>
  53. </p>
  54. </div>
  55. </div>
  56. ) : (
  57. <></>
  58. );
  59. };
  60. return (
  61. <>
  62. <LdapGroupSyncSettingsForm />
  63. <SyncExecution
  64. provider={ExternalGroupProviderType.ldap}
  65. requestSyncAPI={requestSyncAPI}
  66. AdditionalForm={AdditionalForm}
  67. />
  68. </>
  69. );
  70. };