Skip to content

Commit

Permalink
Primitive dashboard display
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanSarder committed May 7, 2017
1 parent 747232a commit a2b7f12
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 311 deletions.
9 changes: 7 additions & 2 deletions app/actions/actions.jsx
Expand Up @@ -64,8 +64,13 @@ export let fetchItems = () => {
dispatch(finishFetch());
})
.catch((err) => {
dispatch(errorMessage(err.response.data.message));
dispatch(finishFetch());
if (err.response) {
dispatch(errorMessage(err.response.data.message));
dispatch(finishFetch());
} else {
dispatch(errorMessage('Oops. Something went wrong! Try again.'));
dispatch(finishFetch());
}
})
}
}
31 changes: 27 additions & 4 deletions app/components/Dashboard.jsx
@@ -1,24 +1,47 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import {Redirect, withRouter} from 'react-router-dom'
import * as actions from 'actions';

class DashBoard extends Component {
constructor(props) {
super(props);
}
componentWillMount() {
this.props.dispatch(actions.fetchItems());
}
render() {
let {items} = this.props;
let renderItems = () => {
if (!items) {
return
}
return items.map((item) => {
let {action, author} = item.logs[item.logs.length-1];
return(<div className="dashboard-item">
<p>{item.name}</p>
<p>{item.number}</p>
<p>{item.state}</p>
<p>{`${action} by ${author}`}</p>
</div>)
})
}

if (this.props.auth.token) {
return (
<h2>Here will be dashboard with items.</h2>
<div className="dashboard-container">
{renderItems()}
</div>
);
} else {
return <Redirect to='/items/2'/>
return <Redirect to='/'/>
}
}
}

export default withRouter(connect(
export default connect(
(state) => {
return state;
}
)(DashBoard));
)(DashBoard);

12 changes: 0 additions & 12 deletions app/components/Home.jsx
Expand Up @@ -8,18 +8,6 @@ class Home extends Component {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
componentWillReceiveProps(nextProps) {
console.log('nextProps');
if (!nextProps.isLoading) {
if (nextProps.auth.error) {
console.log('error');
} else if (nextProps.auth.token) {
console.log('success');
} else {
console.log('something else');
}
}
}

handleSubmit(e) {
let {isLoading, auth, dispatch} = this.props
Expand Down
3 changes: 2 additions & 1 deletion app/styles/app.scss
@@ -1,2 +1,3 @@
@import "base/variables";
@import "components/home-form";
@import "components/home-form";
@import "components/dashboard";
9 changes: 9 additions & 0 deletions app/styles/components/_dashboard.scss
@@ -0,0 +1,9 @@
.dashboard-item {
width: 30%;
}

.dashboard-container {
display: flex;
align-content: space-around;
flex-wrap: wrap;
}
1 change: 1 addition & 0 deletions app/tests/actions/actions.test.jsx
Expand Up @@ -86,6 +86,7 @@ describe('ASYNC ACTIONS', () => {
expect(actions[2]).toInclude({type: 'FINISH_FETCH'});
expect(actions[1]).toInclude({type: 'ADD_ITEMS'});
expect(actions[1].items).toBeA('array');
expect(actions[1].items.length).toBeMoreThan(0);
done()
})
.catch(done);
Expand Down

0 comments on commit a2b7f12

Please sign in to comment.