Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ function verifyMemberNewEmailDone(handle, tokenV3, emailVerifyToken) {
.then(res => ({ data: res }));
}

/**
* @static
* @desc Creates an action that toggles isEmailConflict state
* @param {boolean} state
* @return {Action}
*/
function updateEmailConflict(state = false) {
return state;
}

export default createActions({
PROFILE: {
LOAD_PROFILE: loadProfile,
Expand Down Expand Up @@ -480,5 +490,6 @@ export default createActions({
UPDATE_PASSWORD_DONE: updatePasswordDone,
VERIFY_MEMBER_NEW_EMAIL_INIT: verifyMemberNewEmailInit,
VERIFY_MEMBER_NEW_EMAIL_DONE: verifyMemberNewEmailDone,
UPDATE_EMAIL_CONFLICT: updateEmailConflict,
},
});
22 changes: 22 additions & 0 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ function onDeletePhotoDone(state, { payload, error }) {
function onUpdateProfileDone(state, { payload, error }) {
const newState = { ...state, updatingProfile: false };

if (payload.isEmailConflict) {
return {
...newState,
isEmailConflict: true,
updateProfileSuccess: false,
};
}

if (error) {
logger.error('Failed to update user profile', payload);
fireErrorMessage('ERROR: Failed to update user profile!');
Expand Down Expand Up @@ -455,6 +463,19 @@ function onVerifyMemberNewEmailDone(state, { payload, error }) {
};
}

/**
* Handles UPDATE_EMAIL_CONFLICT action
* @param {Object} state
* @param {Object} action Payload will be a boolean value
* @return {Object} New state
*/
function onUpdateEmailConflict(state, { payload }) {
return {
...state,
isEmailConflict: payload,
};
}

/**
* Creates a new Profile reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand Down Expand Up @@ -509,6 +530,7 @@ function create(initialState) {
[a.updatePasswordDone]: onUpdatePasswordDone,
[a.verifyMemberNewEmailInit]: state => ({ ...state, verifyingEmail: true }),
[a.verifyMemberNewEmailDone]: onVerifyMemberNewEmailDone,
[a.updateEmailConflict]: onUpdateEmailConflict,
}, _.defaults(initialState, {
achievements: null,
copilot: false,
Expand Down
3 changes: 3 additions & 0 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class MembersService {
async updateMemberProfile(profile) {
const url = profile.verifyUrl ? `/members/${profile.handle}?verifyUrl=${profile.verifyUrl}` : `/members/${profile.handle}`;
const res = await this.private.api.putJson(url, { param: profile.verifyUrl ? _.omit(profile, ['verifyUrl']) : profile });
if (profile.verifyUrl && res.status === 409) {
return Promise.resolve(Object.assign({}, profile, { isEmailConflict: true }));
}
return getApiResponsePayload(res);
}

Expand Down