source: client_app/src/components/work_register/internship_register.js@ db94dbd

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

work register

  • Property mode set to 100644
File size: 4.0 KB
Line 
1import React from 'react';
2import 'semantic-ui-react';
3import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
4import { Redirect } from 'react-router-dom';
5import SkillFetch from "../../repository/skill_repo";
6import {Component} from "react/cjs/react.production.min";
7import WorkRegister from "../../repository/work_register_repo";
8
9class InternshipRegister extends Component {
10 constructor(props) {
11 super(props);
12 this.state = {
13 title: "",
14 description: "",
15 accountId: props.accountId,
16 salary: 0,
17 type: props.type,
18 openSpots: 0,
19 skillsTrained: [],
20 error: null,
21 success: null,
22 sortedOptions: []
23 }
24 this.attemptInternshipRegister = this.attemptInternshipRegister.bind(this);
25 }
26
27 handleCheck = (e, {value}) => {
28 this.setState({
29 ...this.state,
30 [e.target.name]: value
31 })
32 }
33
34 setSkills = (e, {value}) =>{
35 this.setState({
36 skillsTrained: value
37 })
38 }
39
40 attemptInternshipRegister(){
41 WorkRegister.internshipRegister(
42 this.state.title,
43 this.state.description,
44 this.state.accountId,
45 this.state.salary,
46 this.state.type,
47 this.state.openSpots,
48 this.state.skillsTrained
49 ).then(res => {
50 this.props.updateInternships(res.data);
51 this.setState({
52 success: true,
53 error: null
54 })
55 }).catch(err => {
56 this.setState({
57 error: "Error registering job!",
58 success: null
59 })
60 });
61 }
62
63 render() {
64 if(this.state.accountId==null || this.state.type==="USER"){
65 return(
66 <Redirect to={"/login"}/>
67 );
68 }
69
70 if(this.state.success===true){
71 if(this.state.type==="COMPANY"){
72 return(
73 <Redirect to={"/company/internships"}/>
74 );
75 }else{
76 return(
77 <Redirect to={"/profile"}/>
78 );
79 }
80 }
81
82 return (
83 <Container>
84 <h1 style={{color: "red"}}>{this.state.error}</h1>
85 <Form onSubmit={this.attemptInternshipRegister}>
86 <Form.Input id="title" name="title" type='text' required fluid label='Title'
87 placeholder='Enter title...' onChange={this.handleCheck}/>
88 <Form.Input id="description" name="description" type='text' required fluid label='Description'
89 placeholder='Enter description...' onChange={this.handleCheck}/>
90 <Form.Input id="salary" name="salary" type='number' required fluid label='Salary'
91 placeholder='Enter salary...' onChange={this.handleCheck}/>
92 <Form.Input id="openSpots" name="openSpots" type='number' required fluid label='Open Spots'
93 placeholder='Enter open spots...' onChange={this.handleCheck}/>
94 <Label>Select trained skills:</Label>
95 <Dropdown placeholder="Skills trained on this internship..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setSkills}/>
96 <br/>
97 <Button type="submit">Add</Button>
98 </Form>
99 </Container>
100 );
101 }
102
103 componentDidMount(){
104 SkillFetch.fetchAll().then((data) =>{
105 var sorted = [];
106 data.data.forEach(item => {
107 var obj = {
108 key: item.id,
109 text: item.name,
110 value: item.id
111 }
112 sorted.push(obj);
113 });
114
115 this.setState({
116 sortedOptions: sorted
117 })
118 })
119 }
120}
121
122export default InternshipRegister;
Note: See TracBrowser for help on using the repository browser.