DisassociateModal.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import Modal from 'react-bootstrap/es/Modal';
  5. import { toastSuccess, toastError } from '../../util/apiNotification';
  6. import { createSubscribedElement } from '../UnstatedUtils';
  7. import AppContainer from '../../services/AppContainer';
  8. import PersonalContainer from '../../services/PersonalContainer';
  9. import LdapAuthTest from '../Admin/Security/LdapAuthTest';
  10. class DisassociateModal extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. username: '',
  15. password: '',
  16. };
  17. this.onChangeUsername = this.onChangeUsername.bind(this);
  18. this.onChangePassword = this.onChangePassword.bind(this);
  19. this.onClickAddBtn = this.onClickAddBtn.bind(this);
  20. }
  21. /**
  22. * Change username
  23. */
  24. onChangeUsername(username) {
  25. this.setState({ username });
  26. }
  27. /**
  28. * Change password
  29. */
  30. onChangePassword(password) {
  31. this.setState({ password });
  32. }
  33. async onClickAddBtn() {
  34. const { t, personalContainer } = this.props;
  35. const { username, password } = this.state;
  36. try {
  37. await personalContainer.associateLdapAccount({ username, password });
  38. toastSuccess(t('security_setting.updated_general_security_setting'));
  39. }
  40. catch (err) {
  41. toastError(err);
  42. }
  43. }
  44. render() {
  45. const { t } = this.props;
  46. return (
  47. <Modal show={this.props.isOpen} onHide={this.props.onClose}>
  48. <Modal.Header className="bg-info" closeButton>
  49. <Modal.Title className="text-white">
  50. {t('Diassociate External Account')}
  51. </Modal.Title>
  52. </Modal.Header>
  53. <Modal.Body>
  54. </Modal.Body>
  55. <Modal.Footer>
  56. </Modal.Footer>
  57. </Modal>
  58. );
  59. }
  60. }
  61. const DisassociateModalWrapper = (props) => {
  62. return createSubscribedElement(DisassociateModal, props, [AppContainer, PersonalContainer]);
  63. };
  64. DisassociateModal.propTypes = {
  65. t: PropTypes.func.isRequired, // i18next
  66. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  67. personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
  68. isOpen: PropTypes.bool.isRequired,
  69. onClose: PropTypes.func.isRequired,
  70. };
  71. export default withTranslation()(DisassociateModalWrapper);