import React from 'react' import axios from 'axios' export default class EditTodo extends React.Component { constructor(props) { super(props) this.onChangeTodoDescription = this.onChangeTodoDescription.bind(this); this.onChangeTodoResponsible = this.onChangeTodoResponsible.bind(this); this.onChangeTodoPriority = this.onChangeTodoPriority.bind(this); this.onChangeTodoCompleted = this.onChangeTodoCompleted.bind(this); this.onSubmit = this.onSubmit.bind(this); this.state = { todo_description: '', todo_responsible: '', todo_priority: '', todo_completed: false } } componentDidMount() { axios.get(`http://localhost:4000/todos/${this.props.match.params.id}`) .then ( response => { this.setState({ todo_description: response.data.todo_description, todo_responsible: response.data.todo_responsible, todo_priority: response.data.todo_priority, todo_completed: response.data.todo_completed } ) console.log("this.props.match.params", this.props.match.params) } ) .catch( (error) => { console.log(error) } ) } onChangeTodoDescription(e) { this.setState({ todo_description: e.target.value }); } onChangeTodoResponsible(e) { this.setState({ todo_responsible: e.target.value }); } onChangeTodoPriority(e) { this.setState({ todo_priority: e.target.value }); } onChangeTodoCompleted(e) { this.setState({ todo_completed: !this.state.todo_completed }); } onSubmit(e) { e.preventDefault(); const obj = { todo_description: this.state.todo_description, todo_responsible: this.state.todo_responsible, todo_priority: this.state.todo_priority, todo_completed: this.state.todo_completed }; console.log(obj); axios.post('http://localhost:4000/todos/update/'+this.props.match.params.id, obj) .then(res => console.log(res.data)); this.props.history.push('/'); } render() { return (

Update Todo


) } }