SecurityLocalSetting.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { createSubscribedElement } from '../../UnstatedUtils';
  5. import AppContainer from '../../../services/AppContainer';
  6. import AdminSecurityContainer from '../../../services/AdminSecurityContainer';
  7. class SecurityLocalSetting extends React.Component {
  8. constructor(props) {
  9. super();
  10. this.state = {
  11. isLocalEnabled: true,
  12. // TODO show selected value at here
  13. modeValue: 'open',
  14. };
  15. this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
  16. }
  17. switchIsLocalEnabled() {
  18. this.setState({ isLocalEnabled: !this.state.isLocalEnabled });
  19. }
  20. render() {
  21. const { t } = this.props;
  22. return (
  23. <React.Fragment>
  24. <h2 className="alert-anchor border-bottom">
  25. { t('security_setting.Local.name') } { t('security_setting.configuration') }
  26. </h2>
  27. {/* TODO show or hide */}
  28. <p className="alert alert-info">
  29. { t('security_setting.Local.note for the only env option', 'LOCAL_STRATEGY_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS') }
  30. </p>
  31. <div className="col-xs-offset-3 col-xs-6">
  32. <div className="checkbox checkbox-success">
  33. <input
  34. id="isLocalEnabled"
  35. type="checkbox"
  36. checked={this.state.isLocalEnabled}
  37. onChange={() => { this.switchIsLocalEnabled() }}
  38. />
  39. <label htmlFor="isLocalEnabled">
  40. <strong>{ t('security_setting.Local.name') }</strong>
  41. </label>
  42. </div>
  43. </div>
  44. {this.state.isLocalEnabled && (
  45. <div className="form-group">
  46. <div className="col-xs-offset-3 col-xs-6 text-left">
  47. <div className="my-0 btn-group">
  48. <label>{ t('Register limitation') }</label>
  49. <div className="dropdown">
  50. <button className="btn btn-default dropdown-toggle w-100" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  51. <span className="pull-left">{t(`security_setting.registration_mode.${this.state.modeValue}`)}</span>
  52. <span className="bs-caret pull-right">
  53. <span className="caret" />
  54. </span>
  55. </button>
  56. {/* TODO adjust dropdown after BS4 */}
  57. <ul className="dropdown-menu" role="menu">
  58. <li key="open" role="presentation" type="button" onClick={() => { this.setState({ modeValue: 'open' }) }}>
  59. <a role="menuitem">{ t('security_setting.registration_mode.open') }</a>
  60. </li>
  61. <li key="restricted" role="presentation" type="button" onClick={() => { this.setState({ modeValue: 'restricted' }) }}>
  62. <a role="menuitem">{ t('security_setting.registration_mode.restricted') }</a>
  63. </li>
  64. <li key="closed" role="presentation" type="button" onClick={() => { this.setState({ modeValue: 'closed' }) }}>
  65. <a role="menuitem">{ t('security_setting.registration_mode.closed') }</a>
  66. </li>
  67. </ul>
  68. </div>
  69. <p className="help-block">
  70. { t('security_setting.Register limitation desc') }
  71. </p>
  72. </div>
  73. </div>
  74. </div>
  75. )}
  76. {/* TODO replace component */}
  77. <div className="col-xs-offset-3 col-xs-6 mt-5">
  78. <button type="submit" className="btn btn-primary">{ t('Update') }</button>
  79. </div>
  80. </React.Fragment>
  81. );
  82. }
  83. }
  84. SecurityLocalSetting.propTypes = {
  85. t: PropTypes.func.isRequired, // i18next
  86. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  87. adminSecurityContainer: PropTypes.instanceOf(AdminSecurityContainer).isRequired,
  88. };
  89. const SecurityLocalSettingWrapper = (props) => {
  90. return createSubscribedElement(SecurityLocalSetting, props, [AppContainer, AdminSecurityContainer]);
  91. };
  92. export default withTranslation()(SecurityLocalSettingWrapper);