-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/fetch-active-review-types-only
- Loading branch information
Showing
8 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |