From b3f2b28383db8fa12e6bb305e4530bf40e9181ed Mon Sep 17 00:00:00 2001 From: dat Date: Thu, 16 Aug 2018 01:00:49 +0700 Subject: [PATCH 1/3] add clearProfile action annd reducer for clear all profile info add clearProfile action annd reducer for clear all profile info for fix https://github.com/topcoder-platform/community-app/issues/1192 --- __tests__/__snapshots__/index.js.snap | 1 + __tests__/actions/__snapshots__/profile.js.snap | 1 + docs/actions.profile.md | 12 ++++++++++++ src/actions/profile.js | 9 +++++++++ src/reducers/profile.js | 3 +++ 5 files changed, 26 insertions(+) diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index fb0ba447..19789173 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -86,6 +86,7 @@ Object { "addSkillInit": [Function], "addWebLinkDone": [Function], "addWebLinkInit": [Function], + "clearProfile": [Function], "deletePhotoDone": [Function], "deletePhotoInit": [Function], "deleteWebLinkDone": [Function], diff --git a/__tests__/actions/__snapshots__/profile.js.snap b/__tests__/actions/__snapshots__/profile.js.snap index 17e184aa..47b779ea 100644 --- a/__tests__/actions/__snapshots__/profile.js.snap +++ b/__tests__/actions/__snapshots__/profile.js.snap @@ -7,6 +7,7 @@ Object { "addSkillInit": [Function], "addWebLinkDone": [Function], "addWebLinkInit": [Function], + "clearProfile": [Function], "deletePhotoDone": [Function], "deletePhotoInit": [Function], "deleteWebLinkDone": [Function], diff --git a/docs/actions.profile.md b/docs/actions.profile.md index e84440c2..3b2bb991 100644 --- a/docs/actions.profile.md +++ b/docs/actions.profile.md @@ -11,6 +11,7 @@ Actions for interactions with profile details API. * [actions.profile](#module_actions.profile) * [.loadProfile(handle)](#module_actions.profile.loadProfile) ⇒ Action + * [.clearProfile()](#module_actions.profile.clearProfile) ⇒ Action * [.getAchievementsInit()](#module_actions.profile.getAchievementsInit) ⇒ Action * [.getAchievementsDone(handle)](#module_actions.profile.getAchievementsDone) ⇒ Action * [.getExternalAccountsInit()](#module_actions.profile.getExternalAccountsInit) ⇒ Action @@ -67,6 +68,17 @@ Creates and action that loads user profile. | --- | --- | --- | | handle | String | User handle. | + + +### actions.profile.clearProfile() ⇒ Action +Creates and action that clear user profile. + +**Kind**: static method of [actions.profile](#module_actions.profile) +**Todo** + +- [ ] This action does not follow the pattern with init/done pairs of + actions. Should be improved. + ### actions.profile.getAchievementsInit() ⇒ Action diff --git a/src/actions/profile.js b/src/actions/profile.js index 69c4cb99..0dcda1f7 100644 --- a/src/actions/profile.js +++ b/src/actions/profile.js @@ -21,6 +21,14 @@ function loadProfile(handle) { return handle; } +/** + * @static + * @desc Creates and action that clear user profile. + * @todo This action does not follow the pattern with init/done pairs of + * actions. Should be improved. + */ +function clearProfile() {} + /** * @static * @desc Creates an action that signals beginning of user achievements loading. @@ -415,6 +423,7 @@ function updatePasswordDone(profile, tokenV3, newPassword, oldPassword) { export default createActions({ PROFILE: { LOAD_PROFILE: loadProfile, + CLEAR_PROFILE: clearProfile, GET_ACHIEVEMENTS_INIT: getAchievementsInit, GET_ACHIEVEMENTS_DONE: getAchievementsDone, GET_EXTERNAL_ACCOUNTS_INIT: getExternalAccountsInit, diff --git a/src/reducers/profile.js b/src/reducers/profile.js index 1fb3bddc..12c734c5 100644 --- a/src/reducers/profile.js +++ b/src/reducers/profile.js @@ -432,6 +432,9 @@ function onUpdatePasswordDone(state, { payload, error }) { function create(initialState) { const a = actions.profile; return handleActions({ + [a.clearProfile]: state => ({ + ...state, achievements: null, country: '', info: null, skills: null, stats: null, + }), [a.loadProfile]: (state, action) => ({ ...state, profileForHandle: action.payload }), [a.getAchievementsInit]: state => state, [a.getAchievementsDone]: onGetAchievementsDone, From bd9ea7c175dc37b28c55f509352d28cf0834539a Mon Sep 17 00:00:00 2001 From: dat Date: Thu, 16 Aug 2018 01:17:02 +0700 Subject: [PATCH 2/3] clearProfile -> _.noop clearProfile -> _.noop --- src/actions/profile.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/actions/profile.js b/src/actions/profile.js index 0dcda1f7..58dc2cbf 100644 --- a/src/actions/profile.js +++ b/src/actions/profile.js @@ -5,7 +5,7 @@ * should be refactored to avoid redundancy. */ import { createActions } from 'redux-actions'; - +import _ from 'lodash'; import { getService as getUserService } from '../services/user'; import { getService as getMembersService } from '../services/members'; @@ -21,14 +21,6 @@ function loadProfile(handle) { return handle; } -/** - * @static - * @desc Creates and action that clear user profile. - * @todo This action does not follow the pattern with init/done pairs of - * actions. Should be improved. - */ -function clearProfile() {} - /** * @static * @desc Creates an action that signals beginning of user achievements loading. @@ -423,7 +415,7 @@ function updatePasswordDone(profile, tokenV3, newPassword, oldPassword) { export default createActions({ PROFILE: { LOAD_PROFILE: loadProfile, - CLEAR_PROFILE: clearProfile, + CLEAR_PROFILE: _.noop, GET_ACHIEVEMENTS_INIT: getAchievementsInit, GET_ACHIEVEMENTS_DONE: getAchievementsDone, GET_EXTERNAL_ACCOUNTS_INIT: getExternalAccountsInit, From daf98223cdb0d739ca44f523f4c3d523b2b886a8 Mon Sep 17 00:00:00 2001 From: Thomas Kranitsas Date: Wed, 15 Aug 2018 21:28:51 +0300 Subject: [PATCH 3/3] Bump npm version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 09570569..26c39869 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "topcoder-react-lib", - "version": "0.4.8", + "version": "0.4.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 05dfd084..88903a7f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "0.4.8", + "version": "0.4.9", "dependencies": { "auth0-js": "^6.8.4", "isomorphic-fetch": "^2.2.1",