diff --git a/src/App.js b/src/App.js index b477422..b109fd8 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,7 @@ import { import { updateProfile } from './controllers/profile' import { + Login, About, Tasks, UpdateTask, @@ -33,7 +34,7 @@ console.log('Using API at ' + API) const defaultState = { loading: true, - user: { name: 'Scott' }, + user: {}, tasks: [], projects: [], component: 'projects', @@ -52,6 +53,8 @@ class App extends React.Component { this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) + this.login = this.login.bind(this) + this.createTask = createTask.bind(this) this.updateTask = updateTask.bind(this) this.deleteTask = deleteTask.bind(this) @@ -86,6 +89,19 @@ class App extends React.Component { } } + async login(userData) { + try { + const { data } = await axios.post(API + '/login', userData) + console.log('login retrieved data:', data) + if (data.name) { + this.setState({ user: data }) + this.navigate('projects') + } else this.setState({ error: 'no user found.' }) + } catch (err) { + console.log(err) + } + } + async fetchData() { const tasks = await this.fetchTasks() const projects = await this.fetchProjects() @@ -112,22 +128,26 @@ class App extends React.Component { return
Loading...
} renderError() { - if (this.state.error.message === 'Network Error') { - alert(`Failed to reach backend at\n${this.state.error.config.url}.`) - } else { - return ( -
- There was an error: {this.state.error.message} - -
- ) + const { error } = this.state + if (error) { + if (this.state.error.message === 'Network Error') { + alert(`Failed to reach backend at\n${this.state.error.config.url}.`) + } else { + return ( +
+ There was an error: {this.state.error.message} + +
+ ) + } } + return
Uncaught error. You probably forgot to render something.
} renderProfile() { return ( @@ -170,6 +190,10 @@ class App extends React.Component { renderAbout() { return } + + renderLogin() { + return + } renderTasks(filtered, completed) { return ( +
+ +
+ +
+
+
+ +
+ +
+
+ + + ) + } +} + +export default Login diff --git a/src/components/navbar.js b/src/components/navbar.js index 794ea42..13d448f 100644 --- a/src/components/navbar.js +++ b/src/components/navbar.js @@ -3,13 +3,23 @@ import React from 'react' function Navbar(props) { return (