Skip to content

Commit

Permalink
Merge branch 'develop' into feat/fetch-active-review-types-only
Browse files Browse the repository at this point in the history
  • Loading branch information
luizrrodrigues authored Aug 16, 2022
2 parents 25faf30 + 1113bd0 commit bffe6eb
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ Object {
"getCommunityStatsDone": [Function],
"getCommunityStatsInit": [Function],
},
"tcAcademy": Object {
"getTcaCertificationsDone": [Function],
"getTcaCertificationsInit": [Function],
},
"terms": Object {
"agreeTermDone": [Function],
"agreeTermInit": [Function],
Expand Down Expand Up @@ -288,6 +292,7 @@ Object {
"reviewOpportunity": [Function],
"settings": [Function],
"stats": [Function],
"tcAcademy": [Function],
"terms": [Function],
},
"services": Object {
Expand Down Expand Up @@ -354,6 +359,10 @@ Object {
"default": undefined,
"getService": [Function],
},
"tcAcademy": Object {
"default": undefined,
"getService": [Function],
},
"terms": Object {
"default": undefined,
"getService": [Function],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1000.29.5",
"version": "1000.29.8",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import settingsActions from './settings';
import lookerActions from './looker';
import memberSearchActions from './member-search';
import notificationActions from './notifications';
import tcAcademyActions from './tc-academy';

export const actions = {
auth: authActions.auth,
Expand All @@ -34,6 +35,7 @@ export const actions = {
looker: lookerActions.looker,
memberSearch: memberSearchActions.memberSearch,
notifications: notificationActions.notifications,
tcAcademy: tcAcademyActions.tcAcademy,
};

export default undefined;
35 changes: 35 additions & 0 deletions src/actions/tc-academy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { redux } from 'topcoder-react-utils';
import { getService } from 'services/tc-academy';

const tcAcademyService = getService();

/**
* @static
* @desc Creates an action that signals beginning of user tc-academy certifications loading.
* @return {Action}
*/
function getTcaCertificationsInit(userId) {
return { userId };
}

/**
* @static
* @desc Creates an action that loads user tc-academy certifications from API v2.
* @param {String} userId User id.
* @return {Action}
*/
async function getTcaCertificationsDone(userId) {
const res = await tcAcademyService.getCertifications(userId);

return {
userId,
certifications: res,
};
}

export default redux.createActions({
TC_ACADEMY: {
GET_TCA_CERTIFICATIONS_INIT: getTcaCertificationsInit,
GET_TCA_CERTIFICATIONS_DONE: getTcaCertificationsDone,
},
});
3 changes: 3 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import challenge, { factory as challengeFactory } from './challenge';
import profile, { factory as profileFactory } from './profile';
import members, { factory as membersFactory } from './members';
import notifications, { factory as notificationsFactory } from './notifications';
import tcAcademy, { factory as tcAcademyFactory } from './tc-academy';
import lookup, { factory as lookupFactory } from './lookup';
import memberTasks, { factory as memberTasksFactory } from './member-tasks';
import reviewOpportunity, { factory as reviewOpportunityFactory }
Expand Down Expand Up @@ -44,6 +45,7 @@ export function factory(options) {
looker: lookerFactory(options),
memberSearch: memberSearchFactory(options),
notifications: notificationsFactory(options),
tcAcademy: tcAcademyFactory(options),
});
}

Expand All @@ -65,4 +67,5 @@ export default ({
looker,
memberSearch,
notifications,
tcAcademy,
});
63 changes: 63 additions & 0 deletions src/reducers/tc-academy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Reducer for TC Academy
*/

import { handleActions } from 'redux-actions';
import actions from 'actions/tc-academy';

/**
* Handles TCACADEMY/GET_TCA_CERTIFICATIONS_INIT action.
* @param {Object} state
* @return {Object} New state
*/
function onGetTcaCertificationsInit(state) {
return {
...state,
certifications: [],
failed: false,
loading: true,
};
}

/**
* Handles TCACADEMY/GET_TCA_CERTIFICATIONS_DONE actions.
* @param {Object} state Previous state.
* @param {Object} action Action.
*/
function onGetTcaCertificationsDone(state, action) {
return {
...state,
certifications: [],
...(action.error ? {} : action.payload),
failed: action.error,
loading: false,
};
}

/**
* Creates a new challenges reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
* @return challenges reducer.
*/
function create(initialState) {
const a = actions.tcAcademy;

return handleActions({
[a.getTcaCertificationsInit]: onGetTcaCertificationsInit,
[a.getTcaCertificationsDone]: onGetTcaCertificationsDone,
}, initialState || {});
}

/**
* Factory which creates a new reducer with its initial state tailored to the
* given options object, if specified (for server-side rendering). If options
* object is not specified, it creates just the default reducer. Accepted options are:
* @return {Promise}
* @resolves {Function(state, action): state} New reducer.
*/
export function factory() {
return Promise.resolve(create());
}

/* Default reducer with empty initial state. */
export default create();
2 changes: 2 additions & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as userTraits from './user-traits';
import * as submissions from './submissions';
import * as memberSearch from './member-search';
import * as notifications from './notifications';
import * as tcAcademy from './tc-academy';

export const services = {
api,
Expand All @@ -35,6 +36,7 @@ export const services = {
submissions,
memberSearch,
notifications,
tcAcademy,
};

export default undefined;
37 changes: 37 additions & 0 deletions src/services/tc-academy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { getApi } from './api';

/**
* Topcoder Academy service class
*/
class TcAcademyService {
constructor() {
this.private = {
api: getApi('V5'),
};
}

/**
*
* @param {string} userId Get all user's certifications (completed)
* @returns
*/
getCertifications(userId) {
return this.private.api.get(`/learning-paths/completed-certifications/${userId}`)
.then(res => (res.ok ? res.json() : new Error(res.statusText)));
}
}

/**
* Returns a new or existing service instance.
* @return {TcAcademyService} Topcoder Academy service instance
*/
let lastInstance = null;
export function getService() {
if (!lastInstance) {
lastInstance = new TcAcademyService();
}
return lastInstance;
}

/* Using default export would be confusing in this case. */
export default undefined;

0 comments on commit bffe6eb

Please sign in to comment.