[6729ba5] | 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 EditProject 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.attemptProjectEdit = this.attemptProjectEdit.bind(this);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | handleCheck = (e, {value}) => {
|
---|
| 25 | this.setState({
|
---|
| 26 | ...this.state,
|
---|
| 27 | [e.target.name]: value
|
---|
| 28 | })
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | attemptProjectEdit(){
|
---|
| 32 | WorkEdit.projectEdit(
|
---|
| 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.editProject(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" || this.state.accountType==="COMPANY"){
|
---|
| 61 | return(
|
---|
| 62 | <Redirect to={"/login"}/>
|
---|
| 63 | );
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | if(this.state.success===true){
|
---|
| 67 | if(this.state.accountType==="TEAM"){
|
---|
| 68 | return(
|
---|
| 69 | <Redirect to={"/team/projects"}/>
|
---|
| 70 | );
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | return(
|
---|
| 75 | <Container>
|
---|
| 76 | <h1 style={{color: "red"}}>{this.state.error}</h1>
|
---|
| 77 | <Form onSubmit={this.attemptProjectEdit}>
|
---|
| 78 | <Form.Input id="title" name="title" type='text' value={this.state.title} required fluid label='Title'
|
---|
| 79 | placeholder='Enter title...' onChange={this.handleCheck}/>
|
---|
| 80 | <Form.Input id="description" name="description" value={this.state.description} type='text' required fluid label='Description'
|
---|
| 81 | placeholder='Enter description...' onChange={this.handleCheck}/>
|
---|
| 82 | <Form.Input id="salary" name="salary" type='number' value={this.state.salary} required fluid label='Salary'
|
---|
| 83 | placeholder='Enter salary...' onChange={this.handleCheck}/>
|
---|
[81c9e25] | 84 | <Button type="submit">Confirm</Button>
|
---|
[6729ba5] | 85 | </Form>
|
---|
| 86 | </Container>
|
---|
| 87 | );
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | export default EditProject; |
---|