/* eslint-disable react/jsx-indent-props */ import React from 'react'; import { Row, FormGroup, ControlLabel, Button } from 'react-bootstrap'; import Col from '../../components/Col/Col'; import PropTypes from 'prop-types'; import { Link } from 'react-router-dom'; import { Meteor } from 'meteor/meteor'; import { Accounts } from 'meteor/accounts-base'; import { Bert } from 'meteor/themeteorchef:bert'; import randomHex from 'crypto-random-hex'; import Icon from '../../components/Icon/Icon'; import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons'; import InputHint from '../../components/InputHint/InputHint'; import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter'; import validate from '../../../modules/validate'; import './Signup.scss'; import { translate } from 'react-i18next'; import { T9n } from 'meteor-accounts-t9n'; class Signup extends React.Component { constructor(props) { super(props); this.t = props.t; this.handleSubmit = this.handleSubmit.bind(this); // console.log(props.location.state); this.state = props.location.state; } componentDidMount() { const component = this; validate(component.form, { rules: { firstName: { required: true }, lastName: { required: true }, emailAddress: { required: true, email: true }, password: { required: true, minlength: 6 } }, messages: { firstName: { required: this.t('¿Cuál es tu nombre?') }, lastName: { required: this.t('¿Cuál es tu apellido?') }, emailAddress: { required: this.t('Necesitamos una contraseña aquí.'), email: this.t('¿Es correcto este correo?') }, password: { required: this.t('Necesitamos una contraseña aquí.'), minlength: this.t('Usa al menos seis caracteres.') } }, submitHandler() { component.handleSubmit(); } }); } handleSubmit() { const { history, t } = this.props; Accounts.createUser({ email: this.emailAddress.value, password: this.password.value, profile: { name: { first: this.firstName.value, last: this.lastName.value } } }, (error) => { if (error) { Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger'); } else { Meteor.call('users.sendVerificationEmail'); Bert.alert(t('Bienvenid@!'), 'success'); history.push('/subscriptions'); } }); } render() { const { t, history } = this.props; return (

{t('Registrarse')}

(this.form = form)} onSubmit={event => event.preventDefault()}> {t('Nombre')} (this.firstName = firstName)} className="form-control" /> {t('Apellidos')} (this.lastName = lastName)} className="form-control" /> {t('Correo electrónico')} (this.emailAddress = emailAddress)} className="form-control" /> {t('Contraseña')} (this.password = password)} className="form-control" /> {t('Usa al menos seis caracteres.')}

{t('¿Ya tienes un cuenta?')} {t('Iniciar sesión')}.

); } } Signup.propTypes = { history: PropTypes.object.isRequired, location: PropTypes.object }; export default translate([], { wait: true })(Signup);