0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/client/app/components/gh-user-invited.js
Kevin Ansfield 7ac6ebb920 Refactor notifications service & components
issue #5409

- change persistent/passive notification status to alert/notification
- replace showSuccess/Info/Warn/Error with showNotification/showAlert
- fix and clean up notification/alert components
2015-07-28 12:26:11 +01:00

61 lines
2.3 KiB
JavaScript

import Ember from 'ember';
export default Ember.Component.extend({
tagName: '',
user: null,
notifications: Ember.inject.service(),
createdAt: Ember.computed('user.created_at', function () {
var createdAt = this.get('user.created_at');
return createdAt ? createdAt.fromNow() : '';
}),
actions: {
resend: function () {
var user = this.get('user'),
notifications = this.get('notifications');
user.resendInvite().then(function (result) {
var notificationText = 'Invitation resent! (' + user.get('email') + ')';
// If sending the invitation email fails, the API will still return a status of 201
// but the user's status in the response object will be 'invited-pending'.
if (result.users[0].status === 'invited-pending') {
notifications.showAlert('Invitation email was not sent. Please try resending.', {type: 'error'});
} else {
user.set('status', result.users[0].status);
notifications.showNotification(notificationText);
}
}).catch(function (error) {
notifications.showAPIError(error);
});
},
revoke: function () {
var user = this.get('user'),
email = user.get('email'),
notifications = this.get('notifications'),
self = this;
// reload the user to get the most up-to-date information
user.reload().then(function () {
if (user.get('invited')) {
user.destroyRecord().then(function () {
var notificationText = 'Invitation revoked. (' + email + ')';
notifications.showNotification(notificationText);
}).catch(function (error) {
notifications.showAPIError(error);
});
} else {
// if the user is no longer marked as "invited", then show a warning and reload the route
self.sendAction('reload');
notifications.showAlert('This user has already accepted the invitation.', {type: 'error', delayed: true});
}
});
}
}
});