4 changed files with 94 additions and 119 deletions
@ -1,123 +1,55 @@ |
|||||||
import React from "react"; |
import React from "react" |
||||||
|
import { Link } from "react-router-dom" |
||||||
|
import axios from "axios" |
||||||
|
|
||||||
|
const Todo = props => ( |
||||||
|
<tr> |
||||||
|
<td> {props.todo.todo_description} </td> |
||||||
|
<td> {props.todo.todo_responsible} </td> |
||||||
|
<td> {props.todo.todo_priority} </td> |
||||||
|
<td> |
||||||
|
<Link to={`/edit/${props.todo._id}`}>Edit</Link> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
) |
||||||
|
|
||||||
export default class TodosList extends React.Component { |
export default class TodosList extends React.Component { |
||||||
constructor(props) { |
constructor(props) { |
||||||
super(props); |
super(props); |
||||||
|
|
||||||
this.state = { |
this.state = { todos: [] }; |
||||||
todo_description: "", |
} |
||||||
todo_responsible: "", |
|
||||||
todo_priority: "", |
componentDidMount() { |
||||||
todo_completed: false |
axios.get('http://localhost:4000/todos/') |
||||||
}; |
.then(response => { this.setState({ todos: response.data }) }) |
||||||
|
.catch( error => { console.log(error) }) |
||||||
this.onChangeTodoDescription = this.onChangeTodoDescription.bind(this); |
} |
||||||
this.onChangeTodoResponsible = this.onChangeTodoResponsible.bind(this); |
|
||||||
this.onChangeTodoPriority = this.onChangeTodoPriority.bind(this); |
todoList() { |
||||||
this.onSubmit = this.onSubmit.bind(this); |
return this.state.todos.map((currentTodo, item) => { |
||||||
} |
return <Todo todo={currentTodo} key={item} /> |
||||||
|
}) |
||||||
onChangeTodoDescription(event) { |
} |
||||||
this.setState({ todo_description: event.target.value }); |
|
||||||
} |
render() { |
||||||
|
return ( |
||||||
onChangeTodoResponsible(event) { |
<div> |
||||||
this.setState({ todo_responsible: event.target.value }); |
<h3>Todos List</h3> |
||||||
} |
<table className="table table-striped" style={{ marginTop: 20 }} > |
||||||
|
<thead> |
||||||
onChangeTodoPriority(event) { |
<tr> |
||||||
this.setState({ todo_priority: event.target.value }); |
<th>Description</th> |
||||||
} |
<th>Responsible</th> |
||||||
|
<th>Priority</th> |
||||||
onSubmit(event) { |
<th>Action</th> |
||||||
event.preventDefault(); |
</tr> |
||||||
|
</thead> |
||||||
console.log(`Form submitted:`); |
<tbody> |
||||||
console.log(`Todo Description: ${this.state.todo_description}`); |
{ this.todoList() } |
||||||
console.log(`Todo Responsible: ${this.state.todo_responsible}`); |
</tbody> |
||||||
console.log(`Todo Priority: ${this.state.todo_priority}`); |
</table> |
||||||
|
|
||||||
this.setState({ |
|
||||||
todo_description: "", |
|
||||||
todo_responsible: "", |
|
||||||
todo_priority: "", |
|
||||||
todo_completed: false |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
render() { |
|
||||||
return ( |
|
||||||
<div> |
|
||||||
<div style={{ marginTop: 10 }}> |
|
||||||
<h3>Create New Todo</h3> |
|
||||||
<form onSubmit={this.onSubmit}> |
|
||||||
<div className="form-group"> |
|
||||||
<label>Description: </label> |
|
||||||
<input |
|
||||||
type="text" |
|
||||||
className="form-control" |
|
||||||
value={this.state.todo_description} |
|
||||||
onChange={this.onChangeTodoDescription} |
|
||||||
/> |
|
||||||
</div> |
|
||||||
<div className="form-group"> |
|
||||||
<label>Responsible: </label> |
|
||||||
<input |
|
||||||
type="text" |
|
||||||
className="form-control" |
|
||||||
value={this.state.todo_responsible} |
|
||||||
onChange={this.onChangeTodoResponsible} |
|
||||||
/> |
|
||||||
</div> |
|
||||||
<div className="form-group"> |
|
||||||
<div className="form-check form-check-inline"> |
|
||||||
<input |
|
||||||
className="form-check-input" |
|
||||||
type="radio" |
|
||||||
name="priorityOptions" |
|
||||||
id="priorityLow" |
|
||||||
value="Low" |
|
||||||
checked={this.state.todo_priority === "Low"} |
|
||||||
onChange={this.onChangeTodoPriority} |
|
||||||
/> |
|
||||||
<label className="form-check-label">Low</label> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
<div className="form-group"> |
|
||||||
<div className="form-check form-check-inline"> |
|
||||||
<input |
|
||||||
className="form-check-input" |
|
||||||
type="radio" |
|
||||||
name="priorityOptions" |
|
||||||
id="priorityMedium" |
|
||||||
value="Medium" |
|
||||||
checked={this.state.todo_priority === "Medium"} |
|
||||||
onChange={this.onChangeTodoPriority} |
|
||||||
/> |
|
||||||
<label className="form-check-label">Medium</label> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
<div className="form-group"> |
|
||||||
<div className="form-check form-check-inline"> |
|
||||||
<input |
|
||||||
className="form-check-input" |
|
||||||
type="radio" |
|
||||||
name="priorityOptions" |
|
||||||
id="priorityHigh" |
|
||||||
value="High" |
|
||||||
checked={this.state.todo_priority === "High"} |
|
||||||
onChange={this.onChangeTodoPriority} |
|
||||||
/> |
|
||||||
<label className="form-check-label">High</label> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
|
|
||||||
<div className="form-group"> |
|
||||||
<input type="submit" value="Create Todo" className="btn btn-primary"/> |
|
||||||
</div> |
</div> |
||||||
</form> |
) |
||||||
</div> |
} |
||||||
</div> |
|
||||||
); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue