source: client_app/src/components/work_edit/edit_job.js@ 81c9e25

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

reorganization

  • Property mode set to 100644
File size: 3.2 KB
Line 
1import React,{Component} from 'react';
2import {Button, Container, Dropdown, Form, Label} from "semantic-ui-react";
3import {Redirect} from "react-router-dom";
4import WorkEdit from "../../repository/edit_work_repo";
5
6class EditJob 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 accountId: props.location.state.item.accountId,
16 accountType: props.location.state.item.accountType,
17 success: false,
18 error: false,
19 }
20
21 this.attemptJobEdit = this.attemptJobEdit.bind(this);
22 }
23
24 handleCheck = (e, {value}) => {
25 this.setState({
26 ...this.state,
27 [e.target.name]: value
28 })
29 }
30
31 attemptJobEdit(){
32 WorkEdit.jobEdit(
33 this.state.id,
34 this.state.title,
35 this.state.description,
36 this.state.accountId,
37 this.state.salary
38 ).then(res => {
39 if(res.data.error===null){
40 this.props.editJob(res.data, this.state.index);
41 this.setState({
42 success: true,
43 error: null
44 })
45 }else{
46 this.setState({
47 success: false,
48 error: res.data.error
49 })
50 }
51 }).catch(err => {
52 this.setState({
53 error: "Error editing job!",
54 success: null
55 })
56 });
57 }
58
59 render(){
60 if(this.state.accountId==null || this.state.accountType==="USER"){
61 return(
62 <Redirect to={"/login"}/>
63 );
64 }
65
66 if(this.state.success===true){
67 if(this.state.accountType==="COMPANY"){
68 return(
69 <Redirect to={"/company/jobs"}/>
70 );
71 }else{
72 return(
73 <Redirect to={"/team/jobs"}/>
74 );
75 }
76 }
77
78 return(
79 <Container>
80 <h1 style={{color: "red"}}>{this.state.error}</h1>
81 <Form onSubmit={this.attemptJobEdit}>
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 <Button type="submit">Confirm</Button>
89 </Form>
90 </Container>
91 );
92 }
93}
94
95export default EditJob;
Note: See TracBrowser for help on using the repository browser.