From 5033790ae8e31dfdf0306765af03a8ea19838dcf Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 3 Aug 2018 16:54:19 -0400 Subject: [PATCH] Move route creation code from USFS into here --- app.js | 6 ++--- js/routes.jsx | 65 ++++++++++++++++++++++++++++++++++++++--------- package-lock.json | 22 ++++++++-------- package.json | 3 ++- 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index d763964..d4ba366 100644 --- a/app.js +++ b/app.js @@ -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'; @@ -21,7 +21,7 @@ ReactDOM.render( ( - {route} + {makeRoutes(withRouter)} ), document.getElementById('root') diff --git a/js/routes.jsx b/js/routes.jsx index 0787706..1daa227 100644 --- a/js/routes.jsx +++ b/js/routes.jsx @@ -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, + }; +} diff --git a/package-lock.json b/package-lock.json index 27c6c8e..58a21c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1814,9 +1814,9 @@ "dev": true }, "chain-function": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/chain-function/-/chain-function-1.0.0.tgz", - "integrity": "sha1-DUqzfn4Y6tC9xHuSB2QRjOWHM9w=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/chain-function/-/chain-function-1.0.1.tgz", + "integrity": "sha512-SxltgMwL9uCko5/ZCLiyG2B7R9fY4pDZUw7hJ4MhirdjBLosoDqkWABi3XMucddHdLiFJMb7PD2MZifZriuMTg==" }, "chalk": { "version": "1.1.3", @@ -7283,9 +7283,9 @@ "dev": true }, "raven-js": { - "version": "3.26.3", - "resolved": "https://registry.npmjs.org/raven-js/-/raven-js-3.26.3.tgz", - "integrity": "sha512-VPAsPfK73A9VPcJx5X/kt0GxOqUGpGDM8vdzsYNQXMhYemyZGiW1JX1AI+f4jxm37Apijj6VVtCyJcYFz3ocSQ==" + "version": "3.26.4", + "resolved": "https://registry.npmjs.org/raven-js/-/raven-js-3.26.4.tgz", + "integrity": "sha512-5VmC3IWhTQJkaiQaCY0S5V8za4bpUgbbuVT1MkDH7JVqgu8CPQ750XaFF8BVRbLV9F5nvoz7n0UT0CKteDuZAg==" }, "raw-body": { "version": "2.3.2", @@ -7373,6 +7373,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/react-router/-/react-router-3.2.1.tgz", "integrity": "sha512-SXkhC0nr3G0ltzVU07IN8jYl0bB6FsrDIqlLC9dK3SITXqyTJyM7yhXlUqs89w3Nqi5OkXsfRUeHX+P874HQrg==", + "dev": true, "requires": { "create-react-class": "^15.5.1", "history": "^3.0.0", @@ -7386,7 +7387,8 @@ "hoist-non-react-statics": { "version": "2.5.5", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", - "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" + "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==", + "dev": true } } }, @@ -8930,9 +8932,8 @@ } }, "us-forms-system": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/us-forms-system/-/us-forms-system-1.0.1.tgz", - "integrity": "sha512-4y41TmPhw/7wY+vV/o52FOTBhhHHoM9h5oUHaCZtyilaFzc2KM5r8qWxgbphKZ9Itk6pysG7ami2+q3CqdPkww==", + "version": "github:dmethvin-gov/us-forms-system#417c46d1b249b5ad41a5fd3c23f1354d15260880", + "from": "github:dmethvin-gov/us-forms-system#no-router", "requires": { "@department-of-veterans-affairs/react-jsonschema-form": "^1.0.0", "classnames": "^2.2.5", @@ -8942,7 +8943,6 @@ "moment": "^2.15.1", "raven-js": "^3.12.1", "react-redux": "4.4.8", - "react-router": "3", "react-scroll": "^1.7.9", "react-transition-group": "^1.1.2", "recompose": "^0.21.2", diff --git a/package.json b/package.json index 0a8521b..4feda3e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } }