Skip to content

Commit 79c9ece

Browse files
Got wizard working with pages that aren't wired up for redux forms validation.
1 parent 4e45ac9 commit 79c9ece

File tree

8 files changed

+232
-144
lines changed

8 files changed

+232
-144
lines changed

package-lock.json

Lines changed: 82 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"react-router-redux": "^5.0.0-alpha.9",
1414
"react-scripts": "2.1.5",
1515
"redux": "^4.0.1",
16+
"redux-form": "^8.1.0",
1617
"redux-thunk": "^2.3.0",
1718
"rrc": "^0.10.1"
1819
},
@@ -36,9 +37,12 @@
3637
"devDependencies": {
3738
"concurrently": "^4.1.0",
3839
"cross-fetch": "^3.0.1",
40+
"eslint-config-airbnb": "^17.1.0",
41+
"eslint-config-prettier": "^4.1.0",
42+
"eslint-plugin-prettier": "^3.0.1",
43+
"eslint-plugin-react": "^7.12.4",
3944
"onchange": "^5.2.0",
4045
"prettier": "^1.16.4",
41-
"redux-form": "^8.1.0",
4246
"redux-immutable-state-invariant": "^2.1.0"
4347
}
4448
}

src/modules/rootReducer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import userContext from "./userContext";
55
import busyIndicator from "./busyIndicator";
66
import pendingRequest from "./pendingRequest";
77
import notificationPopup from "./notificationPopup";
8+
import wizard from "./wizard";
89
import httpCache from "./httpCache";
910

1011
export default combineReducers({
@@ -13,6 +14,7 @@ export default combineReducers({
1314
[pendingRequest.constants.STATE_NAME]: pendingRequest.reducer,
1415
[httpCache.constants.STATE_NAME]: httpCache.reducer,
1516
[notificationPopup.constants.STATE_NAME]: notificationPopup.reducer,
17+
[wizard.constants.STATE_NAME]: wizard.reducer,
1618
form: formReducer,
1719
routing: routerReducer
1820
});

src/modules/wizard/components/ValidatingReduxFormLogic.js

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, { Fragment } from "react";
2+
import { connect } from "react-redux";
3+
import {
4+
pageRequiresValidation,
5+
finishedDisposing,
6+
initialized,
7+
canTransition
8+
} from "../wizard.actions";
9+
import { getWizardState } from "../wizard.selectors";
10+
import { wizardStates } from "../wizard.constants";
11+
12+
class WizardPageContainer extends React.Component {
13+
componentDidMount() {
14+
this.transitionStateMachine(this.props);
15+
}
16+
17+
componentDidUpdate(prevProps) {
18+
if (this.props.wizard.currentState !== prevProps.wizard.currentState) {
19+
this.transitionStateMachine(this.props);
20+
}
21+
}
22+
23+
transitionStateMachine(nextProps) {
24+
switch (nextProps.wizard.currentState) {
25+
case wizardStates.INITIALIZING: {
26+
if (!nextProps.requiresInitialization) {
27+
nextProps.initialized();
28+
}
29+
break;
30+
}
31+
case wizardStates.PAGE_INITIALIZED: {
32+
if (nextProps.requiresValidation) {
33+
nextProps.requiresValidation();
34+
} else {
35+
nextProps.canTransition();
36+
}
37+
break;
38+
}
39+
case wizardStates.DISPOSING: {
40+
nextProps.finishedDisposing();
41+
break;
42+
}
43+
default: {
44+
break;
45+
}
46+
}
47+
}
48+
49+
render() {
50+
return <Fragment>{this.props.children}</Fragment>;
51+
}
52+
}
53+
54+
const mapStateToProps = state => {
55+
return {
56+
wizard: getWizardState(state)
57+
};
58+
};
59+
60+
const mapDispatchToProps = {
61+
pageRequiresValidation,
62+
finishedDisposing,
63+
initialized,
64+
canTransition
65+
};
66+
67+
export default connect(
68+
mapStateToProps,
69+
mapDispatchToProps
70+
)(WizardPageContainer);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Wizard from "./WizardContainer";
22
import ValidatingReduxFormWizardPage from "./ValidatingReduxFormWizardPageContainer";
33
import WithReduxFormWizardPageValidation from "./WithReduxFormWizardPageValidation";
4+
import WizardPage from "./WizardPageContainer";
45

56
export default {
67
Wizard,
78
ValidatingReduxFormWizardPage,
8-
WithReduxFormWizardPageValidation
9+
WithReduxFormWizardPageValidation,
10+
WizardPage
911
};

0 commit comments

Comments
 (0)