diff --git a/package-lock.json b/package-lock.json index d26154d..f60a6c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2158,6 +2158,37 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "axobject-query": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.1.1.tgz", diff --git a/package.json b/package.json index 7272466..35ad80b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.4.0", "@testing-library/user-event": "^7.2.1", + "axios": "^0.19.2", "bootstrap": "^4.4.1", "react": "^16.12.0", "react-dom": "^16.12.0", diff --git a/src/components/create-todo.component.js b/src/components/create-todo.component.js index f86f76e..efd9134 100644 --- a/src/components/create-todo.component.js +++ b/src/components/create-todo.component.js @@ -1,4 +1,5 @@ import React from 'react' +import axios from 'axios' export default class CreateTodo extends React.Component { constructor(props) { @@ -43,6 +44,16 @@ export default class CreateTodo extends React.Component { console.log(`Todo Responsible: ${this.state.todo_responsible}`) console.log(`Todo Priority: ${this.state.todo_priority}`) + const newTodo = { + todo_description: this.state.todo_description, + todo_responsible: this.state.todo_responsible, + todo_priority: this.state.todo_priority, + todo_completed: this.state.todo_completed + } + + axios.post('http://localhost:4000/todos/add', newTodo) + .then(res => console.log(res.data)) + this.setState({ todo_description: '', todo_responsible: '', diff --git a/src/components/todos-list.component.js b/src/components/todos-list.component.js index 84cac05..3513e83 100644 --- a/src/components/todos-list.component.js +++ b/src/components/todos-list.component.js @@ -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 => ( + + {props.todo.todo_description} + {props.todo.todo_responsible} + {props.todo.todo_priority} + + Edit + + +) export default class TodosList extends React.Component { - constructor(props) { - super(props); - - this.state = { - todo_description: "", - todo_responsible: "", - todo_priority: "", - todo_completed: false - }; - - this.onChangeTodoDescription = this.onChangeTodoDescription.bind(this); - this.onChangeTodoResponsible = this.onChangeTodoResponsible.bind(this); - this.onChangeTodoPriority = this.onChangeTodoPriority.bind(this); - this.onSubmit = this.onSubmit.bind(this); - } - - onChangeTodoDescription(event) { - this.setState({ todo_description: event.target.value }); - } - - onChangeTodoResponsible(event) { - this.setState({ todo_responsible: event.target.value }); - } - - onChangeTodoPriority(event) { - this.setState({ todo_priority: event.target.value }); - } - - onSubmit(event) { - event.preventDefault(); - - console.log(`Form submitted:`); - console.log(`Todo Description: ${this.state.todo_description}`); - console.log(`Todo Responsible: ${this.state.todo_responsible}`); - console.log(`Todo Priority: ${this.state.todo_priority}`); - - this.setState({ - todo_description: "", - todo_responsible: "", - todo_priority: "", - todo_completed: false - }); - } - - render() { - return ( -
-
-

Create New Todo

-
-
- - -
-
- - -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- -
- + constructor(props) { + super(props); + + this.state = { todos: [] }; + } + + componentDidMount() { + axios.get('http://localhost:4000/todos/') + .then(response => { this.setState({ todos: response.data }) }) + .catch( error => { console.log(error) }) + } + + todoList() { + return this.state.todos.map((currentTodo, item) => { + return + }) + } + + render() { + return ( +
+

Todos List

+ + + + + + + + + + + { this.todoList() } + +
DescriptionResponsiblePriorityAction
- -
-
- ); - } + ) + } }