import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { SimpleForm, SimpleInput, TextInput, Checkbox, } from 'gabsocial/features/forms'; import { register, fetchCaptcha } from 'gabsocial/actions/auth'; import { Map as ImmutableMap } from 'immutable'; const mapStateToProps = (state, props) => ({ instance: state.get('instance'), }); export default @connect(mapStateToProps) class RegistrationForm extends ImmutablePureComponent { static propTypes = { instance: ImmutablePropTypes.map, } state = { captcha: ImmutableMap(), captchaLoading: true, submissionLoading: false, params: ImmutableMap(), } componentWillMount() { this.props.dispatch(fetchCaptcha()).then(response => { const captcha = ImmutableMap(response.data); this.setState({ captcha: captcha, captchaLoading: false }); this.setParams({ captcha_token: captcha.get('token') }); }).catch(error => console.error(error)); } setParams = map => { this.setState({ params: this.state.params.merge(ImmutableMap(map)) }); } onInputChange = e => { this.setParams({ [e.target.name]: e.target.value }); } onCheckboxChange = e => { this.setParams({ [e.target.name]: e.target.checked }); } onSubmit = e => { this.props.dispatch(register(this.state.params.toJS())); } getCaptchaElem = () => { const { captcha } = this.state; if (captcha.get('type') !== 'native') return null; return (