diff --git a/src/common/array-store.js b/src/common/array-store.js index 2789dcd..dbff5c3 100644 --- a/src/common/array-store.js +++ b/src/common/array-store.js @@ -22,6 +22,7 @@ import { ReduceStore } from 'flux/utils'; import AppDispatcher from './app-dispatcher'; +import NotificationsDataManager from '../common/data-managers/notifications-data-manager'; class ArrayStore extends ReduceStore { constructor(type, dataManager) { @@ -84,9 +85,18 @@ class ArrayStore extends ReduceStore { } case this.type + '/load-error': - // TODO: Add error message - return state; - + if (action.error && !action.error.handled && action.error.response) { + + const USER_LOAD_ERROR_NOTIFICATION = { + title: 'Failed to load', + message: action.error.response.body.message, + level: 'error' + }; + NotificationsDataManager.addNotification(USER_LOAD_ERROR_NOTIFICATION); + + } + return super.reduce(state, action); + case this.type + '/start-add': this.dataManager.add(action.data, action.token); return state; @@ -95,8 +105,9 @@ class ArrayStore extends ReduceStore { return this.updateElements(state, [action.data]); case this.type + '/add-error': - // TODO: Add error message - return state; + + return state; + case this.type + '/start-remove': this.dataManager.remove(action.data, action.token); @@ -108,9 +119,18 @@ class ArrayStore extends ReduceStore { }); case this.type + '/remove-error': - // TODO: Add error message - return state; + if (action.error && !action.error.handled && action.error.response) { + const USER_REMOVE_ERROR_NOTIFICATION = { + title: 'Failed to add remove ', + message: action.error.response.body.message, + level: 'error' + }; + NotificationsDataManager.addNotification(USER_REMOVE_ERROR_NOTIFICATION); + + } + return super.reduce(state, action); + case this.type + '/start-edit': this.dataManager.update(action.data, action.token); return state; @@ -122,10 +142,18 @@ class ArrayStore extends ReduceStore { case this.type + '/edited': return this.updateElements(state, [action.data]); - case this.type + '/edit-error': - // TODO: Add error message + case this.type + '/confirm-pw-doesnt-match': + const USER_PW_ERROR_NOTIFICATION = { + title: 'The new password does not match', + message: 'Try again', + level: 'error' + }; + NotificationsDataManager.addNotification(USER_PW_ERROR_NOTIFICATION); return state; + case this.type + '/edit-error': + return state; + default: return state; } diff --git a/src/user/edit-user.js b/src/user/edit-user.js index a30019a..3427452 100644 --- a/src/user/edit-user.js +++ b/src/user/edit-user.js @@ -37,7 +37,8 @@ class EditUserDialog extends React.Component { id: '', password: '', active: '', - confirmpassword: '' + confirmpassword: '', + oldPassword: '' } } @@ -61,6 +62,7 @@ class EditUserDialog extends React.Component { var pw = true; var active = true; var confirmpassword = true; + var oldPW = true; if (this.state.username === '') { @@ -87,9 +89,12 @@ class EditUserDialog extends React.Component { confirmpassword = false; } + if(this.state.oldPassword === ''){ + oldPW = false; + } // form is valid if any of the fields contain somethig - this.valid = username || role || mail || pw || active || confirmpassword; + this.valid = username || role || mail || pw || active || confirmpassword || oldPW; } @@ -115,6 +120,10 @@ class EditUserDialog extends React.Component { E-mail this.handleChange(e)} /> + + Old Password + this.handleChange(e)} /> + Password this.handleChange(e)} /> diff --git a/src/user/user.js b/src/user/user.js index 69e6b1e..74ac1a8 100644 --- a/src/user/user.js +++ b/src/user/user.js @@ -84,7 +84,11 @@ class User extends Component { } else{ - console.log("error: not the same password"); + AppDispatcher.dispatch({ + type: 'users/confirm-pw-doesnt-match', + data: data, + token: this.state.token + }); } } @@ -120,6 +124,8 @@ class User extends Component { Role: {this.state.user.role} + + this.closeEditModal(data)} user={this.state.modalData} /> diff --git a/src/user/users-store.js b/src/user/users-store.js index 5d88f7a..b2ddfe9 100644 --- a/src/user/users-store.js +++ b/src/user/users-store.js @@ -55,7 +55,7 @@ class UsersStore extends ArrayStore { NotificationsDataManager.addNotification(USER_EDIT_ERROR_NOTIFICATION); } - return super.reduce(state, action); + return super.reduce(state, action); default: return super.reduce(state, action); diff --git a/src/user/users.js b/src/user/users.js index c22e81f..1b788a0 100644 --- a/src/user/users.js +++ b/src/user/users.js @@ -103,7 +103,11 @@ class Users extends Component { } else{ - console.log("error: not the same password"); + AppDispatcher.dispatch({ + type: 'users/confirm-pw-doesnt-match', + data: data, + token: this.state.token + }); } } }