Skip to content

Commit

Permalink
Wrap pages within common sidebar and navigation bar (#185)
Browse files Browse the repository at this point in the history
* chore(commonWrapper): wrap components under common  sidebar and navbar

 - redirect to login if not authenticated
 - remove hero, navbar and sidebar component from dashboard component

* chore(commonWrapper): add user's society in state

* chore(commonWrapper): add user's society image in society stats component

 - pass down user's society as props to society stats component
 - add society images

* chore(commonWrapper): refactor tests to add society
  • Loading branch information
Chris Maina authored and Kachulio1 committed Feb 20, 2019
1 parent 9508eec commit 238d225
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 48 deletions.
27 changes: 21 additions & 6 deletions src/app/Authentication/components/AuthenticateRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import {
withRouter,
} from 'react-router-dom';

import {
HeroComponent,
NavbarComponent,
SidebarComponent,
} from '../../common/components';
import LoginComponent from '../../Login/components';


/**
* @name _Authenticate
* Authenticates routes. If not authenticated returns a message
Expand All @@ -16,13 +24,20 @@ export const Authenticate = ({ component: Component, isAuthenticated, ...rest })
render={
(props) => {
if (isAuthenticated) {
return <Component {...props} />;
return (
<div className='wrapper'>
<HeroComponent />
<div className='main-content'>
<SidebarComponent className='sidebar' />
<div className='sub-content'>
<NavbarComponent />
<Component {...props} />
</div>
</div>
</div>
);
}
return (
<div>
<h1> PLEASE LOGIN. NOT AUTHORIZED </h1>
</div>
);
return (<LoginComponent />);
}
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';

import { Authenticate } from '../AuthenticateRoute';
import LoginComponent from '../../../Login/components';

describe('<AuthenticateRoute />', () => {
const setUpWrapper = ({
Expand All @@ -20,9 +21,9 @@ describe('<AuthenticateRoute />', () => {
expect(wrapper.find('Route').exists()).toBe(true);
});

it('renders error message when component is not authenticated', () => {
it('renders Login component when component is not authenticated', () => {
const wrapper = setUpWrapper({ isAuthenticated: false});
wrapper.props().render({ isAuthenticated: false });
expect(wrapper.props().render({ isAuthenticated: false })).toEqual(<div><h1> PLEASE LOGIN. NOT AUTHORIZED </h1></div>);
expect(wrapper.props().render({ isAuthenticated: false })).toEqual(<LoginComponent />);
});
});
60 changes: 26 additions & 34 deletions src/app/Dashboard/components/DashboardComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

import {
HeroComponent, NavbarComponent, SidebarComponent, ButtonComponent,
} from '../../common/components';
import { ButtonComponent } from '../../common/components';
import MyStatsComponent from './MyStatsComponent';
import SocietyStatsComponent from './SocietyStatsComponent';

Expand All @@ -24,6 +22,7 @@ export class DashboardComponent extends Component {
*/
static defaultProps = {
error: {},
society: '',
loading: false,
pointsEarned: 0,
activitiesLogged: 0,
Expand All @@ -38,6 +37,7 @@ export class DashboardComponent extends Component {
*/
static propTypes = {
loading: PropTypes.bool,
society: PropTypes.string,
error: PropTypes.shape({}),
pointsEarned: PropTypes.number,
activitiesLogged: PropTypes.number,
Expand All @@ -54,7 +54,7 @@ export class DashboardComponent extends Component {

render() {
const {
error, loading, pointsEarned, activitiesLogged,
error, society, loading, pointsEarned, activitiesLogged,
} = this.props;
const { user } = this.state;
let dashboardHtml;
Expand All @@ -64,36 +64,27 @@ export class DashboardComponent extends Component {
dashboardHtml = <p>The was an error while fetching your data. Please try again later.</p>;
} else {
dashboardHtml = (
<div className='wrapper'>
<HeroComponent />
<div className='main-content'>
<SidebarComponent className='sidebar' />
<div className='sub-content'>
<NavbarComponent />
<div className='user-dashboard'>
<h2 className='user-dashboard__name col-sm-12'>{user.name}</h2>
<div className='col-sm-12'>
<h3 className='user-dashboard__level'>D2</h3>
</div>
<div className='profile-overview col-sm-12'>
<div className='profile-overview__image' />
<MyStatsComponent points={pointsEarned} activities={activitiesLogged} />
<SocietyStatsComponent usedPoints={1508} remainingPoints={326} />
</div>
<div className='user-dashboard__actions col-sm-12'>
<h3 className='user-dashboard__title'>My Activities</h3>
<div>
<ButtonComponent className='user-dashboard__button button__add'>
<span className='fa fa-plus' />
<span>Log Points</span>
</ButtonComponent>
<ButtonComponent className='user-dashboard__button button__filter'>
<span>Filter</span>
<span className='fa fa-filter' />
</ButtonComponent>
</div>
</div>
</div>
<div className='user-dashboard'>
<h2 className='user-dashboard__name col-sm-12'>{user.name}</h2>
<div className='col-sm-12'>
<h3 className='user-dashboard__level'>D2</h3>
</div>
<div className='profile-overview col-sm-12'>
<div className='profile-overview__image' />
<MyStatsComponent points={pointsEarned} activities={activitiesLogged} />
<SocietyStatsComponent society={society} usedPoints={1508} remainingPoints={326} />
</div>
<div className='user-dashboard__actions col-sm-12'>
<h3 className='user-dashboard__title'>My Activities</h3>
<div>
<ButtonComponent className='button__add'>
<span className='fa fa-plus' />
<span>Log Points</span>
</ButtonComponent>
<ButtonComponent className='button__filter'>
<span>Filter</span>
<span className='fa fa-filter' />
</ButtonComponent>
</div>
</div>
</div>
Expand All @@ -105,6 +96,7 @@ export class DashboardComponent extends Component {

const mapStateToProps = ({ dashboard }) => ({
error: null,
society: dashboard.society,
loading: dashboard.loading,
pointsEarned: dashboard.pointsEarned,
userActivities: dashboard.userActivities,
Expand Down
6 changes: 4 additions & 2 deletions src/app/Dashboard/components/SocietyStatsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { societyStats } from '../constants';

const SocietyStatsComponent = (props) => {
const { usedPoints, remainingPoints } = props;
const { society, usedPoints, remainingPoints } = props;
return (
<div className='society-stats'>
<div className='progress'>
Expand Down Expand Up @@ -44,19 +44,21 @@ const SocietyStatsComponent = (props) => {
{remainingPoints}
<span className='stats__description__figure-subsc '>Points</span>
</p>
<span className='society-stats__desc__logo' />
<span className={`society-stats__desc__logo ${society.toLowerCase()}`} />
</div>
</div>
);
};


SocietyStatsComponent.defaultProps = {
society: societyStats.society,
usedPoints: societyStats.usedPoints,
remainingPoints: societyStats.remainingPoints,
};

SocietyStatsComponent.propTypes = {
society: PropTypes.string,
usedPoints: PropTypes.number,
remainingPoints: PropTypes.number,
};
Expand Down
1 change: 1 addition & 0 deletions src/app/Dashboard/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const myStats = {
};

export const societyStats = {
society: '',
usedPoints: 0,
remainingPoints: 0,
};
3 changes: 2 additions & 1 deletion src/app/Dashboard/operations/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const fetchUserActivitiesRequest = userId => ({
userId,
});

const fetchUserActivitiesSuccess = (activites, pointsEarned, activitiesLogged) => ({
const fetchUserActivitiesSuccess = (activites, pointsEarned, activitiesLogged, society) => ({
society,
activites,
pointsEarned,
activitiesLogged,
Expand Down
4 changes: 3 additions & 1 deletion src/app/Dashboard/operations/dashboard.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { get } from '../../utils/api';
export function* fetchUserActivities(action) {
try {
const result = yield call(get, `users/${action.userId}/logged-activities`);
yield put(actions.fetchUserActivitiesSuccess(result.data, result.pointsEarned, result.activitiesLogged));
yield put(
actions.fetchUserActivitiesSuccess(result.data, result.pointsEarned, result.activitiesLogged, result.society),
);
} catch (error) {
yield put(actions.fetchUserActivitiesError(error));
}
Expand Down
1 change: 1 addition & 0 deletions src/app/Dashboard/operations/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const dashboard = (state = initialState.dashboard, action) => {
return {
...state,
loading: false,
society: action.society,
pointsEarned: action.pointsEarned,
userActivities: action.activities,
activitiesLogged: action.activitiesLogged,
Expand Down
1 change: 1 addition & 0 deletions src/app/Dashboard/operations/tests/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const myloggedActivities = {
activitiesLogged: 4,
data: activities,
pointsEarned: 300,
society: 'Phoenix',
}

export default activities;
6 changes: 5 additions & 1 deletion src/app/Dashboard/operations/tests/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Dashboard reducer', () => {
}),
).toEqual({
error: null,
society: '',
loading: true,
pointsEarned: 0,
userActivities: [],
Expand All @@ -39,6 +40,7 @@ describe('Dashboard reducer', () => {
}),
).toEqual({
error,
society: '',
loading: false,
pointsEarned: 0,
userActivities: [],
Expand All @@ -49,13 +51,15 @@ describe('Dashboard reducer', () => {

describe('handles case FETCH_USER_ACTIVITIES_SUCCESS', () => {
it('returns poinstEarned, activitiesLogged and userActivities', () => {
const { data, pointsEarned, activitiesLogged } = myloggedActivities;
const { data, society, pointsEarned, activitiesLogged } = myloggedActivities;
expect(dashboard(defaultState, {
type: types.FETCH_USER_ACTIVITIES_SUCCESS,
society,
activities: data,
pointsEarned,
activitiesLogged,
})).toEqual({
society,
error: null,
pointsEarned,
loading: false,
Expand Down
13 changes: 12 additions & 1 deletion src/app/Dashboard/styles/societyStats.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@
background-position: center;
background-size: contain;
background-repeat: no-repeat;
background-image: url(../../../images/societyLogos/istelle.png);
&.phoenix {
background-image: url(../../../images/societyLogos/phoenix.png);
}
&.istelle {
background-image: url(../../../images/societyLogos/istelle.png);
}
&.invictus {
background-image: url(../../../images/societyLogos/invictus.jpg);
}
&.sparks {
background-image: url(../../../images/societyLogos/sparks.png);
}
}

// Large devices (desktops/mac, 992px and up)
Expand Down
Binary file added src/images/societyLogos/invictus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/societyLogos/phoenix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/societyLogos/sparks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/reducers/initialState.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const initialState = {
dashboard: {
error: null,
society: '',
loading: false,
pointsEarned: 0,
userActivities: [],
Expand Down

0 comments on commit 238d225

Please sign in to comment.