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 'soapbox/features/forms'; import { register } from 'soapbox/actions/auth'; import CaptchaField from 'soapbox/features/auth_login/components/captcha'; import { Map as ImmutableMap } from 'immutable'; import { v4 as uuidv4 } from 'uuid'; const mapStateToProps = (state, props) => ({ instance: state.get('instance'), }); export default @connect(mapStateToProps) class RegistrationForm extends ImmutablePureComponent { static propTypes = { instance: ImmutablePropTypes.map, } state = { captchaLoading: true, submissionLoading: false, params: ImmutableMap(), captchaIdempotencyKey: uuidv4(), } 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.setState({ submissionLoading: true }); this.props.dispatch(register(this.state.params.toJS())).catch(error => { this.setState({ submissionLoading: false }); this.refreshCaptcha(); }); } onFetchCaptcha = captcha => { this.setState({ captchaLoading: false }); this.setParams({ captcha_token: captcha.get('token'), captcha_answer_data: captcha.get('answer_data'), }); } onFetchCaptchaFail = error => { this.setState({ captchaLoading: false }); } refreshCaptcha = () => { this.setState({ captchaIdempotencyKey: uuidv4() }); } render() { const { instance } = this.props; const isLoading = this.state.captchaLoading || this.state.submissionLoading; return (

With an account on {instance.get('title')} you'll be able to follow people on any server in the fediverse.

I agree to the Terms of Service.} name='agreement' onChange={this.onCheckboxChange} required />
); } }