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 SkillFetch from "../../repository/skill_repo";
|
---|
6 | import UserRegister from "../../repository/register_repo";
|
---|
7 | import {Component} from "react/cjs/react.production.min";
|
---|
8 |
|
---|
9 | class RegisterUser extends Component {
|
---|
10 | constructor(props) {
|
---|
11 | super(props);
|
---|
12 | this.state = {
|
---|
13 | email: "",
|
---|
14 | password: "",
|
---|
15 | type: "0",
|
---|
16 | name: "",
|
---|
17 | surname: "",
|
---|
18 | retainedSkills: [],
|
---|
19 | skillsToLearn: [],
|
---|
20 | allSkills: [],
|
---|
21 | error: props.error
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | handleCheck = (e, {value}) => {
|
---|
26 | this.setState({
|
---|
27 | ...this.state,
|
---|
28 | [e.target.name]: value
|
---|
29 | })
|
---|
30 | }
|
---|
31 |
|
---|
32 | render() {
|
---|
33 | return (
|
---|
34 | <Container>
|
---|
35 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
36 | <Form onSubmit={this.attemptRegister}>
|
---|
37 | <Form.Input id="email" name="email" type='email' required fluid label='E-mail'
|
---|
38 | placeholder='Enter e-mail.' onChange={this.handleCheck}/>
|
---|
39 | <Form.Input id="password" name="password" type='password' required fluid label='Password'
|
---|
40 | placeholder='Enter password.' onChange={this.handleCheck}/>
|
---|
41 | <Form.Input id="name" name="name" type='text' required fluid label='Name'
|
---|
42 | placeholder='Enter name.' onChange={this.handleCheck}/>
|
---|
43 | <Form.Input id="surname" name="surname" type='text' required fluid label='Surname'
|
---|
44 | placeholder='Enter surname.' onChange={this.handleCheck}/>
|
---|
45 | <label>Skills you know:</label>
|
---|
46 | <select multiple="" class="ui dropdown">
|
---|
47 | {this.state.allSkills.map(item => {
|
---|
48 | return <option value={item.id}>{item.name}</option>
|
---|
49 | })}
|
---|
50 | </select>
|
---|
51 | <Button type="submit">Register</Button>
|
---|
52 | </Form>
|
---|
53 | </Container>
|
---|
54 | );
|
---|
55 | }
|
---|
56 |
|
---|
57 | componentDidMount(){
|
---|
58 | SkillFetch.fetchAll().then((data) =>{
|
---|
59 | this.setState({
|
---|
60 | allSkills: data.data
|
---|
61 | })
|
---|
62 | })
|
---|
63 | }
|
---|
64 |
|
---|
65 | attemptRegister(){
|
---|
66 | UserRegister.userRegister(
|
---|
67 | this.state.email,
|
---|
68 | this.state.password,
|
---|
69 | this.state.name,
|
---|
70 | this.state.surname,
|
---|
71 | this.state.retainedSkills,
|
---|
72 | this.state.skillsToLearn
|
---|
73 | ).then(data => {
|
---|
74 | if(data.success){
|
---|
75 | return <Redirect to={"/login"}/>
|
---|
76 | }else{
|
---|
77 | return <Redirect to={"/user/register"} error={data.error}/>
|
---|
78 | }
|
---|
79 | })
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | export default RegisterUser; |
---|