register-button.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import Loader from 'misago/components/loader'; // jshint ignore:line
  3. import RegisterModal from 'misago/components/register.js'; // jshint ignore:line
  4. import captcha from 'misago/services/captcha'; // jshint ignore:line
  5. import modal from 'misago/services/modal'; // jshint ignore:line
  6. import snackbar from 'misago/services/snackbar'; // jshint ignore:line
  7. import zxcvbn from 'misago/services/zxcvbn'; // jshint ignore:line
  8. export default class extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. 'isLoading': false,
  13. 'isLoaded': false
  14. };
  15. }
  16. /* jshint ignore:start */
  17. showRegisterModal = () => {
  18. if (misago.get('SETTINGS').account_activation === 'closed') {
  19. snackbar.info(gettext("New registrations are currently disabled."));
  20. } else if (this.state.isLoaded) {
  21. modal.show(RegisterModal);
  22. } else {
  23. this.setState({
  24. 'isLoading': true
  25. });
  26. Promise.all([
  27. captcha.load(),
  28. zxcvbn.load()
  29. ]).then(() => {
  30. if (!this.state.isLoaded) {
  31. this.setState({
  32. 'isLoading': false,
  33. 'isLoaded': false
  34. });
  35. }
  36. modal.show(RegisterModal);
  37. });
  38. }
  39. };
  40. /* jshint ignore:end */
  41. getClassName() {
  42. return this.props.className + (this.state.isLoading ? ' btn-loading' : '');
  43. }
  44. render() {
  45. /* jshint ignore:start */
  46. return <button type="button" onClick={this.showRegisterModal}
  47. className={'btn ' + this.getClassName()}
  48. disabled={this.state.isLoaded}>
  49. {gettext("Register")}
  50. {this.state.isLoading ? <Loader /> : null }
  51. </button>;
  52. /* jshint ignore:end */
  53. }
  54. }