AssociateModal.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 AssociateModal 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('Create External Account') }
  51. </Modal.Title>
  52. </Modal.Header>
  53. <Modal.Body>
  54. <ul className="nav nav-tabs passport-settings mb-2" role="tablist">
  55. <li className="active">
  56. <a href="#passport-ldap" data-toggle="tab" role="tab"><i className="fa fa-sitemap"></i> LDAP</a>
  57. </li>
  58. <li className="tbd disabled"><a><i className="fa fa-github"></i> (TBD) GitHub</a></li>
  59. <li className="tbd disabled"><a><i className="fa fa-google"></i> (TBD) Google OAuth</a></li>
  60. <li className="tbd disabled"><a><i className="fa fa-facebook"></i> (TBD) Facebook</a></li>
  61. <li className="tbd disabled"><a><i className="fa fa-twitter"></i> (TBD) Twitter</a></li>
  62. </ul>
  63. <LdapAuthTest
  64. username={this.state.username}
  65. password={this.state.password}
  66. onChangeUsername={this.onChangeUsername}
  67. onChangePassword={this.onChangePassword}
  68. />
  69. </Modal.Body>
  70. <Modal.Footer>
  71. <button type="button" className="btn btn-info mt-3" onClick={this.onClickAddBtn}>
  72. <i className="fa fa-plus-circle" aria-hidden="true"></i>
  73. {t('add')}
  74. </button>
  75. </Modal.Footer>
  76. </Modal>
  77. );
  78. }
  79. }
  80. const AssociateModalWrapper = (props) => {
  81. return createSubscribedElement(AssociateModal, props, [AppContainer, PersonalContainer]);
  82. };
  83. AssociateModal.propTypes = {
  84. t: PropTypes.func.isRequired, // i18next
  85. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  86. personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
  87. isOpen: PropTypes.bool.isRequired,
  88. onClose: PropTypes.func.isRequired,
  89. };
  90. export default withTranslation()(AssociateModalWrapper);