import React from 'react' import { Form, Input, Icon, Button, Link, CircularLoader } from 'UI' import { login } from 'App/routes' import ReCAPTCHA from 'react-google-recaptcha' import stl from './signup.module.css' import { signup } from 'Duck/user'; import { connect } from 'react-redux' import Select from 'Shared/Select' const LOGIN_ROUTE = login() const recaptchaRef = React.createRef() @connect( state => ({ tenants: state.getIn(['user', 'tenants']), errors: state.getIn([ 'user', 'signupRequest', 'errors' ]), loading: state.getIn([ 'user', 'signupRequest', 'loading' ]), }), { signup }, ) export default class SignupForm extends React.Component { state = { tenantId: '', fullname: '', password: '', email: '', projectName: '', organizationName: '', reload: false, CAPTCHA_ENABLED: window.env.CAPTCHA_ENABLED === 'true', }; static getDerivedStateFromProps(props, state) { if (props.errors && props.errors.size > 0 && state.reload) { recaptchaRef.current.reset(); return { reload: false } } return null; } handleSubmit = (token) => { const { tenantId, fullname, password, email, projectName, organizationName, auth } = this.state; this.props.signup({ tenantId, fullname, password, email, projectName, organizationName, auth, 'g-recaptcha-response': token }) this.setState({ reload: true }) } write = ({ target: { value, name } }) => this.setState({ [ name ]: value }) writeOption = ({ name, value }) => this.setState({ [ name ]: value.value }); onSubmit = (e) => { e.preventDefault(); const { CAPTCHA_ENABLED } = this.state; if (CAPTCHA_ENABLED && recaptchaRef.current) { recaptchaRef.current.execute(); } else if (!CAPTCHA_ENABLED) { this.handleSubmit(); } } render() { const { loading, errors, tenants } = this.props; const { CAPTCHA_ENABLED } = this.state; return (
) } }