Skip to content

Commit ed85b7d

Browse files
Merge branch 'develop' into support_for_job_description
2 parents e0ef678 + 8109cb2 commit ed85b7d

File tree

16 files changed

+178
-66
lines changed

16 files changed

+178
-66
lines changed

__tests__/__snapshots__/index.js.snap

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ Object {
305305
"SUBMISSION_END_DATE": "submissionEndDate",
306306
},
307307
"default": undefined,
308+
"getFilterUrl": [Function],
308309
"getService": [Function],
309310
"normalizeChallenge": [Function],
310311
},
@@ -373,10 +374,16 @@ Object {
373374
"processMMSubmissions": [Function],
374375
},
375376
"tc": Object {
377+
"CHALLENGE_STATUS": Object {
378+
"ACTIVE": "Active",
379+
"CANCELLED": "Cancelled",
380+
"COMPLETED": "Completed",
381+
"DRAFT": "Draft",
382+
},
376383
"COMPETITION_TRACKS": Object {
377-
"DATA_SCIENCE": "Data Science",
378-
"DESIGN": "Design",
379-
"DEVELOP": "Development",
384+
"DES": "Design",
385+
"DEV": "Development",
386+
"DS": "Data Science",
380387
"QA": "Quality Assurance",
381388
},
382389
"OLD_COMPETITION_TRACKS": Object {

__tests__/reducers/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const mockActions = {
2020
jest.setMock(require.resolve('actions/auth'), mockActions);
2121
jest.setMock(require.resolve('actions/profile'), mockActions);
2222

23-
jest.setMock('tc-accounts', {
23+
jest.setMock('@topcoder-platform/tc-auth-lib', {
2424
decodeToken: () => 'User object',
2525
isTokenExpired: () => false,
2626
});

__tests__/reducers/challenge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const mockSmpActions = {
4444
};
4545
_.merge(actions, mockSmpActions);
4646

47-
jest.setMock('tc-accounts', {
47+
jest.setMock('@topcoder-platform/tc-auth-lib', {
4848
decodeToken: () => 'User object',
4949
isTokenExpired: () => false,
5050
});

config/jest/setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global jest */
22
require('topcoder-react-utils/config/jest/setup');
33

4-
jest.setMock('tc-accounts', {
4+
jest.setMock('@topcoder-platform/tc-auth-lib', {
55
decodeToken: token => (token ? {
66
handle: 'username12345',
77
userId: '12345',

config/webpack/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
'redux',
2323
'redux-actions',
2424
'isomorphic-fetch',
25-
'tc-accounts',
25+
'@topcoder-platform/tc-auth-lib',
2626
'to-capital-case',
2727
'topcoder-react-utils',
2828
'tc-core-library-js',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
"react-redux": "^6.0.1",
4848
"redux": "^3.7.2",
4949
"redux-actions": "^2.4.0",
50-
"tc-accounts": "https://github.com/appirio-tech/accounts-app.git#dev",
5150
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6",
5251
"to-capital-case": "^1.0.0",
53-
"topcoder-react-utils": "0.7.5"
52+
"topcoder-react-utils": "0.7.5",
53+
"@topcoder-platform/tc-auth-lib": "git+https://github.com/topcoder-platform/tc-auth-lib.git#1.0.1"
5454
},
5555
"devDependencies": {
5656
"autoprefixer": "^8.6.4",

src/actions/auth.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,32 @@
44
*/
55

66
import { createActions } from 'redux-actions';
7-
import { decodeToken } from 'tc-accounts';
7+
import { decodeToken } from '@topcoder-platform/tc-auth-lib';
88
import { getApiV3, getApiV5 } from '../services/api';
9+
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
10+
11+
/**
12+
* Helper method that checks for HTTP error response v5 and throws Error in this case.
13+
* @param {Object} res HTTP response object
14+
* @return {Object} API JSON response object
15+
* @private
16+
*/
17+
async function checkErrorV5(res) {
18+
if (!res.ok) {
19+
if (res.status === 403) {
20+
setErrorIcon(ERROR_ICON_TYPES.API, 'Auth0', res.statusText);
21+
}
22+
throw new Error(res.statusText);
23+
}
24+
const jsonRes = (await res.json());
25+
if (jsonRes.message) {
26+
throw new Error(res.message);
27+
}
28+
return {
29+
result: jsonRes,
30+
headers: res.headers,
31+
};
32+
}
933

1034
/**
1135
* @static
@@ -22,8 +46,7 @@ function loadProfileDone(userTokenV3) {
2246
apiV3.get(`/members/${user.handle}`)
2347
.then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})),
2448
apiV5.get(`/groups?memberId=${user.userId}&membershipType=user`)
25-
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
26-
.then(res => (res.message ? new Error(res.message) : res)),
49+
.then(checkErrorV5).then(res => res.result || []),
2750
]).then(([profile, groups]) => ({ ...profile, groups }));
2851
}
2952

src/actions/challenge.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import _ from 'lodash';
88
import { config } from 'topcoder-react-utils';
99
import { createActions } from 'redux-actions';
10-
import { decodeToken } from 'tc-accounts';
10+
import { decodeToken } from '@topcoder-platform/tc-auth-lib';
1111
import { getService as getChallengesService } from '../services/challenges';
1212
import { getService as getSubmissionService } from '../services/submissions';
1313
import { getApi } from '../services/api';
@@ -248,7 +248,7 @@ function loadResultsInit(challengeId) {
248248
* @return {Action}
249249
*/
250250
function loadResultsDone(auth, challengeId, type) {
251-
return getApi('V2', auth.tokenV2)
251+
return getApi('V2')
252252
.fetch(`/${type}/challenges/result/${challengeId}`)
253253
.then(response => response.json())
254254
.then(response => ({
@@ -273,7 +273,7 @@ function fetchCheckpointsInit() {}
273273
*/
274274
function fetchCheckpointsDone(tokenV2, challengeId) {
275275
const endpoint = `/design/challenges/checkpoint/${challengeId}`;
276-
return getApi('V2', tokenV2).fetch(endpoint)
276+
return getApi('V2').fetch(endpoint)
277277
.then((response) => {
278278
if (response.status !== 200) {
279279
throw response.status;

src/reducers/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
import _ from 'lodash';
16-
import { decodeToken } from 'tc-accounts';
16+
import { decodeToken } from '@topcoder-platform/tc-auth-lib';
1717
import { redux } from 'topcoder-react-utils';
1818
import actions from '../actions/auth';
1919
import profileActions from '../actions/profile';

src/reducers/challenge.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function onFetchCheckpointsDone(state, action) {
173173
loadingCheckpoints: false,
174174
};
175175
}
176-
if (state.details && state.details.legacyId === action.payload.challengeId) {
176+
if (state.details && `${state.details.legacyId}` === `${action.payload.challengeId}`) {
177177
return {
178178
...state,
179179
checkpoints: action.payload.checkpoints,
@@ -471,7 +471,7 @@ export function factory(options = {}) {
471471
const challengeDetails = _.get(res, 'payload', {});
472472
const track = _.get(challengeDetails, 'track', '');
473473
let checkpointsPromise = null;
474-
if (track === COMPETITION_TRACKS.DESIGN) {
474+
if (track === COMPETITION_TRACKS.DES) {
475475
const p = _.get(challengeDetails, 'phases', [])
476476
.filter(x => x.name === 'Checkpoint Review');
477477
if (p.length && !p[0].isOpen) {

0 commit comments

Comments
 (0)