Skip to content

add clearProfile action and reducer for clear all profile info #21

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

Merged
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
1 change: 1 addition & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ Object {
"addSkillInit": [Function],
"addWebLinkDone": [Function],
"addWebLinkInit": [Function],
"clearProfile": [Function],
"deletePhotoDone": [Function],
"deletePhotoInit": [Function],
"deleteWebLinkDone": [Function],
1 change: 1 addition & 0 deletions __tests__/actions/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ Object {
"addSkillInit": [Function],
"addWebLinkDone": [Function],
"addWebLinkInit": [Function],
"clearProfile": [Function],
"deletePhotoDone": [Function],
"deletePhotoInit": [Function],
"deleteWebLinkDone": [Function],
12 changes: 12 additions & 0 deletions docs/actions.profile.md
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 2 additions & 1 deletion src/actions/profile.js
Original file line number Diff line number Diff line change
@@ -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,
3 changes: 3 additions & 0 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
@@ -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,