diff --git a/src/server/index.js b/src/server/index.js index 062cb1449c..59fb521c59 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,7 +9,7 @@ import Application from 'shared'; import config from 'config'; import express from 'express'; import fetch from 'isomorphic-fetch'; -import { logger } from 'topcoder-react-lib'; +import { logger, services } from 'topcoder-react-lib'; import fs from 'fs'; import moment from 'moment'; import path from 'path'; @@ -160,11 +160,14 @@ async function onExpressJsSetup(server) { /* Proxy endpoint for GET requests (to fetch data from resources prohibiting * cross-origin requests). */ - /* server.use( + server.use( '/community-app-assets/api/proxy-get', checkAuthorizationHeader, async (req, res, next) => { + const tokenM2M = await services.api.getTcM2mToken(); try { - let data = await fetch(req.query.url); + let data = await fetch(req.query.url, { + headers: { Authorization: `Bearer ${tokenM2M}` }, + }); data = await data.text(); res.send(data); } catch (err) { @@ -172,7 +175,6 @@ async function onExpressJsSetup(server) { } }, ); - */ /* Proxy endpoint for POST requests (to fetch data from resources prohibiting * cross-origin requests). */ diff --git a/src/server/sw.js b/src/server/sw.js index b51f364bb6..b3cbdbc6cf 100644 --- a/src/server/sw.js +++ b/src/server/sw.js @@ -87,7 +87,7 @@ workbox.routing.registerRoute(/\/challenges(\/)?(\?.*)?$/, async ({ event, url } }, 'GET'); // Serve challenge details pages like: /challenges/12345678 -workbox.routing.registerRoute(/\/challenges\/\d+(\/)?(.*)/, async ({ event, url }) => { +workbox.routing.registerRoute(/\/challenges\/(([\w]{4,12}-?){5}|\d+)\/?(\?.*)?/, async ({ event, url }) => { if (url.pathname.endsWith('/')) { // Remove ending '/' char url.pathname = url.pathname.substring(0, url.pathname.length - 1); diff --git a/src/shared/components/challenge-detail/Header/TabSelector/index.jsx b/src/shared/components/challenge-detail/Header/TabSelector/index.jsx index 7049280fd2..1c7d20c74e 100644 --- a/src/shared/components/challenge-detail/Header/TabSelector/index.jsx +++ b/src/shared/components/challenge-detail/Header/TabSelector/index.jsx @@ -21,8 +21,8 @@ export default function ChallengeViewSelector(props) { const { challenge, checkpointCount, - numRegistrants, - numSubmissions, + numOfRegistrants, + numOfSubmissions, numWinners, onSelectorClicked, selectedView, @@ -86,7 +86,7 @@ export default function ChallengeViewSelector(props) { DETAILS { - numRegistrants ? ( + numOfRegistrants ? ( REGISTRANTS ( - {numRegistrants} + {numOfRegistrants} ) ) : null @@ -123,7 +123,7 @@ export default function ChallengeViewSelector(props) { ) } { - numSubmissions ? ( + numOfSubmissions ? ( SUBMISSIONS ( - {numSubmissions} + {numOfSubmissions} ) ) : null @@ -188,8 +188,8 @@ export default function ChallengeViewSelector(props) { ChallengeViewSelector.defaultProps = { challenge: {}, checkpointCount: 0, - numRegistrants: 0, - numSubmissions: 0, + numOfRegistrants: 0, + numOfSubmissions: 0, // hasRegistered: false, }; @@ -204,8 +204,8 @@ ChallengeViewSelector.propTypes = { }), }), checkpointCount: PT.number, - numRegistrants: PT.number, - numSubmissions: PT.number, + numOfRegistrants: PT.number, + numOfSubmissions: PT.number, numWinners: PT.number.isRequired, onSelectorClicked: PT.func.isRequired, selectedView: PT.string.isRequired, diff --git a/src/shared/components/challenge-detail/Header/index.jsx b/src/shared/components/challenge-detail/Header/index.jsx index b5dcf32b33..1646fe61ee 100644 --- a/src/shared/components/challenge-detail/Header/index.jsx +++ b/src/shared/components/challenge-detail/Header/index.jsx @@ -68,8 +68,8 @@ export default function ChallengeHeader(props) { prizeSets, reliabilityBonus, userDetails, - numRegistrants, - numSubmissions, + numOfRegistrants, + numOfSubmissions, appealsEndDate, } = challenge; @@ -451,10 +451,10 @@ export default function ChallengeHeader(props) { onSelectorClicked={onSelectorClicked} trackLower={trackLower} selectedView={selectedView} - numRegistrants={numRegistrants} + numOfRegistrants={numOfRegistrants} numWinners={numWinners} hasCheckpoints={checkpoints && checkpoints.length > 0} - numSubmissions={numSubmissions} + numOfSubmissions={numOfSubmissions} hasRegistered={hasRegistered} checkpointCount={checkpointCount} mySubmissions={mySubmissions} @@ -492,8 +492,8 @@ ChallengeHeader.propTypes = { reliabilityBonus: PT.any, userDetails: PT.any, currentPhases: PT.any, - numRegistrants: PT.any, - numSubmissions: PT.any, + numOfRegistrants: PT.any, + numOfSubmissions: PT.any, status: PT.any, appealsEndDate: PT.any, allPhases: PT.any, diff --git a/src/shared/components/challenge-detail/RecommendedActiveChallenges/ChallengesCard/index.jsx b/src/shared/components/challenge-detail/RecommendedActiveChallenges/ChallengesCard/index.jsx index 96053c9871..b543b5964d 100644 --- a/src/shared/components/challenge-detail/RecommendedActiveChallenges/ChallengesCard/index.jsx +++ b/src/shared/components/challenge-detail/RecommendedActiveChallenges/ChallengesCard/index.jsx @@ -65,7 +65,7 @@ export default function ChallengesCard({ 0 ? challenge.events[0].eventName : ''} + tcoEligible={!_.isEmpty(challenge.events) ? challenge.events[0].eventName : ''} isDataScience={challenge.isDataScience} challengesUrl={challengesUrl} /> diff --git a/src/shared/components/challenge-detail/Registrants/index.jsx b/src/shared/components/challenge-detail/Registrants/index.jsx index fb9b4132c2..061aab9319 100644 --- a/src/shared/components/challenge-detail/Registrants/index.jsx +++ b/src/shared/components/challenge-detail/Registrants/index.jsx @@ -20,7 +20,7 @@ function formatDate(date) { } function getDate(arr, handle) { - const results = arr.filter(a => _.toString(a.submitter || a.handle) === _.toString(handle)) + const results = arr.filter(a => _.toString(a.submitter || a.memberHandle) === _.toString(handle)) .sort((a, b) => new Date(b.submissionTime || b.submissionDate).getTime() - new Date(a.submissionTime || a.submissionDate).getTime()); return results[0] ? (results[0].submissionTime || results[0].submissionDate) : ''; @@ -32,7 +32,7 @@ function passedCheckpoint(checkpoints, handle, results) { } function getPlace(results, handle, places) { - const found = _.find(results, w => _.toString(w.handle) === _.toString(handle) + const found = _.find(results, w => _.toString(w.memberHandle) === _.toString(handle) && w.placement <= places && w.submissionStatus !== 'Failed Review'); if (found) { @@ -99,7 +99,7 @@ export default class Registrants extends React.Component { let checkpoint; if (twoRounds) { - checkpoint = getDate(checkpoints, registrant.handle); + checkpoint = getDate(checkpoints, registrant.memberHandle); if (!checkpoint && moment(registrant.submissionDate).isBefore(checkpointDate)) { checkpoint = registrant.submissionDate; @@ -188,8 +188,8 @@ export default class Registrants extends React.Component { break; } case 'Username': { - valueA = `${a.handle}`.toLowerCase(); - valueB = `${b.handle}`.toLowerCase(); + valueA = `${a.memberHandle}`.toLowerCase(); + valueB = `${b.memberHandle}`.toLowerCase(); valueIsString = true; break; } @@ -239,7 +239,7 @@ export default class Registrants extends React.Component { onSortChange, } = this.props; const { - prizes, + prizeSets, legacy, } = challenge; const { track } = legacy; @@ -247,14 +247,14 @@ export default class Registrants extends React.Component { const { field, sort } = this.getRegistrantsSortParam(); const revertSort = (sort === 'desc') ? 'asc' : 'desc'; const isDesign = track.toLowerCase() === 'design'; - const isF2F = challenge.subTrack.indexOf('FIRST_2_FINISH') > -1; - const isBugHunt = challenge.subTrack.indexOf('BUG_HUNT') > -1; + const isF2F = challenge.type.toLowerCase().indexOf('first2finish') > -1; + const isBugHunt = challenge.type.toLowerCase() === 'bug hunt'; const checkpoints = challenge.checkpoints || []; const twoRounds = challenge.round1Introduction && challenge.round2Introduction; - const places = prizes.length; + const places = prizeSets.find(ps => ps.type === 'placement').prizes.lenght; return (
@@ -379,8 +379,14 @@ export default class Registrants extends React.Component {
{ sortedRegistrants.map((r) => { - const placement = getPlace(results, r.handle, places); - const colorStyle = JSON.parse(r.colorStyle.replace(/(\w+):\s*([^;]*)/g, '{"$1": "$2"}')); + const placement = getPlace(results, r.memberHandle, places); + /* + * TODO: Need check as get this back, currenlty V5 API missing this data + * = JSON.parse(r.colorStyle.replace(/(\w+):\s*([^;]*)/g, '{"$1": "$2"}')); + */ + const colorStyle = { + color: '#000000', + }; let checkpoint = this.getCheckPoint(r); if (checkpoint) { checkpoint = formatDate(checkpoint); @@ -393,7 +399,7 @@ export default class Registrants extends React.Component { } return ( -
+
{ !isDesign && !isF2F && !isBugHunt && (
@@ -411,11 +417,11 @@ export default class Registrants extends React.Component { @@ -423,7 +429,7 @@ export default class Registrants extends React.Component {
Registration Date
- {formatDate(r.registrationDate)} + {formatDate(r.created)}
{ twoRounds @@ -437,7 +443,7 @@ export default class Registrants extends React.Component { {checkpoint} { - passedCheckpoint(checkpoints, r.handle, checkpointResults) + passedCheckpoint(checkpoints, r.memberHandle, checkpointResults) && }
@@ -482,16 +488,16 @@ Registrants.propTypes = { challenge: PT.shape({ phases: PT.arrayOf(PT.shape({ actualEndDate: PT.string, - phaseType: PT.string.isRequired, + name: PT.string.isRequired, scheduledEndDate: PT.string, })).isRequired, allPhases: PT.arrayOf(PT.shape()), checkpoints: PT.arrayOf(PT.shape()), legacy: PT.shape({ - track: PT.any, + track: PT.string, }), - subTrack: PT.any, - prizes: PT.arrayOf(PT.number).isRequired, + type: PT.string, + prizeSets: PT.arrayOf(PT.shape()).isRequired, registrants: PT.arrayOf(PT.shape()).isRequired, round1Introduction: PT.string, round2Introduction: PT.string, diff --git a/src/shared/components/challenge-detail/Specification/SideBar/index.jsx b/src/shared/components/challenge-detail/Specification/SideBar/index.jsx index 0ace088c75..4602d9602b 100644 --- a/src/shared/components/challenge-detail/Specification/SideBar/index.jsx +++ b/src/shared/components/challenge-detail/Specification/SideBar/index.jsx @@ -36,7 +36,7 @@ export default function SideBar({ const faqURL = config.URL.INFO.DESIGN_CHALLENGE_SUBMISSION; let submissionLimitDisplay = 'Unlimited'; const submissionLimit = _.find(metadata, { type: 'submissionLimit' }); - const fileTypes = _.find(metadata, { type: 'fileTypes' }); + const fileTypes = _.find(metadata, { name: 'fileTypes' }); if (submissionLimit) { if (submissionLimit.value === 1) { diff --git a/src/shared/components/challenge-detail/Submissions/index.jsx b/src/shared/components/challenge-detail/Submissions/index.jsx index a7936abc70..b975a8d387 100644 --- a/src/shared/components/challenge-detail/Submissions/index.jsx +++ b/src/shared/components/challenge-detail/Submissions/index.jsx @@ -327,8 +327,8 @@ class SubmissionsComponent extends React.Component {
); - const isF2F = challenge.subTrack.indexOf('FIRST_2_FINISH') > -1; - const isBugHunt = challenge.subTrack.indexOf('BUG_HUNT') > -1; + const isF2F = challenge.type.toLowerCase().indexOf('first2finish') > -1; + const isBugHunt = challenge.type.toLowerCase() === 'bug hunt'; // copy colorStyle from registrants to submissions _.forEach(sortedSubmissions, (s) => { @@ -785,7 +785,7 @@ SubmissionsComponent.propTypes = { registrants: PT.any, allPhases: PT.any, phases: PT.any, - subTrack: PT.any, + type: PT.any, }).isRequired, toggleSubmissionHistory: PT.func.isRequired, submissionHistoryOpen: PT.shape({}).isRequired, diff --git a/src/shared/components/challenge-listing/ChallengeCard/index.jsx b/src/shared/components/challenge-listing/ChallengeCard/index.jsx index 7e3da661a0..97cef46625 100644 --- a/src/shared/components/challenge-listing/ChallengeCard/index.jsx +++ b/src/shared/components/challenge-listing/ChallengeCard/index.jsx @@ -71,7 +71,7 @@ function ChallengeCard({ 0 ? challenge.events[0].eventName : ''} + tcoEligible={!_.isEmpty(challenge.events) ? challenge.events[0].eventName : ''} isDataScience={challenge.isDataScience} /> diff --git a/src/shared/containers/challenge-detail/index.jsx b/src/shared/containers/challenge-detail/index.jsx index 63013b6476..f4ce7ef42b 100644 --- a/src/shared/containers/challenge-detail/index.jsx +++ b/src/shared/containers/challenge-detail/index.jsx @@ -116,7 +116,7 @@ function isRegistered(details, registrants, handle) { if (details && details.roles && details.roles.includes('Submitter')) { return true; } - if (_.find(registrants, r => _.toString(r.handle) === _.toString(handle))) { + if (_.find(registrants, r => _.toString(r.memberHandle) === _.toString(handle))) { return true; } return false; @@ -231,6 +231,7 @@ class ChallengeDetailPageContainer extends React.Component { challenge && challenge.id === challengeId && !loadingRecommendedChallengesUUID + && recommendedTechnology && ( !recommendedChallenges[recommendedTechnology] || ( @@ -731,7 +732,7 @@ function mapStateToProps(state, props) { if (challenge.submissions) { challenge.submissions = challenge.submissions.map(submission => ({ ...submission, - registrant: _.find(challenge.registrants, { handle: submission.submitter }), + registrant: _.find(challenge.registrants, { memberHandle: submission.createdBy }), })); } @@ -739,7 +740,7 @@ function mapStateToProps(state, props) { mmSubmissions = mmSubmissions.map((submission) => { let registrant; let { member } = submission; - if (auth.user.handle === submission.member) { + if (auth.user.handle === submission.memberHandle) { mySubmissions = submission.submissions || []; mySubmissions = mySubmissions.map((mySubmission, index) => { // eslint-disable-next-line no-param-reassign diff --git a/src/shared/reducers/index.js b/src/shared/reducers/index.js index 6b759c0c7c..a84d236a80 100644 --- a/src/shared/reducers/index.js +++ b/src/shared/reducers/index.js @@ -45,12 +45,12 @@ function generateSsrOptions(req) { const res = { auth: getAuthTokens(req), }; - if (req.url.match(/^\/challenges\/\d+\/my-submissions/)) { - const challengeId = req.url.match(/\d+/)[0]; + if (req.url.match(/^\/challenges\/(([\w]{4,12}-?){5}|\d+)\/my-submissions/)) { + const challengeId = req.url.match(/(([\w]{4,12}-?){5}|\d+)/)[0]; _.set(res, 'challenge.challengeDetails.id', challengeId); _.set(res, 'challenge.challengeDetails.mySubmission', true); - } else if (req.url.match(/\/challenges\/\d+([?/].*)?$/)) { - const challengeId = req.url.match(/\d+/)[0]; + } else if (req.url.match(/\/challenges\/(([\w]{4,12}-?){5}|\d+)\/?(\?.*)?$/)) { + const challengeId = req.url.match(/(([\w]{4,12}-?){5}|\d+)/)[0]; _.set(res, 'challenge.challengeDetails.id', challengeId); } @@ -62,8 +62,8 @@ function generateSsrOptions(req) { let entity; // if it's challenge details page - if (req.url.match(/^\/challenges\/\d+/)) { - const challengeId = req.url.match(/\d+/)[0]; + if (req.url.match(/^\/challenges\/(([\w]{4,12}-?){5}|\d+)/)) { + const challengeId = req.url.match(/(([\w]{4,12}-?){5}|\d+)/)[0]; entity = { type: 'challenge', id: challengeId }; } diff --git a/src/shared/reducers/reviewOpportunity.js b/src/shared/reducers/reviewOpportunity.js index 080b6614d4..2bdd61235a 100644 --- a/src/shared/reducers/reviewOpportunity.js +++ b/src/shared/reducers/reviewOpportunity.js @@ -15,9 +15,9 @@ import { reducers } from 'topcoder-react-lib'; */ export function factory(req) { const options = {}; - if (req && req.url.match(/^\/challenges\/\d{8}\/review-opportunities/)) { + if (req && req.url.match(/^\/challenges\/(([\w]{4,12}-?){5}|\d+)\/review-opportunities/)) { options.auth = getAuthTokens(req); - const challengeId = req.url.match(/\d+/)[0]; + const challengeId = req.url.match(/(([\w]{4,12}-?){5}|\d+)/)[0]; _.set(options, 'reviewOpportunity.challenge.id', challengeId); } diff --git a/src/shared/reducers/terms.js b/src/shared/reducers/terms.js index 13c1f54a61..463610a28e 100644 --- a/src/shared/reducers/terms.js +++ b/src/shared/reducers/terms.js @@ -322,8 +322,8 @@ export function factory(req) { let entity; // if it's challenge details page - if (req.url.match(/^\/challenges\/\d+/)) { - const challengeId = req.url.match(/\d+/)[0]; + if (req.url.match(/^\/challenges\/(([\w]{4,12}-?){5}|\d+)/)) { + const challengeId = req.url.match(/(([\w]{4,12}-?){5}|\d+)/)[0]; entity = { type: 'challenge', id: challengeId }; } diff --git a/src/shared/routes/Communities/Comcast/Routes.jsx b/src/shared/routes/Communities/Comcast/Routes.jsx index 63684d1ec6..0ff445ff3a 100644 --- a/src/shared/routes/Communities/Comcast/Routes.jsx +++ b/src/shared/routes/Communities/Comcast/Routes.jsx @@ -48,7 +48,7 @@ export default function CS({ base, meta }) { communityId: meta.communityId, })} exact - path={`${base}/work/:challengeId(\\d{8}|\\d{5})`} + path={`${base}/work/:challengeId(((([\\w]{4,12}-?){5}|\\d+)))`} /> Submission({ @@ -56,7 +56,7 @@ export default function CS({ base, meta }) { challengesUrl: `${base}/work`, })} exact - path={`${base}/work/:challengeId(\\d{8}|\\d{5})/submit`} + path={`${base}/work/:challengeId(((([\\w]{4,12}-?){5}|\\d+)))/submit`} /> SubmissionManagement({ @@ -64,7 +64,7 @@ export default function CS({ base, meta }) { challengesUrl: `${base}/work`, })} exact - path={`${base}/work/:challengeId(\\d{8}|\\d{5})/my-submissions`} + path={`${base}/work/:challengeId(((([\\w]{4,12}-?){5}|\\d+))/my-submissions`} /> - +