import React from 'react'; import { Row, Col, FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import AsyncButton from '../components/async-button'; import Card from '../components/card'; import Error from '../components/error'; import Fa from '../components/fa'; import Logo from './logo'; import BorderlessForm from './borderless-form'; import { validateForm } from '../commons/validator'; import { server } from '../commons/server'; /** * Values to be validated */ const formModel = { name: { required: true }, login: { required: true }, email: { required: true, email: true }, organization: { } }; /** * Wellcome page - First page displayed under e-TB Manager first time execution */ export default class UserReg extends React.Component { constructor(props) { super(props); this.submit = this.submit.bind(this); this.state = {}; } /** * Called when user clicks on the continue button */ submit() { const res = validateForm(this, formModel); // is there any validation error ? if (res.errors) { this.setState({ errors: res.errors }); return; } // clear error messages this.setState({ errors: null, fetching: true }); const self = this; server.post('/api/pub/selfreg', res.value) .then(resp => { if (!resp.success) { self.setState({ errors: resp.errors, fetching: false }); return; } self.setState({ success: true, fetching: false }); }) .catch(() => self.setState({ fetching: false })); } /** * Render message when user successfully register himself * @return {[type]} [description] */ renderSuccess() { return ( {__('global.success')} {__('userreg.success.1')} ); } /** * Render the component */ render() { const err = {}; if (this.state.errors) { // transform error from an array to an object this.state.errors.forEach(item => { err[item.field] = item.msg; }); } const fetching = !!this.state.fetching; const success = !!this.state.success; return ( { success ? this.renderSuccess() : {__('userreg')} {__('User.name') + ':'} {__('User.login') + ':'} {__('User.email') + ':'} {__('login.organization') + ':'} {__('action.submit')} } ); } }
{__('userreg.success.1')}