
-
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/containers/ChallengeEditor/index.js b/src/containers/ChallengeEditor/index.js
index 51ffaa26..910c2f01 100644
--- a/src/containers/ChallengeEditor/index.js
+++ b/src/containers/ChallengeEditor/index.js
@@ -30,6 +30,8 @@ import {
replaceResourceInRole
} from '../../actions/challenges'
+import { loadProject } from '../../actions/projects'
+
import { connect } from 'react-redux'
import { SUBMITTER_ROLE_UUID, MESSAGE } from '../../config/constants'
import { patchChallenge } from '../../services/challenges'
@@ -59,6 +61,7 @@ class ChallengeEditor extends Component {
this.closeSuccessModal = this.closeSuccessModal.bind(this)
this.onCloseTask = this.onCloseTask.bind(this)
this.closeTask = this.closeTask.bind(this)
+ this.fetchProjectDetails = this.fetchProjectDetails.bind(this)
}
componentDidMount () {
@@ -86,7 +89,6 @@ class ChallengeEditor extends Component {
loadGroups()
loadResourceRoles()
this.fetchChallengeDetails(match, loadChallengeDetails, loadResources)
-
// this.unlisten = this.props.history.listen(() => {
// const { isLoading } = this.props
// if (!isLoading) {
@@ -112,12 +114,23 @@ class ChallengeEditor extends Component {
}
}
+ async fetchProjectDetails (newMatch) {
+ let projectId = _.get(newMatch.params, 'projectId', null)
+ projectId = projectId ? parseInt(projectId) : null
+ if (projectId) {
+ await this.props.loadProject(projectId)
+ }
+ }
+
async fetchChallengeDetails (newMatch, loadChallengeDetails, loadResources) {
let projectId = _.get(newMatch.params, 'projectId', null)
projectId = projectId ? parseInt(projectId) : null
const challengeId = _.get(newMatch.params, 'challengeId', null)
await loadResources(challengeId)
loadChallengeDetails(projectId, challengeId)
+ if (!challengeId) {
+ this.fetchProjectDetails(newMatch)
+ }
}
isEditable () {
@@ -413,7 +426,8 @@ ChallengeEditor.propTypes = {
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
createChallenge: PropTypes.func.isRequired,
deleteChallenge: PropTypes.func.isRequired,
- replaceResourceInRole: PropTypes.func
+ replaceResourceInRole: PropTypes.func,
+ loadProject: PropTypes.func
// members: PropTypes.arrayOf(PropTypes.shape())
}
@@ -450,7 +464,8 @@ const mapDispatchToProps = {
partiallyUpdateChallengeDetails,
deleteChallenge,
createChallenge,
- replaceResourceInRole
+ replaceResourceInRole,
+ loadProject
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ChallengeEditor))
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)
+}