From 059512333fc4bb12a7930eb2184d23d0b3e17c4e Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Wed, 3 May 2017 17:30:40 +0200 Subject: [PATCH] handle taken usernames add/edit user --- src/stores/array-store.js | 1 - src/stores/users-store.js | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/stores/array-store.js b/src/stores/array-store.js index b7cfbee..ccd9689 100644 --- a/src/stores/array-store.js +++ b/src/stores/array-store.js @@ -95,7 +95,6 @@ class ArrayStore extends ReduceStore { return this.updateElements(state, [action.data]); case this.type + '/add-error': - console.log('something happened'); // TODO: Add error message return state; diff --git a/src/stores/users-store.js b/src/stores/users-store.js index 0b38e69..e42b1ed 100644 --- a/src/stores/users-store.js +++ b/src/stores/users-store.js @@ -21,6 +21,7 @@ import ArrayStore from './array-store'; import UsersDataManager from '../data-managers/users-data-manager'; +import NotificationsDataManager from '../data-managers/notifications-data-manager'; class UsersStore extends ArrayStore { constructor() { @@ -30,6 +31,32 @@ class UsersStore extends ArrayStore { reduce(state, action) { switch (action.type) { + case this.type + '/add-error': + if (action.error && !action.error.handled && action.error.response) { + // If it was an error and hasn't been handled, user could not be added + const USER_ADD_ERROR_NOTIFICATION = { + title: 'Failed to add new user', + message: action.error.response.body.message, + level: 'error' + } + NotificationsDataManager.addNotification(USER_ADD_ERROR_NOTIFICATION); + + } + return super.reduce(state, action); + + case this.type + '/edit-error': + if (action.error && !action.error.handled && action.error.response) { + // If it was an error and hasn't been handled, user couldn't not be updated + const USER_EDIT_ERROR_NOTIFICATION = { + title: 'Failed to edit user', + message: action.error.response.body.message, + level: 'error' + } + NotificationsDataManager.addNotification(USER_EDIT_ERROR_NOTIFICATION); + + } + return super.reduce(state, action); + default: return super.reduce(state, action); }