LdapGroupManagement.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, toastSuccess } from '~/client/util/toastr';
  7. import { LdapGroupSyncSettingsForm } from './LdapGroupSyncSettingsForm';
  8. export const LdapGroupManagement: FC = () => {
  9. const [isUserBind, setIsUserBind] = useState(false);
  10. const { t } = useTranslation('admin');
  11. useEffect(() => {
  12. const getIsUserBind = async() => {
  13. try {
  14. const response = await apiv3Get('/security-setting/');
  15. const { ldapAuth } = response.data.securityParams;
  16. setIsUserBind(ldapAuth.isUserBind);
  17. }
  18. catch (e) {
  19. toastError(e);
  20. }
  21. };
  22. getIsUserBind();
  23. }, []);
  24. const onSyncBtnClick = useCallback(async(e) => {
  25. e.preventDefault();
  26. try {
  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. toastSuccess(t('external_user_group.ldap.sync_succeeded'));
  35. }
  36. catch (errs) {
  37. toastError(t(errs[0]?.message));
  38. }
  39. }, [t, isUserBind]);
  40. return (
  41. <>
  42. <LdapGroupSyncSettingsForm />
  43. <h3 className="border-bottom mb-3">{t('external_user_group.execute_sync')}</h3>
  44. <form onSubmit={onSyncBtnClick}>
  45. {isUserBind && (
  46. <div className="row form-group">
  47. <label htmlFor="ldapGroupSyncPassword" className="text-left text-md-right col-md-3 col-form-label">{t('external_user_group.ldap.password')}</label>
  48. <div className="col-md-6">
  49. <input
  50. className="form-control"
  51. type="password"
  52. name="password"
  53. id="ldapGroupSyncPassword"
  54. />
  55. <p className="form-text text-muted">
  56. <small>{t('external_user_group.ldap.password_detail')}</small>
  57. </p>
  58. </div>
  59. </div>
  60. )}
  61. <div className="row">
  62. <div className="col-md-3"></div>
  63. <div className="col-md-6"><button className="btn btn-primary" type="submit">{t('external_user_group.sync')}</button></div>
  64. </div>
  65. </form>
  66. </>
  67. );
  68. };