Skip to content

Instantly share code, notes, and snippets.

@mmcgahan
Created January 19, 2017 19:49
Show Gist options
  • Save mmcgahan/e565bcb27c1cfa54b0d9166e4bd2ff62 to your computer and use it in GitHub Desktop.
Save mmcgahan/e565bcb27c1cfa54b0d9166e4bd2ff62 to your computer and use it in GitHub Desktop.
index a2b9728..7143b31 100644
--- a/src/util/linksHelper.js
+++ b/src/util/linksHelper.js
@@ -1,6 +1,8 @@
import {
generateGroupRoute,
generateGroupCommunicationRoute,
+ generateRegisterRoute,
+ generateRegisterChildRoute,
} from './routesHelper';
/**
@@ -21,3 +23,11 @@ export function generateGroupUrl(urlname) {
export function generateGroupCommunicationUrl(urlname, communicationId) {
return `${generateGroupUrl(urlname)}/${generateGroupCommunicationRoute(communicationId)}`;
}
+
+/**
+ * Generates a register url
+ * @param {String} Optional child view of register
+ */
+export function generateRegisterUrl(view) {
+ return `${generateRegisterRoute()}/${generateRegisterChildRoute(view)}`;
+}
diff --git a/src/util/routesHelper.js b/src/util/routesHelper.js
index 53b1f99..470892e 100644
--- a/src/util/routesHelper.js
+++ b/src/util/routesHelper.js
@@ -15,3 +15,21 @@ export function generateGroupRoute(urlname = ':urlname') {
export function generateGroupCommunicationRoute(communicationId = ':communicationId') {
return `communications/${communicationId}`;
}
+
+/**
+ * Generates a register route
+ * @return {String} the register route
+ */
+export function generateRegisterRoute() {
+ return '/register';
+}
+
+/**
+ * Generates a child route for register
+ * @param {String} route the child view for register
+ * @return {String} the register child route
+ */
+export function generateRegisterChildRoute(route) {
+ const ROUTES = ['photo', 'questions', 'categories', 'topics', 'groups'];
+ return ROUTES.includes(route) ? `${route}/` : '';
+}
index f5161f5..d5b40fb 100644
--- a/src/features/register/RegisterContainer.jsx
+++ b/src/features/register/RegisterContainer.jsx
@@ -3,6 +3,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Link } from 'react-router';
+import { generateRegisterUrl } from '../../util/linksHelper';
import * as actionCreators from './registerActionCreators';
@@ -61,29 +62,26 @@ export class RegisterContainer extends React.Component {
*/
getNextRoute() {
- const REGISTER_ROOT = '/register';
-
- let nextRoute;
+ let nextStep;
switch(this.currentView) {
case 'photo':
- nextRoute = `${REGISTER_ROOT}/questions/`;
+ nextStep = 'questions';
break;
case 'questions':
- nextRoute = `${REGISTER_ROOT}/categories/`;
+ nextStep = 'categories';
break;
case 'categories':
- nextRoute = `${REGISTER_ROOT}/topics/`;
+ nextStep = 'topics';
break;
case 'topics':
- nextRoute = `${REGISTER_ROOT}/groups/`;
+ nextStep = 'groups';
break;
case 'groups':
- nextRoute = '/';
break;
}
- return nextRoute;
+ return nextStep ? generateRegisterUrl(nextStep) : '/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment