Last change
on this file since 351c43f was 351c43f, checked in by i-ina <76742075+i-ina@…>, 3 years ago |
begining register form
|
-
Property mode
set to
100644
|
File size:
2.0 KB
|
Rev | Line | |
---|
[351c43f] | 1 | import React from 'react';
|
---|
| 2 | import { Button, Checkbox, Container, Form } from "semantic-ui-react";
|
---|
| 3 | import { Redirect } from 'react-router-dom';
|
---|
| 4 | import SkillFetch from "../../repository/skill_repo";
|
---|
| 5 | import UserRegister from "../../repository/register_repo";
|
---|
| 6 |
|
---|
| 7 | class RegisterUser extends Component {
|
---|
| 8 | constructor(props) {
|
---|
| 9 | super(props);
|
---|
| 10 | this.state = {
|
---|
| 11 | email: "",
|
---|
| 12 | password: "",
|
---|
| 13 | type: "0",
|
---|
| 14 | name: "",
|
---|
| 15 | surname: "",
|
---|
| 16 | retainedSkills: [],
|
---|
| 17 | skillsToLearn: [],
|
---|
| 18 | allSkills: [],
|
---|
| 19 | error: props.error
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | render() {
|
---|
| 24 | return (
|
---|
| 25 | <Container>
|
---|
| 26 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
| 27 | <Form onSubmit={this.attemptRegister}>
|
---|
| 28 | <Form.Input id="email" name="email" type='email' required fluid label='E-mail'
|
---|
| 29 | placeholder='Enter e-mail.' onChange={handleCheck}/>
|
---|
| 30 | <Form.Input id="password" name="password" type='password' required fluid label='Password'
|
---|
| 31 | placeholder='Enter password.' onChange={handleCheck}/>
|
---|
| 32 |
|
---|
| 33 | <Button type="submit">Register</Button>
|
---|
| 34 | </Form>
|
---|
| 35 | </Container>
|
---|
| 36 | );
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | componentDidMount(){
|
---|
| 40 | SkillFetch.fetchAll().then((data) =>{
|
---|
| 41 | this.setState({
|
---|
| 42 | allSkills: data
|
---|
| 43 | })
|
---|
| 44 | })
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | attemptRegister(){
|
---|
| 48 | UserRegister.userRegister(
|
---|
| 49 | this.state.email,
|
---|
| 50 | this.state.password,
|
---|
| 51 | this.state.name,
|
---|
| 52 | this.state.surname,
|
---|
| 53 | this.state.retainedSkills,
|
---|
| 54 | this.state.skillsToLearn
|
---|
| 55 | ).then(data => {
|
---|
| 56 | if(data.success){
|
---|
| 57 | return <Redirect to={"/login"}/>
|
---|
| 58 | }else{
|
---|
| 59 | return <Redirect to={"/user/register"} error={data.error}/>
|
---|
| 60 | }
|
---|
| 61 | })
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | export default RegisterUser; |
---|
Note:
See
TracBrowser
for help on using the repository browser.