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) ⇒ <code>Action</code> + * [.clearProfile()](#module_actions.profile.clearProfile) ⇒ <code>Action</code> * [.getAchievementsInit()](#module_actions.profile.getAchievementsInit) ⇒ <code>Action</code> * [.getAchievementsDone(handle)](#module_actions.profile.getAchievementsDone) ⇒ <code>Action</code> * [.getExternalAccountsInit()](#module_actions.profile.getExternalAccountsInit) ⇒ <code>Action</code> @@ -67,6 +68,17 @@ Creates and action that loads user profile. | --- | --- | --- | | handle | <code>String</code> | User handle. | +<a name="module_actions.profile.clearProfile"></a> + +### actions.profile.clearProfile() ⇒ <code>Action</code> +Creates and action that clear user profile. + +**Kind**: static method of [<code>actions.profile</code>](#module_actions.profile) +**Todo** + +- [ ] This action does not follow the pattern with init/done pairs of + actions. Should be improved. + <a name="module_actions.profile.getAchievementsInit"></a> ### actions.profile.getAchievementsInit() ⇒ <code>Action</code> diff --git a/src/actions/profile.js b/src/actions/profile.js index 69c4cb99..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'; @@ -415,6 +415,7 @@ function updatePasswordDone(profile, tokenV3, newPassword, oldPassword) { export default createActions({ PROFILE: { LOAD_PROFILE: loadProfile, + CLEAR_PROFILE: _.noop, 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,