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. // biome-ignore lint/correctness/noNestedComponentDefinitions: ignore
  36. const AdditionalForm = (): JSX.Element => {
  37. return isUserBind ? (
  38. <div className="row form-group">
  39. <label
  40. htmlFor="ldapGroupSyncPassword"
  41. className="text-left text-md-right col-md-3 col-form-label"
  42. >
  43. {t('external_user_group.ldap.password')}
  44. </label>
  45. <div className="col-md-6">
  46. <input
  47. className="form-control"
  48. type="password"
  49. name="password"
  50. id="ldapGroupSyncPassword"
  51. />
  52. <p className="form-text text-muted">
  53. <small>{t('external_user_group.ldap.password_detail')}</small>
  54. </p>
  55. </div>
  56. </div>
  57. ) : (
  58. <></>
  59. );
  60. };
  61. return (
  62. <>
  63. <LdapGroupSyncSettingsForm />
  64. <SyncExecution
  65. provider={ExternalGroupProviderType.ldap}
  66. requestSyncAPI={requestSyncAPI}
  67. AdditionalForm={AdditionalForm}
  68. />
  69. </>
  70. );
  71. };