Skip to content

Commit

Permalink
Move route creation code from USFS into here
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin-gov committed Aug 3, 2018
1 parent a8d2d8f commit 5033790
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { IndexRedirect, Route, Router, useRouterHistory } from 'react-router';
import { IndexRedirect, Route, Router, useRouterHistory, withRouter } from 'react-router';
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { createHistory } from 'history';

import 'us-forms-system/lib/css/styles.css';

import route from './js/routes.jsx';
import { makeRoutes } from './js/routes.jsx';
import reducer from './js/reducers';
import Form from './js/components/Form.jsx';

Expand All @@ -21,7 +21,7 @@ ReactDOM.render(
(
<Provider store={store}>
<Router history={browserHistory}>
{route}
{makeRoutes(withRouter)}
</Router>
</Provider>
), document.getElementById('root')
Expand Down
65 changes: 53 additions & 12 deletions js/routes.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
import { createRoutes } from 'us-forms-system/lib/js/helpers';

import formConfig from './config/form';
import Form from './components/Form.jsx';

const routes = createRoutes(formConfig);
import FormPage from 'us-forms-system/lib/js/containers/FormPage';
import ReviewPage from 'us-forms-system/lib/js/review/ReviewPage';

import { createFormPageList, createPageList } from 'us-forms-system/lib/js/helpers';

export function makeRoutes(withRouter) {
const formPages = createFormPageList(formConfig);
const pageList = createPageList(formConfig, formPages);
let routes = formPages
.map(page => {
return {
path: page.path,
component: withRouter(page.component || FormPage),
pageConfig: page,
pageList,
urlPrefix: formConfig.urlPrefix
};
});
if (formConfig.introduction) {
routes = [
{
path: 'introduction',
component: withRouter(formConfig.introduction),
formConfig,
pageList
}
].concat(routes);
}

const route = {
path: '/',
component: Form,
indexRoute: {
onEnter: (nextState, replace) => replace(formConfig.urlPrefix+routes[0].path)
},
childRoutes: routes,
};
routes = routes.concat([
{
path: 'review-and-submit',
formConfig,
component: withRouter(ReviewPage),
pageList
},
{
path: 'confirmation',
component: formConfig.confirmation //withRouter
},
{
path: '*',
onEnter: (nextState, replace) => replace(formConfig.urlPrefix || '/')
}
]);

export default route;
return {
path: '/',
component: Form,
indexRoute: {
onEnter: (nextState, replace) => replace(formConfig.urlPrefix+routes[0].path)
},
childRoutes: routes,
};
}
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"css-loader": "^0.28.11",
"react": "^15.6.2",
"react-dom": "^15.6.2",
"react-router": "3",
"style-loader": "^0.21.0",
"svg-url-loader": "^2.3.2",
"url-loader": "^1.0.1",
Expand All @@ -35,6 +36,6 @@
"webpack-merge": "^4.1.3"
},
"dependencies": {
"us-forms-system": "^1.0.1"
"us-forms-system": "dmethvin-gov/us-forms-system.git#no-router"
}
}

0 comments on commit 5033790

Please sign in to comment.