
-
Work Manager
+
+ Work Manager
+ {isBetaMode() && beta}
+
All Work
diff --git a/src/config/constants.js b/src/config/constants.js
index e8eab683..9cafe92f 100644
--- a/src/config/constants.js
+++ b/src/config/constants.js
@@ -113,6 +113,8 @@ export const SET_FILTER_CHALLENGE_VALUE = 'SET_FILTER_CHALLENGE_VALUE'
export const RESET_SIDEBAR_ACTIVE_PARAMS = 'RESET_SIDEBAR_ACTIVE_PARAMS'
+export const BETA_MODE_COOKIE_TAG = 'beta-mode'
+
// Name of challenge tracks
export const CHALLENGE_TRACKS = {
DESIGN: DES_TRACK_ID,
diff --git a/src/routes.js b/src/routes.js
index 2dad9624..70708384 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -5,6 +5,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { Redirect, Route, Switch, withRouter } from 'react-router-dom'
import _ from 'lodash'
+import { BETA_MODE_COOKIE_TAG } from './config/constants'
import renderApp from './components/App'
import TopBarContainer from './containers/TopbarContainer'
import Sidebar from './containers/Sidebar'
@@ -15,6 +16,7 @@ import { saveToken } from './actions/auth'
import { loadChallengeDetails } from './actions/challenges'
import { connect } from 'react-redux'
import { checkAllowedRoles } from './util/tc'
+import { setCookie, removeCookie, isBetaMode } from './util/cookie'
const { ACCOUNTS_APP_LOGIN_URL } = process.env
@@ -72,6 +74,19 @@ class Routes extends React.Component {
})
}
+ componentDidUpdate () {
+ const { search } = this.props.location
+ const params = new URLSearchParams(search)
+ if (!_.isEmpty(params.get('beta'))) {
+ if (params.get('beta') === 'true' && !isBetaMode()) {
+ setCookie(BETA_MODE_COOKIE_TAG, 'true')
+ } else if (params.get('beta') === 'false' && isBetaMode()) {
+ removeCookie(BETA_MODE_COOKIE_TAG)
+ }
+ this.props.history.push(this.props.location.pathname)
+ }
+ }
+
render () {
if (!this.props.isLoggedIn) {
return null
@@ -143,7 +158,8 @@ Routes.propTypes = {
saveToken: PropTypes.func,
location: PropTypes.object,
isLoggedIn: PropTypes.bool,
- token: PropTypes.string
+ token: PropTypes.string,
+ history: PropTypes.object
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Routes))
diff --git a/src/util/cookie.js b/src/util/cookie.js
new file mode 100644
index 00000000..b1242acb
--- /dev/null
+++ b/src/util/cookie.js
@@ -0,0 +1,34 @@
+/**
+ * Provides Cookie related utility methods
+ */
+
+import { BETA_MODE_COOKIE_TAG } from '../config/constants'
+
+/**
+ * A function that get's a cookie
+ */
+export function getCookie (name) {
+ const v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')
+ return v ? v[2] : undefined
+}
+
+/**
+ * A function that set's a cookie
+ */
+export function setCookie (name, value) {
+ document.cookie = `${name}=${value}; path=/`
+}
+
+/**
+ * A function that removes Cookie by setting expiry date to past
+ */
+export function removeCookie (name) {
+ document.cookie = `${name}=; path=/; expires=Thu, 18 Dec 2013 12:00:00 UTC;`
+}
+
+/**
+ * A function that checks whether beta mode is enabled or not
+ */
+export function isBetaMode () {
+ return getCookie(BETA_MODE_COOKIE_TAG)
+}