Skip to content

Commit 0c8b878

Browse files
author
vikasrohit
authored
Merge pull request #1060 from mark-nakachon/issue-#1058
fix issue-#1058
2 parents 6ca2894 + 9f18786 commit 0c8b878

File tree

7 files changed

+78
-16
lines changed

7 files changed

+78
-16
lines changed

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import PhaseInput from '../../PhaseInput'
2121
import LegacyLinks from '../../LegacyLinks'
2222
import AssignedMemberField from '../AssignedMember-Field'
2323
import { getResourceRoleByName } from '../../../util/tc'
24+
import { isBetaMode } from '../../../util/cookie'
2425
import { loadGroupDetails } from '../../../actions/challenges'
2526
import Tooltip from '../../Tooltip'
2627
import { MESSAGE, REVIEW_TYPES } from '../../../config/constants'
@@ -37,9 +38,8 @@ const ChallengeView = ({
3738
assignedMemberDetails,
3839
enableEdit,
3940
onLaunchChallenge,
40-
onCloseTask,
41-
location }) => {
42-
const params = new URLSearchParams(location.search)
41+
onCloseTask
42+
}) => {
4343
const selectedType = _.find(metadata.challengeTypes, { id: challenge.typeId })
4444
const challengeTrack = _.find(metadata.challengeTracks, { id: challenge.trackId })
4545

@@ -188,7 +188,7 @@ const ChallengeView = ({
188188
<span><span className={styles.fieldTitle}>Groups:</span> {groups}</span>
189189
</div>
190190
</div>
191-
{params.get('beta') && (
191+
{isBetaMode() && (
192192
<div className={styles.row}>
193193
<div className={styles.col}>
194194
<span>
@@ -283,8 +283,7 @@ ChallengeView.propTypes = {
283283
assignedMemberDetails: PropTypes.shape(),
284284
enableEdit: PropTypes.bool,
285285
onLaunchChallenge: PropTypes.func,
286-
onCloseTask: PropTypes.func,
287-
location: PropTypes.object
286+
onCloseTask: PropTypes.func
288287
}
289288

290289
export default withRouter(ChallengeView)

src/components/ChallengeEditor/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import LegacyLinks from '../LegacyLinks'
5050
import AssignedMemberField from './AssignedMember-Field'
5151
import Tooltip from '../Tooltip'
5252
import { getResourceRoleByName } from '../../util/tc'
53+
import { isBetaMode } from '../../util/cookie'
5354

5455
const theme = {
5556
container: styles.modalContainer
@@ -810,8 +811,7 @@ class ChallengeEditor extends Component {
810811

811812
async createNewChallenge () {
812813
if (!this.props.isNew) return
813-
const { metadata, createChallenge, projectDetail, location } = this.props
814-
const params = new URLSearchParams(location.search)
814+
const { metadata, createChallenge, projectDetail } = this.props
815815
const { name, trackId, typeId } = this.state.challenge
816816
const { timelineTemplates } = metadata
817817
const isDesignChallenge = trackId === DES_TRACK_ID
@@ -840,7 +840,7 @@ class ChallengeEditor extends Component {
840840
terms: [{ id: DEFAULT_TERM_UUID, roleId: SUBMITTER_ROLE_UUID }]
841841
// prizeSets: this.getDefaultPrizeSets()
842842
}
843-
if (params.get('beta') === 'true' && projectDetail.terms) {
843+
if (isBetaMode() && projectDetail.terms) {
844844
const currTerms = new Set(newChallenge.terms.map(term => term.id))
845845
newChallenge.terms.push(
846846
...projectDetail.terms
@@ -1126,8 +1126,6 @@ class ChallengeEditor extends Component {
11261126
}
11271127

11281128
render () {
1129-
const params = new URLSearchParams(this.props.location.search)
1130-
11311129
const {
11321130
isLaunch,
11331131
isConfirm,
@@ -1407,7 +1405,7 @@ class ChallengeEditor extends Component {
14071405
{/* remove terms field and use default term */}
14081406
{false && (<TermsField terms={metadata.challengeTerms} challenge={challenge} onUpdateMultiSelect={this.onUpdateMultiSelect} />)}
14091407
<GroupsField onUpdateMultiSelect={this.onUpdateMultiSelect} challenge={challenge} />
1410-
{params.get('beta') && (
1408+
{isBetaMode() && (
14111409
<div className={styles.row}>
14121410
<div className={styles.col}>
14131411
<span>
@@ -1548,8 +1546,7 @@ ChallengeEditor.propTypes = {
15481546
replaceResourceInRole: PropTypes.func,
15491547
partiallyUpdateChallengeDetails: PropTypes.func.isRequired,
15501548
deleteChallenge: PropTypes.func.isRequired,
1551-
loggedInUser: PropTypes.shape().isRequired,
1552-
location: PropTypes.object
1549+
loggedInUser: PropTypes.shape().isRequired
15531550
}
15541551

15551552
export default withRouter(ChallengeEditor)

src/components/Sidebar/Sidebar.module.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
color: $white;
2626
margin-bottom: 37px;
2727
padding-left: 30px;
28+
29+
.beta {
30+
font-size: 16px;
31+
color: $red;
32+
font-weight: bold;
33+
position: relative;
34+
top: -12px;
35+
left: 12px;
36+
}
2837
}
2938

3039
.homeLink {

src/components/Sidebar/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import cn from 'classnames'
88
import TopcoderLogo from '../../assets/images/topcoder-logo.png'
99
import styles from './Sidebar.module.scss'
1010

11+
import { isBetaMode } from '../../util/cookie'
12+
1113
const Sidebar = ({
1214
projectId, resetSidebarActiveParams
1315
}) => {
1416
return (
1517
<div className={styles.sidebar}>
1618
<img src={TopcoderLogo} className={styles.logo} />
17-
<div className={styles.title}>Work Manager</div>
19+
<div className={styles.title}>
20+
Work Manager
21+
{isBetaMode() && <span className={styles.beta}>beta</span>}
22+
</div>
1823
<Link to='/'>
1924
<div className={cn(styles.homeLink, { [styles.active]: !projectId })} onClick={resetSidebarActiveParams}>
2025
All Work

src/config/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export const SET_FILTER_CHALLENGE_VALUE = 'SET_FILTER_CHALLENGE_VALUE'
113113

114114
export const RESET_SIDEBAR_ACTIVE_PARAMS = 'RESET_SIDEBAR_ACTIVE_PARAMS'
115115

116+
export const BETA_MODE_COOKIE_TAG = 'beta-mode'
117+
116118
// Name of challenge tracks
117119
export const CHALLENGE_TRACKS = {
118120
DESIGN: DES_TRACK_ID,

src/routes.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React from 'react'
55
import PropTypes from 'prop-types'
66
import { Redirect, Route, Switch, withRouter } from 'react-router-dom'
77
import _ from 'lodash'
8+
import { BETA_MODE_COOKIE_TAG } from './config/constants'
89
import renderApp from './components/App'
910
import TopBarContainer from './containers/TopbarContainer'
1011
import Sidebar from './containers/Sidebar'
@@ -15,6 +16,7 @@ import { saveToken } from './actions/auth'
1516
import { loadChallengeDetails } from './actions/challenges'
1617
import { connect } from 'react-redux'
1718
import { checkAllowedRoles } from './util/tc'
19+
import { setCookie, removeCookie, isBetaMode } from './util/cookie'
1820

1921
const { ACCOUNTS_APP_LOGIN_URL } = process.env
2022

@@ -72,6 +74,19 @@ class Routes extends React.Component {
7274
})
7375
}
7476

77+
componentDidUpdate () {
78+
const { search } = this.props.location
79+
const params = new URLSearchParams(search)
80+
if (!_.isEmpty(params.get('beta'))) {
81+
if (params.get('beta') === 'true' && !isBetaMode()) {
82+
setCookie(BETA_MODE_COOKIE_TAG, 'true')
83+
} else if (params.get('beta') === 'false' && isBetaMode()) {
84+
removeCookie(BETA_MODE_COOKIE_TAG)
85+
}
86+
this.props.history.push(this.props.location.pathname)
87+
}
88+
}
89+
7590
render () {
7691
if (!this.props.isLoggedIn) {
7792
return null
@@ -143,7 +158,8 @@ Routes.propTypes = {
143158
saveToken: PropTypes.func,
144159
location: PropTypes.object,
145160
isLoggedIn: PropTypes.bool,
146-
token: PropTypes.string
161+
token: PropTypes.string,
162+
history: PropTypes.object
147163
}
148164

149165
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Routes))

src/util/cookie.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Provides Cookie related utility methods
3+
*/
4+
5+
import { BETA_MODE_COOKIE_TAG } from '../config/constants'
6+
7+
/**
8+
* A function that get's a cookie
9+
*/
10+
export function getCookie (name) {
11+
const v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')
12+
return v ? v[2] : undefined
13+
}
14+
15+
/**
16+
* A function that set's a cookie
17+
*/
18+
export function setCookie (name, value) {
19+
document.cookie = `${name}=${value}; path=/`
20+
}
21+
22+
/**
23+
* A function that removes Cookie by setting expiry date to past
24+
*/
25+
export function removeCookie (name) {
26+
document.cookie = `${name}=; path=/; expires=Thu, 18 Dec 2013 12:00:00 UTC;`
27+
}
28+
29+
/**
30+
* A function that checks whether beta mode is enabled or not
31+
*/
32+
export function isBetaMode () {
33+
return getCookie(BETA_MODE_COOKIE_TAG)
34+
}

0 commit comments

Comments
 (0)