Skip to content

Commit 6231152

Browse files
authored
Merge pull request #99 from topcoder-platform/feature-sort-registrations
Feature sort registrations
2 parents e3b5d0c + 541327c commit 6231152

File tree

12 files changed

+165
-72
lines changed

12 files changed

+165
-72
lines changed

__tests__/__snapshots__/index.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Object {
5858
"getLookerDone": [Function],
5959
},
6060
"lookup": Object {
61+
"getAllCountriesDone": [Function],
62+
"getAllCountriesInit": [Function],
6163
"getCountriesDone": [Function],
6264
"getCountriesInit": [Function],
6365
"getSkillTagsDone": [Function],

__tests__/actions/__snapshots__/lookup.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
exports[`Module exports 1`] = `
44
Object {
55
"lookup": Object {
6+
"getAllCountriesDone": [Function],
7+
"getAllCountriesInit": [Function],
68
"getCountriesDone": [Function],
79
"getCountriesInit": [Function],
810
"getSkillTagsDone": [Function],

__tests__/reducers/__snapshots__/lookup.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Default reducer Get countries 1`] = `
44
Object {
5+
"allCountries": Array [],
56
"countries": Array [
67
Object {
78
"country": "Afghanistan",
@@ -23,6 +24,7 @@ Object {
2324

2425
exports[`Default reducer Get countries error 1`] = `
2526
Object {
27+
"allCountries": Array [],
2628
"countries": Array [
2729
Object {
2830
"country": "Afghanistan",
@@ -44,6 +46,7 @@ Object {
4446

4547
exports[`Default reducer Get skill tags 1`] = `
4648
Object {
49+
"allCountries": Array [],
4750
"countries": Array [],
4851
"loadingSkillTagsError": false,
4952
"skillTags": Array [
@@ -59,6 +62,7 @@ Object {
5962

6063
exports[`Default reducer Get skill tags error 1`] = `
6164
Object {
65+
"allCountries": Array [],
6266
"countries": Array [],
6367
"loadingSkillTagsError": true,
6468
"skillTags": Array [
@@ -74,13 +78,15 @@ Object {
7478

7579
exports[`Default reducer Initial state 1`] = `
7680
Object {
81+
"allCountries": Array [],
7782
"countries": Array [],
7883
"skillTags": Array [],
7984
}
8085
`;
8186

8287
exports[`Factory without server side rendering Get countries 1`] = `
8388
Object {
89+
"allCountries": Array [],
8490
"countries": Array [
8591
Object {
8692
"country": "Afghanistan",
@@ -102,6 +108,7 @@ Object {
102108

103109
exports[`Factory without server side rendering Get countries error 1`] = `
104110
Object {
111+
"allCountries": Array [],
105112
"countries": Array [
106113
Object {
107114
"country": "Afghanistan",
@@ -123,6 +130,7 @@ Object {
123130

124131
exports[`Factory without server side rendering Get skill tags 1`] = `
125132
Object {
133+
"allCountries": Array [],
126134
"countries": Array [],
127135
"loadingSkillTagsError": false,
128136
"skillTags": Array [
@@ -138,6 +146,7 @@ Object {
138146

139147
exports[`Factory without server side rendering Get skill tags error 1`] = `
140148
Object {
149+
"allCountries": Array [],
141150
"countries": Array [],
142151
"loadingSkillTagsError": true,
143152
"skillTags": Array [
@@ -153,6 +162,7 @@ Object {
153162

154163
exports[`Factory without server side rendering Initial state 1`] = `
155164
Object {
165+
"allCountries": Array [],
156166
"countries": Array [],
157167
"skillTags": Array [],
158168
}

dist/dev/index.js

+57-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/actions.lookup.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ Actions related to lookup data.
99
* [.getSkillTagsDone()](#module_actions.lookup.getSkillTagsDone) ⇒ <code>Action</code>
1010
* [.getCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
1111
* [.getCountriesDone()](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
12+
* [.getAllCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
13+
* [.getAllCountriesDone(tokenV3)](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
1214

1315
<a name="module_actions.lookup.getSkillTagsInit"></a>
1416

1517
### actions.lookup.getSkillTagsInit() ⇒ <code>Action</code>
1618
Creates an action that signals beginning of getting all skill tags.
1719

18-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
20+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
1921
<a name="module_actions.lookup.getSkillTagsDone"></a>
2022

2123
### actions.lookup.getSkillTagsDone() ⇒ <code>Action</code>
2224
Creates an action that gets all skill tags.
2325

24-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
26+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
2527
<a name="module_actions.lookup.getCountriesDone"></a>
2628

2729
### actions.lookup.getCountriesDone() ⇒ <code>Action</code>
2830
Creates an action that gets all countries.
2931

30-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
32+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
33+
<a name="module_actions.lookup.getCountriesDone"></a>
34+
35+
### actions.lookup.getAllCountriesDone(tokenV3) ⇒ <code>Action</code>
36+
Creates an action that gets all countries new version.
37+
38+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
39+
40+
| Param | Type | Description |
41+
| --- | --- | --- |
42+
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |

docs/services.members.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Gets member external account info.
114114

115115
| Param | Type |
116116
| --- | --- |
117-
| handle | <code>String</code> |
117+
| handle | <code>String</code> |
118118

119119
<a name="module_services.members..MembersService+getExternalLinks"></a>
120120

@@ -126,7 +126,7 @@ Gets member external links.
126126

127127
| Param | Type |
128128
| --- | --- |
129-
| handle | <code>String</code> |
129+
| handle | <code>String</code> |
130130

131131
<a name="module_services.members..MembersService+getSkills"></a>
132132

@@ -138,7 +138,7 @@ Gets member skills.
138138

139139
| Param | Type |
140140
| --- | --- |
141-
| handle | <code>String</code> |
141+
| handle | <code>String</code> |
142142

143143
<a name="module_services.members..MembersService+getStats"></a>
144144

@@ -150,7 +150,7 @@ Gets member statistics.
150150

151151
| Param | Type |
152152
| --- | --- |
153-
| handle | <code>String</code> |
153+
| handle | <code>String</code> |
154154

155155
<a name="module_services.members..MembersService+getStatsHistory"></a>
156156

@@ -162,7 +162,7 @@ Gets member statistics history
162162

163163
| Param | Type |
164164
| --- | --- |
165-
| handle | <code>String</code> |
165+
| handle | <code>String</code> |
166166

167167
<a name="module_services.members..MembersService+getStatsDistribution"></a>
168168

@@ -174,9 +174,9 @@ Gets member statistics distribution
174174

175175
| Param | Type |
176176
| --- | --- |
177-
| handle | <code>String</code> |
178-
| track | <code>String</code> |
179-
| subTrack | <code>String</code> |
177+
| handle | <code>String</code> |
178+
| track | <code>String</code> |
179+
| subTrack | <code>String</code> |
180180

181181
<a name="module_services.members..MembersService+getMemberSuggestions"></a>
182182

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/lookup.js

+19
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@ function getCountriesDone() {
4242
return getService().getCountries();
4343
}
4444

45+
/**
46+
* @static
47+
* @desc Creates an action that signals beginning of getting all countries api version 5.
48+
* @return {Action}
49+
*/
50+
function getAllCountriesInit() {}
51+
52+
/**
53+
* @static
54+
* @desc Creates an action that gets all countries api version 5.
55+
* @param {String} tokenV3 Optional. Auth token for Topcoder API v3.
56+
* @return {Action}
57+
*/
58+
function getAllCountriesDone(tokenV3) {
59+
return getService(tokenV3).getAllCountries();
60+
}
61+
4562
export default createActions({
4663
LOOKUP: {
4764
GET_SKILL_TAGS_INIT: getSkillTagsInit,
4865
GET_SKILL_TAGS_DONE: getSkillTagsDone,
4966
GET_COUNTRIES_INIT: getCountriesInit,
5067
GET_COUNTRIES_DONE: getCountriesDone,
68+
GET_ALL_COUNTRIES_INIT: getAllCountriesInit,
69+
GET_ALL_COUNTRIES_DONE: getAllCountriesDone,
5170
},
5271
});

src/reducers/lookup.js

+22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ function onGetCountriesDone(state, { payload, error }) {
4848
});
4949
}
5050

51+
/**
52+
* Handles LOOKUP/GET_ALL_COUNTRIES_DONE action.
53+
* @param {Object} state
54+
* @param {Object} action Payload will be JSON from api call
55+
* @return {Object} New state
56+
*/
57+
function onGetAllCountriesDone(state, { payload, error }) {
58+
if (error) {
59+
logger.error('Failed to get all countries', payload);
60+
return { ...state, loadingAllCountriesError: true };
61+
}
62+
63+
return ({
64+
...state,
65+
loadingAllCountriesError: false,
66+
allCountries: payload,
67+
});
68+
}
69+
5170
/**
5271
* Creates a new Lookup reducer with the specified initial state.
5372
* @param {Object} initialState Optional. Initial state.
@@ -60,9 +79,12 @@ function create(initialState = {}) {
6079
[a.getSkillTagsDone]: onGetSkillTagsDone,
6180
[a.getCountriesInit]: state => state,
6281
[a.getCountriesDone]: onGetCountriesDone,
82+
[a.getAllCountriesInit]: state => state,
83+
[a.getAllCountriesDone]: onGetAllCountriesDone,
6384
}, _.defaults(initialState, {
6485
skillTags: [],
6586
countries: [],
87+
allCountries: [],
6688
}));
6789
}
6890

src/services/challenges.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import logger from '../utils/logger';
1212
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1313
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
1414
import { getApi } from './api';
15+
import { getService as getMembersService } from './members';
1516

1617
export const ORDER_BY = {
1718
SUBMISSION_END_DATE: 'submissionEndDate',
@@ -262,6 +263,7 @@ class ChallengesService {
262263
getChallenges,
263264
tokenV2,
264265
tokenV3,
266+
memberService: getMembersService(),
265267
};
266268
}
267269

src/services/lookup.js

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class LookupService {
1414
constructor(tokenV3) {
1515
this.private = {
1616
api: getApi('V3', tokenV3),
17+
apiV5: getApi('V5', tokenV3),
1718
tokenV3,
1819
};
1920
}
@@ -37,6 +38,16 @@ class LookupService {
3738
const res = await this.private.api.get('/members/lookup/countries');
3839
return getApiResponsePayload(res);
3940
}
41+
42+
/**
43+
* Gets all countries.
44+
* @return {Promise} Resolves to the countries.
45+
*/
46+
async getAllCountries() {
47+
const res = await this.private.apiV5.get('/lookups/countries');
48+
const jsonResult = await res.json();
49+
return jsonResult;
50+
}
4051
}
4152

4253
let lastInstance = null;

src/utils/tc.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@ export const REVIEW_OPPORTUNITY_TYPES = {
2929
* Gets payload from a standard success response from TC API; or throws
3030
* an error in case of a failure response.
3131
* @param {Object} res
32+
* @param {Boolean} shouldThrowError should throw error if request fail
3233
* @return {Promise} Resolves to the payload.
3334
*/
34-
export async function getApiResponsePayload(res) {
35-
if (!res.ok) throw new Error(res.statusText);
35+
export async function getApiResponsePayload(res, shouldThrowError = true) {
36+
if (!res.ok) {
37+
if (shouldThrowError) {
38+
throw new Error(res.statusText);
39+
} else {
40+
return null;
41+
}
42+
}
3643
const x = (await res.json()).result;
37-
if (!x.success) throw new Error(x.content);
44+
if ((!x.success)) {
45+
if (shouldThrowError) {
46+
throw new Error(x.content);
47+
} else {
48+
return null;
49+
}
50+
}
3851
return x.content;
3952
}
4053

0 commit comments

Comments
 (0)