1 | import React from 'react';
|
---|
2 | import 'semantic-ui-react';
|
---|
3 | import SemanticDatePicker from 'react-semantic-ui-datepickers';
|
---|
4 | import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
|
---|
5 | import { Redirect } from 'react-router-dom';
|
---|
6 | import SkillFetch from "../../repository/skill_repo";
|
---|
7 | import {Component} from "react/cjs/react.production.min";
|
---|
8 | import WorkRegister from "../../repository/work_register_repo";
|
---|
9 |
|
---|
10 | class ProjectRegister extends Component {
|
---|
11 | constructor(props) {
|
---|
12 | super(props);
|
---|
13 | this.state = {
|
---|
14 | title: "",
|
---|
15 | description: "",
|
---|
16 | accountId: props.accountId,
|
---|
17 | salary: 0,
|
---|
18 | type: props.type,
|
---|
19 | validUntil: "",
|
---|
20 | skillsRequired: [],
|
---|
21 | error: null,
|
---|
22 | success: null,
|
---|
23 | sortedOptions: []
|
---|
24 | }
|
---|
25 | this.attemptProjectRegister = this.attemptProjectRegister.bind(this);
|
---|
26 | }
|
---|
27 |
|
---|
28 | handleCheck = (e, {value}) => {
|
---|
29 | this.setState({
|
---|
30 | ...this.state,
|
---|
31 | [e.target.name]: value
|
---|
32 | })
|
---|
33 | }
|
---|
34 | editValid = (e, {value}) => {
|
---|
35 | this.setState({
|
---|
36 | validUntil: value
|
---|
37 | })
|
---|
38 | }
|
---|
39 |
|
---|
40 | setSkills = (e, {value}) =>{
|
---|
41 | this.setState({
|
---|
42 | skillsRequired: value
|
---|
43 | })
|
---|
44 | }
|
---|
45 |
|
---|
46 | attemptProjectRegister(){
|
---|
47 | WorkRegister.projectRegister(
|
---|
48 | this.state.title,
|
---|
49 | this.state.description,
|
---|
50 | this.state.accountId,
|
---|
51 | this.state.salary,
|
---|
52 | this.state.type,
|
---|
53 | this.state.validUntil,
|
---|
54 | this.state.skillsRequired
|
---|
55 | ).then(res => {
|
---|
56 | console.log(res);
|
---|
57 | // this.props.updateProjects(res.data);
|
---|
58 | // this.setState({
|
---|
59 | // success: true,
|
---|
60 | // error: null
|
---|
61 | // })
|
---|
62 | }).catch(err => {
|
---|
63 | console.log(err);
|
---|
64 | this.setState({
|
---|
65 | error: "Error registering job!",
|
---|
66 | success: null
|
---|
67 | })
|
---|
68 | });
|
---|
69 | }
|
---|
70 |
|
---|
71 | render() {
|
---|
72 | if(this.state.accountId==null || this.state.type==="USER"){
|
---|
73 | return(
|
---|
74 | <Redirect to={"/login"}/>
|
---|
75 | );
|
---|
76 | }
|
---|
77 |
|
---|
78 | if(this.state.success===true){
|
---|
79 | if(this.state.type==="TEAM"){
|
---|
80 | return(
|
---|
81 | <Redirect to={"/company/jobs"}/>
|
---|
82 | );
|
---|
83 | }else{
|
---|
84 | return(
|
---|
85 | <Redirect to={"/team/jobs"}/>
|
---|
86 | );
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | return (
|
---|
91 | <Container>
|
---|
92 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
93 | <Form onSubmit={this.attemptProjectRegister}>
|
---|
94 | <Form.Input id="title" name="title" type='text' required fluid label='Title'
|
---|
95 | placeholder='Enter title...' onChange={this.handleCheck}/>
|
---|
96 | <Form.Input id="description" name="description" type='text' required fluid label='Description'
|
---|
97 | placeholder='Enter description...' onChange={this.handleCheck}/>
|
---|
98 | <Form.Input id="salary" name="salary" type='number' required fluid label='Salary'
|
---|
99 | placeholder='Enter salary...' onChange={this.handleCheck}/>
|
---|
100 | <SemanticDatePicker required local="en_US" format='YYYY-MM-DD' onChange={this.editValid} type="basic"/>
|
---|
101 | <br />
|
---|
102 | <Label>Select required skills:</Label>
|
---|
103 | <Dropdown placeholder="Skills needed for the project..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setSkills}/>
|
---|
104 | <br/>
|
---|
105 | <Button type="submit">Add</Button>
|
---|
106 | </Form>
|
---|
107 | </Container>
|
---|
108 | );
|
---|
109 | }
|
---|
110 |
|
---|
111 | componentDidMount(){
|
---|
112 | SkillFetch.fetchAll().then((data) =>{
|
---|
113 | var sorted = [];
|
---|
114 | data.data.forEach(item => {
|
---|
115 | var obj = {
|
---|
116 | key: item.id,
|
---|
117 | text: item.name,
|
---|
118 | value: item.id
|
---|
119 | }
|
---|
120 | sorted.push(obj);
|
---|
121 | });
|
---|
122 |
|
---|
123 | this.setState({
|
---|
124 | sortedOptions: sorted
|
---|
125 | })
|
---|
126 | })
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | export default ProjectRegister; |
---|