Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tc academy certifications #347

Merged
merged 4 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- attach_workspace:
at: .
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: npm publish
- run: npm publish --tag test-release
# dont change anything
workflows:
version: 2
Expand Down
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": "1.2.7",
"version": "1000.29.6",
"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;