diff --git a/client/coral-framework/actions/user.js b/client/coral-framework/actions/user.js index bf2a77402..3e80b718c 100644 --- a/client/coral-framework/actions/user.js +++ b/client/coral-framework/actions/user.js @@ -1,13 +1,21 @@ import {addNotification} from '../actions/notification'; import coralApi from '../helpers/response'; +import * as actions from '../constants/auth'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from './../translations'; const lang = new I18n(translations); +const editUsernameFailure = error => ({type: actions.EDIT_USERNAME_FAILURE, error}); +const editUsernameSuccess = () => ({type: actions.EDIT_USERNAME_SUCCESS}); + export const editName = (username) => (dispatch) => { return coralApi('/account/username', {method: 'PUT', body: {username}}) .then(() => { + dispatch(editUsernameSuccess()); dispatch(addNotification('success', lang.t('successNameUpdate'))); + }) + .catch(error => { + dispatch(editUsernameFailure(lang.t(`error.${error.translation_key}`))); }); }; diff --git a/client/coral-framework/constants/auth.js b/client/coral-framework/constants/auth.js index 9a217fb43..ce5d860b4 100644 --- a/client/coral-framework/constants/auth.js +++ b/client/coral-framework/constants/auth.js @@ -11,6 +11,11 @@ export const CREATE_USERNAME = 'CREATE_USERNAME'; export const SHOW_CREATEUSERNAME_DIALOG = 'SHOW_CREATEUSERNAME_DIALOG'; export const HIDE_CREATEUSERNAME_DIALOG = 'HIDE_CREATEUSERNAME_DIALOG'; +export const EDIT_USERNAME_REQUEST = 'CREATE_USERNAME_REQUEST'; +export const EDIT_USERNAME_SUCCESS = 'CREATE_USERNAME_SUCCESS'; +export const EDIT_USERNAME_FAILURE = 'CREATE_USERNAME_FAILURE'; +export const EDIT_USERNAME = 'CREATE_USERNAME'; + export const FETCH_SIGNUP_REQUEST = 'FETCH_SIGNUP_REQUEST'; export const FETCH_SIGNUP_FAILURE = 'FETCH_SIGNUP_FAILURE'; export const FETCH_SIGNUP_SUCCESS = 'FETCH_SIGNUP_SUCCESS';