Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Merge pull request #386 from kumar303/merge-errors
Browse files Browse the repository at this point in the history
Store/retrieve app state all in one place (fixes #347)
  • Loading branch information
kumar303 committed Sep 3, 2015
2 parents ca82ee2 + fd4892e commit 6c69205
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
8 changes: 5 additions & 3 deletions public/js/apps/management/app.jsx
Expand Up @@ -33,6 +33,7 @@ export default class ManagementApp extends Component {
Management: PropTypes.func,
PayMethods: PropTypes.func,
SignIn: PropTypes.func,
app: PropTypes.object.isRequired,
dispatch: PropTypes.func,
management: PropTypes.object.isRequired,
user: PropTypes.object.isRequired,
Expand All @@ -48,7 +49,7 @@ export default class ManagementApp extends Component {

render() {

const { dispatch, management, user } = this.props;
const { app, dispatch, management, user } = this.props;

console.log('rendering management app at tab:', management.tab);
var qs = parseQuery(this.props.window.location.href);
Expand All @@ -67,9 +68,9 @@ export default class ManagementApp extends Component {
var PayMethods = this.props.PayMethods;
var SignIn = this.props.SignIn;

if (management.error) {
if (app.error) {
children.push(
<ModalError {...boundMgmtActions} error={management.error} />
<ModalError {...boundMgmtActions} error={app.error} />
);
} else if (management.view === 'SHOW_MY_ACCOUNT') {
console.log('Showing pay methods');
Expand Down Expand Up @@ -171,6 +172,7 @@ export default class ManagementApp extends Component {

function select(state) {
return {
app: state.app,
management: state.management,
user: state.user,
};
Expand Down
1 change: 1 addition & 0 deletions public/js/reducers/app.js
Expand Up @@ -3,6 +3,7 @@ import * as actionTypes from 'constants/action-types';

export const initialAppState = {
csrfToken: null,
error: null,
};


Expand Down
7 changes: 0 additions & 7 deletions public/js/reducers/management.js
Expand Up @@ -2,7 +2,6 @@ import * as actionTypes from 'constants/action-types';


export const initialMgmtState = {
error: null,
tab: null,
view: null,
viewData: {},
Expand All @@ -21,12 +20,6 @@ export default function management(state, action) {
});
}
return state;
case actionTypes.APP_ERROR:
return Object.assign({}, initialMgmtState, {
error: {
debugMessage: action.error.debugMessage,
},
});
case actionTypes.GOT_SUBS_BY_PAY_METHOD:
return Object.assign({}, initialMgmtState, state, {
// This is short-lived data only relevant to the current
Expand Down
15 changes: 15 additions & 0 deletions tests/apps/test.management-app.jsx
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
import { Provider } from 'react-redux';

import * as appActions from 'actions/app';
import { createReduxStore } from 'data-store';

import ManagementApp from 'apps/management/app';
Expand Down Expand Up @@ -66,4 +67,18 @@ describe('management/app', function() {

});

it('should display app errors', function() {
var view = mountView();

var appError = appActions.error('some error');
store.dispatch(appError);

var mgmt = TestUtils.findRenderedComponentWithType(
view, FakeManagement
);
var errorPane = mgmt.props.children[0];
assert.deepEqual(errorPane.props.error, appError.error);

});

});
2 changes: 1 addition & 1 deletion tests/reducers/test.app-reducer.js
Expand Up @@ -42,7 +42,7 @@ describe('App Reducer', function() {
});

it('should store CSRF token', function() {
var app = appReducer({}, {
var app = appReducer(initialAppState, {
type: actionTypes.GOT_CSRF_TOKEN,
csrfToken: 'some-csrf-token',
});
Expand Down

0 comments on commit 6c69205

Please sign in to comment.