Skip to content

improvement(reskin-tco-badge): tco badge #339

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Changes from 4 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
@@ -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
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -105,6 +105,8 @@ Object {
"getActiveChallengesInit": [Function],
"getFinancesDone": [Function],
"getFinancesInit": [Function],
"getGamificationRewardsDone": [Function],
"getGamificationRewardsInit": [Function],
"getStatsDistributionDone": [Function],
"getStatsDistributionInit": [Function],
"getStatsDone": [Function],
7,859 changes: 3,920 additions & 3,939 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1.2.6",
"version": "1000.29.2",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
25 changes: 25 additions & 0 deletions src/actions/members.js
Original file line number Diff line number Diff line change
@@ -457,6 +457,29 @@ async function getUserResourcesDone(memberId, tokenV3, uuid) {
return { resources, uuid };
}

/**
* @static
* @desc Initiates an action that fetch member's awards
* @param {String} handle Member handle.
* @return {Action}
*/
async function getGamificationRewardsInit(handle) {
return { handle };
}

/**
* @static
* @desc Creates an action that gets member's awards
*
* @param {String} handle Topcoder member handle.
* @return {Action}
*/
async function getGamificationRewardsDone(handle, tokenV3) {
const rewards = await getService(tokenV3).getRewards(handle);
return rewards;
}


export default createActions({
MEMBERS: {
DROP: drop,
@@ -482,5 +505,7 @@ export default createActions({
GET_USER_MARATHON_DONE: getUserMarathonDone,
GET_USER_RESOURCES_INIT: getUserResourcesInit,
GET_USER_RESOURCES_DONE: getUserResourcesDone,
GET_GAMIFICATION_REWARDS_INIT: getGamificationRewardsInit,
GET_GAMIFICATION_REWARDS_DONE: getGamificationRewardsDone,
},
});
43 changes: 43 additions & 0 deletions src/reducers/members.js
Original file line number Diff line number Diff line change
@@ -463,6 +463,47 @@ function onGetUserResourcesDone(state, { error, payload }) {
};
}

/**
* Inits the loading of user's rewards.
* @param {Object} state
* @param {Object} action
* @return {Object} New state.
*/
function onGetGamificationRewardsInit(state, { payload }) {
const { handle } = payload;
return {
...state,
[handle]: {
...state[handle],
rewards: [],
},
};
}

/**
* Finalizes the loading of user's rewards.
* @param {Object} state
* @param {Object} action
* @return {Object} New state.
*/
function onGetGamificationRewardsDone(state, { error, payload }) {
if (error) {
logger.error('Failed to get user rewards', payload);
fireErrorMessage('Failed to get user rewards', '');
return state;
}

const { rewards, handle } = payload;

return {
...state,
[handle]: {
...state[handle],
rewards,
},
};
}

/**
* Creates a new Members reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
@@ -494,6 +535,8 @@ function create(initialState = {}) {
[a.getUserMarathonDone]: onGetUserMarathonDone,
[a.getUserResourcesInit]: onGetUserResourcesInit,
[a.getUserResourcesDone]: onGetUserResourcesDone,
[a.getGamificationRewardsInit]: onGetGamificationRewardsInit,
[a.getGamificationRewardsDone]: onGetGamificationRewardsDone,
}, initialState);
}

20 changes: 20 additions & 0 deletions src/services/members.js
Original file line number Diff line number Diff line change
@@ -353,6 +353,26 @@ class MembersService {
return results;
});
}

/**
* Fetch member's rewards
* @param {String} handle member handle
*/
async getRewards(handle) {
const url = `/members/${handle}/gamification/rewards`;
try {
const res = await this.private.apiV5.get(url);
const rewards = await res.json();

if (_.get(rewards, 'message') === 'Request failed with status code 404') {
return { rewards: [], handle };
}

return { rewards, handle };
} catch (error) {
return { rewards: [], handle };
}
}
}

let lastInstance = null;