source: client_app/src/components/register/register_company_form.js@ 580ba1a

Last change on this file since 580ba1a was 580ba1a, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

register and edit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1import React from 'react';
2import 'semantic-ui-react';
3import {Button, Container, Form} from "semantic-ui-react";
4import { Redirect } from 'react-router-dom';
5import UserRegister from "../../repository/register_repo";
6import {Component} from "react/cjs/react.production.min";
7
8class RegisterCompany extends Component {
9 constructor(props){
10 super(props);
11 this.state = {
12 email: "",
13 password: "",
14 name:"",
15 country: "",
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,
36 this.state.country,
37 this.state.city,
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({
54 error: "User already exists!",
55 success: null
56 })
57 })
58 }
59
60 render() {
61 if (this.state.success != null) {
62 return (
63 <Redirect to={"/login"}/>
64 );
65 }
66
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 );
87 }
88}
89
90export default RegisterCompany;
Note: See TracBrowser for help on using the repository browser.