import React, { Component } from 'react'; import { Button, Form, Grid, Header, Image, Icon, Input, Message, } from 'semantic-ui-react'; import { Redirect } from 'react-router-dom'; import { Forms } from '../remote'; export default class Signup extends Component { constructor(props) { super(props); this.state = { completeName: '', username: '', email: '', password: '', error: { state: false, message: [] }, success: false, }; } handleRegistration = (e) => { e.preventDefault(); const params = { email: this.state.email, name: this.state.completeName, password: this.state.password, username: this.state.username, }; Forms.submitRegistration(params) .then(() => this.setState({ success: true })) .catch((err) => this.setState({ error: { state: true, message: err.messages } })); }; onChangeHandler = (event) => { const nam = event.target.name; const val = event.target.value; this.setState({ [nam]: val }); }; render() { if (this.state.success) { return ; } return ( <>
{' '} Sign-up to SmartHut
Singup Error {this.state.error.message.map((e, i) => ( {e}
))}
); } }