1 | import React from 'react';
|
---|
2 | import 'semantic-ui-react';
|
---|
3 | import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
|
---|
4 | import { Redirect } from 'react-router-dom';
|
---|
5 | import SkillFetch from "../../repository/skill_repo";
|
---|
6 | import {Component} from "react/cjs/react.production.min";
|
---|
7 | import WorkRegister from "../../repository/work_register_repo";
|
---|
8 |
|
---|
9 | class 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 | return (
|
---|
72 | <Redirect to={"/company/internships"}/>
|
---|
73 | );
|
---|
74 | }
|
---|
75 |
|
---|
76 | return (
|
---|
77 | <Container>
|
---|
78 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
79 | <Form onSubmit={this.attemptInternshipRegister}>
|
---|
80 | <Form.Input id="title" name="title" type='text' required fluid label='Title'
|
---|
81 | placeholder='Enter title...' onChange={this.handleCheck}/>
|
---|
82 | <Form.Input id="description" name="description" type='text' required fluid label='Description'
|
---|
83 | placeholder='Enter description...' onChange={this.handleCheck}/>
|
---|
84 | <Form.Input id="salary" name="salary" type='number' required fluid label='Salary'
|
---|
85 | placeholder='Enter salary...' onChange={this.handleCheck}/>
|
---|
86 | <Form.Input id="openSpots" name="openSpots" type='number' required fluid label='Open Spots'
|
---|
87 | placeholder='Enter open spots...' onChange={this.handleCheck}/>
|
---|
88 | <Label>Select trained skills:</Label>
|
---|
89 | <Dropdown placeholder="Skills trained on this internship..." fluid multiple selection options={this.state.sortedOptions} onChange={this.setSkills}/>
|
---|
90 | <br/>
|
---|
91 | <Button type="submit">Add</Button>
|
---|
92 | </Form>
|
---|
93 | </Container>
|
---|
94 | );
|
---|
95 | }
|
---|
96 |
|
---|
97 | componentDidMount(){
|
---|
98 | SkillFetch.fetchAll().then((data) =>{
|
---|
99 | var sorted = [];
|
---|
100 | data.data.forEach(item => {
|
---|
101 | var obj = {
|
---|
102 | key: item.id,
|
---|
103 | text: item.name,
|
---|
104 | value: item.id
|
---|
105 | }
|
---|
106 | sorted.push(obj);
|
---|
107 | });
|
---|
108 |
|
---|
109 | this.setState({
|
---|
110 | sortedOptions: sorted
|
---|
111 | })
|
---|
112 | })
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | export default InternshipRegister; |
---|