diff --git a/core/client/app/controllers/modals/invite-new-user.js b/core/client/app/controllers/modals/invite-new-user.js index ba0870ca0d..9d0d48c350 100644 --- a/core/client/app/controllers/modals/invite-new-user.js +++ b/core/client/app/controllers/modals/invite-new-user.js @@ -1,8 +1,11 @@ import Ember from 'ember'; +import ValidationEngine from 'ghost/mixins/validation-engine'; -export default Ember.Controller.extend({ +export default Ember.Controller.extend(ValidationEngine, { notifications: Ember.inject.service(), + validationType: 'signup', + role: null, authorRole: null, @@ -42,13 +45,13 @@ export default Ember.Controller.extend({ confirmAccept: function () { var email = this.get('email'), role = this.get('role'), + validationErrors = this.get('errors.messages'), self = this, newUser; // reset the form and close the modal - self.set('email', ''); - self.set('role', self.get('authorRole')); - self.send('closeModal'); + this.set('email', ''); + this.set('role', self.get('authorRole')); this.store.find('user').then(function (result) { var invitedUser = result.findBy('email', email); @@ -82,7 +85,13 @@ export default Ember.Controller.extend({ // save is overridden in order to validate, we probably // want to use inline-validations here and only show an // alert if we have an actual error - self.get('notifications').showErrors(errors); + if (errors) { + self.get('notifications').showErrors(errors); + } else if (validationErrors) { + self.get('notifications').showAlert(validationErrors.toString(), {type: 'error'}); + } + }).finally(function () { + self.get('errors').clear(); }); } }); diff --git a/core/client/app/routes/team/user.js b/core/client/app/routes/team/user.js index 6ec6760814..55e7f802ec 100644 --- a/core/client/app/routes/team/user.js +++ b/core/client/app/routes/team/user.js @@ -46,10 +46,16 @@ var TeamUserRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, { model.rollback(); } + model.get('errors').clear(); + this._super(); }, actions: { + didTransition: function () { + this.modelFor('team.user').get('errors').clear(); + }, + save: function () { this.get('controller').send('save'); } diff --git a/core/client/app/templates/modals/invite-new-user.hbs b/core/client/app/templates/modals/invite-new-user.hbs index db59e84fd0..8c44403d07 100644 --- a/core/client/app/templates/modals/invite-new-user.hbs +++ b/core/client/app/templates/modals/invite-new-user.hbs @@ -2,11 +2,12 @@ title="Invite a New User" confirm=confirm class="invite-new-user"}}