[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 RegisterTeam extends Component {
|
---|
| 9 | constructor(props){
|
---|
| 10 | super(props);
|
---|
| 11 | this.state = {
|
---|
| 12 | email: "",
|
---|
| 13 | password: "",
|
---|
| 14 | name:"",
|
---|
| 15 | members: 0,
|
---|
| 16 | error: null,
|
---|
| 17 | success: null
|
---|
| 18 | }
|
---|
| 19 | this.attemptTeamRegister = this.attemptTeamRegister.bind(this);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | handleCheck = (e, {value}) => {
|
---|
| 23 | this.setState({
|
---|
| 24 | ...this.state,
|
---|
| 25 | [e.target.name]: value
|
---|
| 26 | })
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | attemptTeamRegister = () => {
|
---|
| 30 | UserRegister.teamRegister(
|
---|
| 31 | this.state.email,
|
---|
| 32 | this.state.password,
|
---|
| 33 | this.state.name,
|
---|
| 34 | this.state.members
|
---|
| 35 | ).then(res =>{
|
---|
| 36 | if(res.data.success!=null){
|
---|
| 37 | this.setState({
|
---|
| 38 | success: res.data.success,
|
---|
| 39 | error: null
|
---|
| 40 | })
|
---|
| 41 | this.props.message(this.state.success);
|
---|
| 42 | }else{
|
---|
| 43 | this.setState({
|
---|
| 44 | error: res.data.error,
|
---|
| 45 | success: null
|
---|
| 46 | })
|
---|
| 47 | }
|
---|
| 48 | }).catch(err => {
|
---|
| 49 | this.setState({
|
---|
| 50 | error: "Team already exists!",
|
---|
| 51 | success: null
|
---|
| 52 | })
|
---|
| 53 | })
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | componentDidMount(){
|
---|
| 57 | this.props.message(null);
|
---|
| 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.attemptTeamRegister}>
|
---|
| 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="members" name="members" type="number" required fluid label="Number of members"
|
---|
| 78 | placeholder="Enter member count." onChange={this.handleCheck}/>
|
---|
| 79 | <Form.Field control={Button}>Register</Form.Field>
|
---|
| 80 | </Form>
|
---|
| 81 | </Container>
|
---|
| 82 | );
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | export default RegisterTeam; |
---|