Skip to content

Commit

Permalink
Merge pull request #6899 from topcoder-platform/develop
Browse files Browse the repository at this point in the history
Prod deploy - Redirects for new apps and show reminder for all challenges
  • Loading branch information
jmgasper authored Jul 31, 2023
2 parents 61d2269 + 63d6aa1 commit a1c2a53
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 29 deletions.
1 change: 0 additions & 1 deletion config/custom-environment-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
},
DISABLE_SERVICE_WORKER: 'DISABLE_SERVICE_WORKER',
LOG_ENTRIES_TOKEN: 'LOG_ENTRIES_TOKEN',
TERM_NDA_ID: 'TERM_NDA_ID',
MOCK_TERMS_SERVICE: 'MOCK_TERMS_SERVICE',

NEWSLETTER_SIGNUP: {
Expand Down
5 changes: 2 additions & 3 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ module.exports = {
* agreement flow. */
MOCK_TERMS_SERVICE: false,

// Specifically for the terms ID that matches the NDA requirement.
TERM_NDA_ID: '',

/* Holds params to signup for different newsletters. */
NEWSLETTER_SIGNUP: {
DEFAUL_LIST_ID: '28bfd3c062',
Expand Down Expand Up @@ -476,5 +473,7 @@ module.exports = {
},
/* development id - makes surveys have warning about environment */
UNIVERSAL_NAV_URL: '//uni-nav.topcoder-dev.com/v1/tc-universal-nav.js',
MEMBER_PROFILE_REDIRECT_URL: 'https://profiles.topcoder-dev.com',
ACCOUNT_SETTINGS_REDIRECT_URL: 'https://account-settings.topcoder-dev.com',
SPRIG_ENVIRONMENT_ID: 'bUcousVQ0-yF',
};
3 changes: 0 additions & 3 deletions config/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ module.exports = {
},
PLATFORM_SITE_URL: 'https://platform.topcoder-dev.com',
PLATFORMUI_SITE_URL: 'https://platform-ui.topcoder-dev.com',

// Specifically for the terms ID that matches the NDA requirement.
TERM_NDA_ID: 'e5811a7b-43d1-407a-a064-69e5015b4900',
};
5 changes: 2 additions & 3 deletions config/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ module.exports = {
DICE_VERIFY_URL: 'https://accounts-auth0.topcoder.com',
/* development id - makes surveys have warning about environment */
UNIVERSAL_NAV_URL: '//uni-nav.topcoder.com/v1/tc-universal-nav.js',
MEMBER_PROFILE_REDIRECT_URL: 'https://profiles.topcoder.com',
SPRIG_ENVIRONMENT_ID: 'a-IZBZ6-r7bU',

// Specifically for the terms ID that matches the NDA requirement.
TERM_NDA_ID: 'c41e90e5-4d0e-4811-bd09-38ff72674490',
ACCOUNT_SETTINGS_REDIRECT_URL: 'https://account-settings.topcoder.com',
};
2 changes: 0 additions & 2 deletions config/qa.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ module.exports = {
},
PLATFORM_SITE_URL: 'https://platform.topcoder-qa.com',
PLATFORMUI_SITE_URL: 'https://platform-ui.topcoder-qa.com',
// Specifically for the terms ID that matches the NDA requirement.
TERM_NDA_ID: 'c41e90e5-4d0e-4811-bd09-38ff72674490',
};
22 changes: 22 additions & 0 deletions src/shared/components/RedirectExternalUrlPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import PT from 'prop-types';
import { Helmet } from 'react-helmet';

export default function RedirectExternalUrlPage(props) {
const { externalRedirectUrl } = props;
if (typeof window !== 'undefined' && externalRedirectUrl) {
window.location.replace(externalRedirectUrl);
}
if (!externalRedirectUrl) {
return null;
}
return (
<Helmet>
<meta httpEquiv="Refresh" content={`0; url='${externalRedirectUrl}'`} />
</Helmet>
);
}

RedirectExternalUrlPage.propTypes = {
externalRedirectUrl: PT.string.isRequired,
};
11 changes: 2 additions & 9 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,23 +323,16 @@ class ChallengeDetailPageContainer extends React.Component {
registerForChallenge() {
const {
auth,
challengeId,
communityId,
registerForChallenge,
openTermsModal,
terms,
} = this.props;
if (!auth.tokenV3) {
const utmSource = communityId || 'community-app-main';
window.location.href = `${config.URL.AUTH}/member?retUrl=${encodeURIComponent(window.location.href)}&utm_source=${utmSource}&regSource=challenges`;
} else if (terms && !!_.find(terms, { id: config.TERM_NDA_ID })) {
} else {
// Show security reminder to all registrants
this.setState({
showSecurityReminder: true,
});
} else if (_.every(terms, 'agreed')) {
registerForChallenge(auth, challengeId);
} else {
openTermsModal();
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/shared/routes/ProfileRedirect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* The loader of Profile webpack chunks.
*/
import React from 'react';
import PT from 'prop-types';
import { config } from 'topcoder-react-utils';
import RedirectExternalUrlPage from '../components/RedirectExternalUrlPage';

export default function ProfileRedirect(props) {
const {
match: {
params: { handle },
},
} = props;
return (
<RedirectExternalUrlPage
externalRedirectUrl={handle ? `${config.MEMBER_PROFILE_REDIRECT_URL}/${handle}` : null}
/>
);
}

ProfileRedirect.propTypes = {
match: PT.shape({
params: PT.shape({
handle: PT.string,
}),
}).isRequired,
};
2 changes: 0 additions & 2 deletions src/shared/routes/Settings/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React from 'react';
import PT from 'prop-types';
import { Route, Switch } from 'react-router-dom';

import Settings from 'containers/Settings';
import Success from 'components/Settings/Account/MyAccount/EmailVerifiResult/Success';
import Failed from 'components/Settings/Account/MyAccount/EmailVerifiResult/Failed';
import AlmostDone from 'components/Settings/Account/MyAccount/EmailVerifiResult/AlmostDone';
Expand All @@ -16,7 +15,6 @@ import Error404 from 'components/Error404';
export default function Router({ base }) {
return (
<Switch>
<Route component={Settings} exact path={`${base}/:settingsTab(profile|skills|tracks|tools|account|preferences|payment)`} />
<Route component={EmailVerification} exact path={`${base}/account/changeEmail`} />
<Route component={Success} exact path={`${base}/account/email-verification/success`} />
<Route component={Failed} exact path={`${base}/account/email-verification/failure`} />
Expand Down
74 changes: 74 additions & 0 deletions src/shared/routes/Settings/SettingRedirect.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* The loader of Profile webpack chunks.
*/
import React from 'react';
import PT from 'prop-types';
import _ from 'lodash';
import { config } from 'topcoder-react-utils';
import { connect } from 'react-redux';
import { goToLogin } from 'utils/tc';
import { isTokenExpired } from '@topcoder-platform/tc-auth-lib';
import RedirectExternalUrlPage from '../../components/RedirectExternalUrlPage';

function SettingRedirect(props) {
const {
match: {
params: { settingsTab },
},
authenticating,
tokenV3,
handle,
} = props;
let externalUrl = '';
if (settingsTab === 'profile' && handle) {
externalUrl = `${config.MEMBER_PROFILE_REDIRECT_URL}/${handle}`;
} else if (settingsTab === 'skills' && handle) {
externalUrl = `${config.MEMBER_PROFILE_REDIRECT_URL}/${handle}/?edit-mode=skills`;
} else if (settingsTab === 'tracks') {
externalUrl = `${config.ACCOUNT_SETTINGS_REDIRECT_URL}/#tcandyou`;
} else if (settingsTab === 'tools') {
externalUrl = `${config.ACCOUNT_SETTINGS_REDIRECT_URL}/#tools`;
} else if (settingsTab === 'account') {
externalUrl = `${config.ACCOUNT_SETTINGS_REDIRECT_URL}/#account`;
} else if (settingsTab === 'preferences') {
externalUrl = `${config.ACCOUNT_SETTINGS_REDIRECT_URL}/#preferences`;
} else if (settingsTab === 'payment') {
externalUrl = `${config.ACCOUNT_SETTINGS_REDIRECT_URL}/#payment`;
}

if (!authenticating && !externalUrl) {
// Check auth token, go to login page if invalid
if (!tokenV3 || isTokenExpired(tokenV3)) {
goToLogin('community-app-main');
return null;
}
}

return <RedirectExternalUrlPage externalRedirectUrl={externalUrl} />;
}

SettingRedirect.defaultProps = {
handle: '',
tokenV3: '',
};

SettingRedirect.propTypes = {
match: PT.shape({
params: PT.shape({
settingsTab: PT.string,
}),
}).isRequired,
authenticating: PT.bool.isRequired,
handle: PT.string,
tokenV3: PT.string,
};

function mapStateToProps(state) {
return {
authenticating: state.auth.authenticating,
handle: _.get(state.auth, 'user.handle'),
tokenV3: state.auth.tokenV3,
};
}

export default connect(mapStateToProps)(SettingRedirect);
6 changes: 0 additions & 6 deletions src/shared/routes/Topcoder/Routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import Dashboard from './Dashboard';
import Notifications from './Notifications';
import Settings from '../Settings';
import HallOfFame from '../HallOfFame';
import Profile from '../Profile';
import ProfileBadges from '../ProfileBadges';
import Scoreboard from '../tco/scoreboard';
import MemberSearch from '../../containers/MemberSearch';
Expand Down Expand Up @@ -85,11 +84,6 @@ export default function Topcoder() {
exact
path="/challenges/:challengeId([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}|\d{5,8})/submit"
/>
<Route
component={Profile}
exact
path="/members/:handle([\w\-\[\].{} ]{2,15})"
/>
{
config.GAMIFICATION.ENABLE_BADGE_UI && (
<Route
Expand Down
12 changes: 12 additions & 0 deletions src/shared/routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import TrackHomePages from './TrackHomePages';
import TimelineWall from './TimelineWall';
import PolicyPages from './PolicyPages';
import GigsPages from './GigsPages';
import ProfileRedirect from './ProfileRedirect';
import SettingRedirect from './Settings/SettingRedirect';

import './Topcoder/styles.scss';

Expand Down Expand Up @@ -161,6 +163,16 @@ function Routes({ communityId }) {
exact
path={config.START_PAGE_PATH}
/>
<Route
component={SettingRedirect}
exact
path="/settings/:settingsTab(profile|skills|tracks|tools|account|preferences|payment)"
/>
<Route
component={ProfileRedirect}
exact
path="/members/:handle([\w\-\[\].{} ]{2,15})"
/>
<Topcoder />
</Switch>
</div>
Expand Down

0 comments on commit a1c2a53

Please sign in to comment.