[df3a395] | 1 | import React from 'react';
|
---|
| 2 | import 'semantic-ui-react';
|
---|
| 3 | import {Button, Container, Form} from "semantic-ui-react";
|
---|
| 4 | import { Redirect } from 'react-router-dom';
|
---|
| 5 | import UserRegister from "../../repository/register_repo";
|
---|
| 6 | import {Component} from "react/cjs/react.production.min";
|
---|
| 7 |
|
---|
| 8 | class RegisterCompany extends Component {
|
---|
| 9 | constructor(props){
|
---|
| 10 | super(props);
|
---|
| 11 | this.state = {
|
---|
| 12 | email: "",
|
---|
| 13 | password: "",
|
---|
| 14 | name:"",
|
---|
[580ba1a] | 15 | country: "",
|
---|
[df3a395] | 16 | city: "",
|
---|
| 17 | street: "",
|
---|
| 18 | error: null,
|
---|
| 19 | success: null
|
---|
| 20 | }
|
---|
| 21 | this.attemptCompanyRegister = this.attemptCompanyRegister.bind(this);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | handleCheck = (e, {value}) => {
|
---|
| 25 | this.setState({
|
---|
| 26 | ...this.state,
|
---|
| 27 | [e.target.name]: value
|
---|
| 28 | })
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | attemptCompanyRegister = () => {
|
---|
| 32 | UserRegister.companyRegister(
|
---|
| 33 | this.state.email,
|
---|
| 34 | this.state.password,
|
---|
| 35 | this.state.name,
|
---|
[580ba1a] | 36 | this.state.country,
|
---|
| 37 | this.state.city,
|
---|
[df3a395] | 38 | this.state.street
|
---|
| 39 | ).then(res =>{
|
---|
| 40 | if(res.data.success!=null){
|
---|
| 41 | this.setState({
|
---|
| 42 | success: res.data.success,
|
---|
| 43 | error: null
|
---|
| 44 | })
|
---|
| 45 | this.props.message(this.state.success);
|
---|
| 46 | }else{
|
---|
| 47 | this.setState({
|
---|
| 48 | error: res.data.error,
|
---|
| 49 | success: null
|
---|
| 50 | })
|
---|
| 51 | }
|
---|
| 52 | }).catch(err => {
|
---|
| 53 | this.setState({
|
---|
[580ba1a] | 54 | error: "User already exists!",
|
---|
[df3a395] | 55 | success: null
|
---|
| 56 | })
|
---|
| 57 | })
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | render() {
|
---|
[580ba1a] | 61 | if (this.state.success != null) {
|
---|
| 62 | return (
|
---|
[df3a395] | 63 | <Redirect to={"/login"}/>
|
---|
| 64 | );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[580ba1a] | 67 | return (
|
---|
| 68 | <Container>
|
---|
| 69 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
| 70 | <Form onSubmit={this.attemptCompanyRegister}>
|
---|
| 71 | <Form.Input id="email" name="email" type='email' required fluid label='E-mail'
|
---|
| 72 | placeholder='Enter e-mail.' onChange={this.handleCheck}/>
|
---|
| 73 | <Form.Input id="password" name="password" type='password' required fluid label='Password'
|
---|
| 74 | placeholder='Enter password.' onChange={this.handleCheck}/>
|
---|
| 75 | <Form.Input id="name" name="name" type='text' required fluid label='Name'
|
---|
| 76 | placeholder='Enter company name.' onChange={this.handleCheck}/>
|
---|
| 77 | <Form.Input id="country" name="country" type='text' required fluid label='Country'
|
---|
| 78 | placeholder='Enter your country.' onChange={this.handleCheck}/>
|
---|
| 79 | <Form.Input id="city" name="city" type='text' required fluid label='City'
|
---|
| 80 | placeholder='Enter your city.' onChange={this.handleCheck}/>
|
---|
| 81 | <Form.Input id="street" name="street" type='text' required fluid label='Street'
|
---|
| 82 | placeholder='Enter address street.' onChange={this.handleCheck}/>
|
---|
| 83 | <Form.Field control={Button}>Register</Form.Field>
|
---|
| 84 | </Form>
|
---|
| 85 | </Container>
|
---|
| 86 | );
|
---|
[df3a395] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | export default RegisterCompany; |
---|