import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; import { SimpleForm, SimpleInput, TextInput, SimpleTextarea, Checkbox, } from 'soapbox/features/forms'; import { register, verifyCredentials } 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'; import { getSettings } from 'soapbox/actions/settings'; import { openModal } from 'soapbox/actions/modal'; const messages = defineMessages({ username: { id: 'registration.fields.username_placeholder', defaultMessage: 'Username' }, username_hint: { id: 'registration.fields.username_hint', defaultMessage: 'Only letters, numbers, and underscores are allowed.' }, email: { id: 'registration.fields.email_placeholder', defaultMessage: 'E-Mail address' }, password: { id: 'registration.fields.password_placeholder', defaultMessage: 'Password' }, confirm: { id: 'registration.fields.confirm_placeholder', defaultMessage: 'Password (again)' }, agreement: { id: 'registration.agreement', defaultMessage: 'I agree to the {tos}.' }, tos: { id: 'registration.tos', defaultMessage: 'Terms of Service' }, close: { id: 'registration.confirmation_modal.close', defaultMessage: 'Close' }, }); const mapStateToProps = (state, props) => ({ instance: state.get('instance'), locale: getSettings(state).get('locale'), needsConfirmation: state.getIn(['instance', 'pleroma', 'metadata', 'account_activation_required']), needsApproval: state.getIn(['instance', 'approval_required']), }); export default @connect(mapStateToProps) @injectIntl class RegistrationForm extends ImmutablePureComponent { static propTypes = { instance: ImmutablePropTypes.map, locale: PropTypes.string, intl: PropTypes.object.isRequired, } 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 }); } launchModal = () => { const { dispatch, intl, needsConfirmation, needsApproval } = this.props; const message = (<> {needsConfirmation &&