Ignore:
Timestamp:
01/13/21 03:56:56 (3 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
df3a395
Parents:
19ad843
Message:

finished user registration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client_app/src/components/register/register_user_form.js

    r19ad843 r7944fab  
    11import React from 'react';
    22import 'semantic-ui-react';
    3 import {Button, Container, Form} from "semantic-ui-react";
     3import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
    44import { Redirect } from 'react-router-dom';
    55import SkillFetch from "../../repository/skill_repo";
     
    1818            retainedSkills: [],
    1919            skillsToLearn: [],
    20             allSkills: [],
    21             error: props.error
     20            error: props.error,
     21            success: props.success,
     22            sortedOptions:[]
    2223        }
     24        this.attemptRegister = this.attemptRegister.bind(this);
    2325    }
    2426
     
    3032    }
    3133
     34    setKnown = (e, {value}) =>{
     35        this.setState({
     36            retainedSkills: value
     37        })
     38    }
     39
     40    setToKnow = (e, {value}) =>{
     41        this.setState({
     42            skillsToLearn: value
     43        })
     44    }
     45
     46    attemptRegister(){
     47        UserRegister.userRegister(
     48            this.state.email,
     49            this.state.password,
     50            this.state.name,
     51            this.state.surname,
     52            this.state.retainedSkills,
     53            this.state.skillsToLearn
     54        ).then(res => {
     55            if(res.data.success!=null){
     56                this.setState({
     57                    success: res.data.success,
     58                    error: null
     59                })
     60            }else{
     61                this.setState({
     62                    error: res.data.error,
     63                    success: null
     64                })
     65            }
     66        }).catch(err => {
     67            this.setState({
     68                error: "User already exists!",
     69                success: null
     70            })
     71        });
     72    }
     73
    3274    render() {
     75        console.log(this.state.success);
     76
     77        if(this.state.success!=null){
     78            return(
     79                <Redirect to={"/login"} success={this.state.success}/>
     80            );
     81        }
     82
    3383        return (
    3484            <Container>
     
    4393                    <Form.Input id="surname" name="surname" type='text' required fluid label='Surname'
    4494                                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>
     95                                <Label>Select skills you know:</Label>
     96                    <Dropdown placeholder="Skills you know..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setKnown}/>
     97                    <br/>
     98                    <Label>Select skills you want to know:</Label>
     99                    <Dropdown placeholder="Skills you want to learn..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setToKnow}/>
     100                    <br/>
    51101                    <Button type="submit">Register</Button>
    52102                </Form>
     
    57107    componentDidMount(){
    58108        SkillFetch.fetchAll().then((data) =>{
     109            var sorted = [];
     110            data.data.forEach(item => {
     111               var obj = {
     112                   key: item.id,
     113                   text: item.name,
     114                   value: item.id
     115               }
     116               sorted.push(obj);
     117            });
     118
    59119            this.setState({
    60                 allSkills: data.data
     120                sortedOptions: sorted
    61121            })
    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             }
    79122        })
    80123    }
Note: See TracChangeset for help on using the changeset viewer.