source: client_app/src/components/work_register/project_register.js@ 5b36317

Last change on this file since 5b36317 was 5b36317, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

completed work registration

  • Property mode set to 100644
File size: 3.9 KB
Line 
1import React from 'react';
2import 'semantic-ui-react';
3import SemanticDatePicker from 'react-semantic-ui-datepickers';
4import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
5import { Redirect } from 'react-router-dom';
6import SkillFetch from "../../repository/skill_repo";
7import {Component} from "react/cjs/react.production.min";
8import WorkRegister from "../../repository/work_register_repo";
9
10class 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 this.props.updateProjects(res.data);
57 this.setState({
58 success: true,
59 error: null
60 })
61 }).catch(err => {
62 console.log(err);
63 this.setState({
64 error: "Error registering job!",
65 success: null
66 })
67 });
68 }
69
70 render() {
71 if(this.state.accountId==null || this.state.type==="USER"){
72 return(
73 <Redirect to={"/login"}/>
74 );
75 }
76
77 if(this.state.success===true){
78 return (
79 <Redirect to={"/team/projects"}/>
80 );
81 }
82
83 return (
84 <Container>
85 <h1 style={{color: "red"}}>{this.state.error}</h1>
86 <Form onSubmit={this.attemptProjectRegister}>
87 <Form.Input id="title" name="title" type='text' required fluid label='Title'
88 placeholder='Enter title...' onChange={this.handleCheck}/>
89 <Form.Input id="description" name="description" type='text' required fluid label='Description'
90 placeholder='Enter description...' onChange={this.handleCheck}/>
91 <Form.Input id="salary" name="salary" type='number' required fluid label='Salary'
92 placeholder='Enter salary...' onChange={this.handleCheck}/>
93 <SemanticDatePicker required local="en_US" format='YYYY-MM-DD' onChange={this.editValid} type="basic"/>
94 <br />
95 <Label>Select required skills:</Label>
96 <Dropdown placeholder="Skills needed for the project..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setSkills}/>
97 <br/>
98 <Button type="submit">Add</Button>
99 </Form>
100 </Container>
101 );
102 }
103
104 componentDidMount(){
105 SkillFetch.fetchAll().then((data) =>{
106 var sorted = [];
107 data.data.forEach(item => {
108 var obj = {
109 key: item.id,
110 text: item.name,
111 value: item.id
112 }
113 sorted.push(obj);
114 });
115
116 this.setState({
117 sortedOptions: sorted
118 })
119 })
120 }
121}
122
123export default ProjectRegister;
Note: See TracBrowser for help on using the repository browser.