source: client_app/src/components/register/register_user_form.js@ 19ad843

Last change on this file since 19ad843 was 19ad843, checked in by i-ina <76742075+i-ina@…>, 3 years ago

dropdown

  • Property mode set to 100644
File size: 2.9 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 SkillFetch from "../../repository/skill_repo";
6import UserRegister from "../../repository/register_repo";
7import {Component} from "react/cjs/react.production.min";
8
9class 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
83export default RegisterUser;
Note: See TracBrowser for help on using the repository browser.