1 | import React,{Component} from 'react';
|
---|
2 | import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
|
---|
3 | import {Redirect} from "react-router-dom";
|
---|
4 | import WorkEdit from "../../repository/edit_work_repo";
|
---|
5 |
|
---|
6 | class EditInternship extends Component {
|
---|
7 | constructor(props) {
|
---|
8 | super(props);
|
---|
9 | this.state = {
|
---|
10 | id: props.location.state.item.id,
|
---|
11 | index: props.location.state.index,
|
---|
12 | title: props.location.state.item.title,
|
---|
13 | description: props.location.state.item.description,
|
---|
14 | salary: props.location.state.item.salary,
|
---|
15 | openSpots: props.location.state.item.openSpots,
|
---|
16 | accountId: props.location.state.item.accountId,
|
---|
17 | accountType: props.location.state.item.accountType,
|
---|
18 | success: false,
|
---|
19 | error: false,
|
---|
20 | }
|
---|
21 |
|
---|
22 | this.attemptInternshipEdit = this.attemptInternshipEdit.bind(this);
|
---|
23 | }
|
---|
24 |
|
---|
25 | handleCheck = (e, {value}) => {
|
---|
26 | console.log(e.target.name);
|
---|
27 | this.setState({
|
---|
28 | ...this.state,
|
---|
29 | [e.target.name]: value
|
---|
30 | })
|
---|
31 | }
|
---|
32 |
|
---|
33 | attemptInternshipEdit(){
|
---|
34 | WorkEdit.internshipEdit(
|
---|
35 | this.state.id,
|
---|
36 | this.state.title,
|
---|
37 | this.state.description,
|
---|
38 | this.state.accountId,
|
---|
39 | this.state.salary,
|
---|
40 | this.state.openSpots
|
---|
41 | ).then(res => {
|
---|
42 | console.log(res.data);
|
---|
43 | if(res.data.error===null){
|
---|
44 | this.props.editInternship(res.data, this.state.index);
|
---|
45 | this.setState({
|
---|
46 | success: true,
|
---|
47 | error: null
|
---|
48 | })
|
---|
49 | }else{
|
---|
50 | this.setState({
|
---|
51 | success: false,
|
---|
52 | error: res.data.error
|
---|
53 | })
|
---|
54 | }
|
---|
55 | }).catch(err => {
|
---|
56 | this.setState({
|
---|
57 | error: "Error editing job!",
|
---|
58 | success: null
|
---|
59 | })
|
---|
60 | });
|
---|
61 | }
|
---|
62 |
|
---|
63 | render(){
|
---|
64 | if(this.state.accountId==null || this.state.accountType==="USER" || this.state.accountType==="TEAM"){
|
---|
65 | return(
|
---|
66 | <Redirect to={"/login"}/>
|
---|
67 | );
|
---|
68 | }
|
---|
69 |
|
---|
70 | if(this.state.success===true){
|
---|
71 | if(this.state.accountType==="COMPANY"){
|
---|
72 | return(
|
---|
73 | <Redirect to={"/company/internships"}/>
|
---|
74 | );
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | return(
|
---|
79 | <Container>
|
---|
80 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
81 | <Form onSubmit={this.attemptInternshipEdit}>
|
---|
82 | <Form.Input id="title" name="title" type='text' value={this.state.title} required fluid label='Title'
|
---|
83 | placeholder='Enter title...' onChange={this.handleCheck}/>
|
---|
84 | <Form.Input id="description" name="description" value={this.state.description} type='text' required fluid label='Description'
|
---|
85 | placeholder='Enter description...' onChange={this.handleCheck}/>
|
---|
86 | <Form.Input id="salary" name="salary" type='number' value={this.state.salary} required fluid label='Salary'
|
---|
87 | placeholder='Enter salary...' onChange={this.handleCheck}/>
|
---|
88 | <Form.Input id="openSpots" name="openSpots" type='openSpots' value={this.state.openSpots} required fluid label='Open Spots'
|
---|
89 | placeholder='Enter open spots...' onChange={this.handleCheck}/>
|
---|
90 | <Button type="submit">Confirm</Button>
|
---|
91 | </Form>
|
---|
92 | </Container>
|
---|
93 | );
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | export default EditInternship; |
---|