Created
December 19, 2016 16:20
-
-
Save swallentin/311698b4b0cb47964aa49549d646fde9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.nn['autosave']; | |
const APP = ({children}) => ( | |
<AutoSaveContextProvider> | |
<div>{children}</div> | |
</AutoSaveContextProvider> | |
); | |
const SignupAssessmentComponent = () => (<h1>SignupAssessmentComponent</h1>); | |
const SignupPortfolioComponent = () => (<h1>SignupPortfolioComponent</h1>); | |
const SignupThankYouComponent = () => (<h1>SignupThankYouComponent</h1>); | |
const AssessmentComponent = () => (<h1>AssessmentComponent</h1>); | |
const PortfolioComponent = () => (<h1>PortfolioComponent</h1>); | |
const TermsAndConditionsComponent = () => (<h1>TermsAndConditionsComponent</h1>); | |
const DepositComponent = () => (<h1>DepositComponent</h1>); | |
const CompleteComponent = () => (<h1>CompleteComponent</h1>); | |
const ThankYouComponent = () => (<h1>ThankYouComponent</h1>); | |
const RouterSchemas = { | |
"signup": config => ({ | |
path: '/', | |
component: APP, | |
childRoutes: [ | |
{path: 'assessment', component: config.assessment}, | |
{path: 'portfolio', component: config.portfolio}, | |
{path: 'thankyou', component: config.thankyou}, | |
] | |
}), | |
"MVP": config => ({ | |
path: '/', | |
component: APP, | |
childRouter: [ | |
{path: 'assessment', component: config.assessment}, | |
{path: 'portfolio', component: config.portfolio}, | |
{path: 'toc', component: config.toc}, | |
{path: 'deposit', component: config.deposit}, | |
{path: 'complete', component: config.complete}, | |
{path: 'thankyou', component: config.thankyou}, | |
] | |
}) | |
}; | |
const RouterSchemasConfigurations = [ | |
{ | |
shouldHandle: ctx => ctx.market === 'SE' && ctx.MVP === false, | |
type: 'signup', | |
components: { | |
assessment: SignupAssessmentComponent, | |
portfolio: SignupPortfolioComponent, | |
thankyou: SignupThankYouComponent | |
}, | |
}, | |
{ | |
shouldHandle: ctx => ctx.market === 'SE' && ctx.MVP === true, | |
type: 'MVP', | |
components: { | |
assessment: AssessmentComponent, | |
portfolio: PortfolioComponent, | |
toc: TermsAndConditionsComponent, | |
deposit: DepositComponent, | |
complete: CompleteComponent, | |
thankyou: ThankYouComponent | |
}, | |
} | |
]; | |
const makeRoutes = ctx => { | |
const routeConfig = RouterSchemasConfigurations.filter(c => c.shouldHandle(ctx))[0]; | |
const routes = RouterSchemas[routeConfig.type](routeConfig); | |
return routes; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment