mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
fa84808048
no issue Since `ember-moment@10.0` it's not been necessary to use the `ember-cli-moment-shim` package, with `moment` instead being usable directly via `ember-auto-import`. Getting rid of the shim package is necessary for compatibility with `embroider`, Ember's new build tooling. - dropped `ember-cli-moment-shim` dependency - added `moment-timezone` dependency and updated all imports to reflect the different package - worked around `ember-power-calendar` having `ember-cli-moment-shim` as a sub-dependency - added empty in-repo-addon `ember-power-calendar-moment` to avoid `ember-power-calendar` complaining about a missing package - added `ember-power-calendar-utils` in-repo-addon that is a copy of `ember-power-calendar-moment` but without the build-time renaming of the tree for better compatibility with embroider
85 lines
3.0 KiB
JavaScript
85 lines
3.0 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import moment from 'moment-timezone';
|
|
import {action} from '@ember/object';
|
|
import {isNotFoundError} from 'ember-ajax/errors';
|
|
import {inject as service} from '@ember/service';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class GhUserInvited extends Component {
|
|
@service notifications;
|
|
@service store;
|
|
|
|
@tracked isSending = false;
|
|
|
|
get createdAt() {
|
|
const createdAtUTC = this.args.invite.createdAtUTC;
|
|
return createdAtUTC ? moment(createdAtUTC).fromNow() : '';
|
|
}
|
|
|
|
get expiresAt() {
|
|
const expires = this.args.invite.expires;
|
|
return expires ? moment(expires).fromNow() : '';
|
|
}
|
|
|
|
get isExpired() {
|
|
const expires = this.args.invite.expires;
|
|
const now = (new Date()).valueOf();
|
|
return expires < now;
|
|
}
|
|
|
|
@action
|
|
resend(event) {
|
|
event?.preventDefault();
|
|
|
|
const invite = this.args.invite;
|
|
const notifications = this.notifications;
|
|
|
|
this.isSending = true;
|
|
invite.resend().then((result) => {
|
|
const notificationText = `Invitation resent! (${invite.email})`;
|
|
|
|
// the server deletes the old record and creates a new one when
|
|
// resending so we need to update the store accordingly
|
|
invite.unloadRecord();
|
|
this.store.pushPayload('invite', result);
|
|
|
|
// If sending the invitation email fails, the API will still return a status of 201
|
|
// but the invite's status in the response object will be 'invited-pending'.
|
|
if (result.invites[0].status === 'invited-pending') {
|
|
notifications.showAlert('Invitation email was not sent. Please try resending.', {type: 'error', key: 'invite.resend.not-sent'});
|
|
} else {
|
|
notifications.showNotification(notificationText, {icon: 'send-email', key: 'invite.resend.success'});
|
|
}
|
|
}).catch((error) => {
|
|
notifications.showAPIError(error, {key: 'invite.resend'});
|
|
}).finally(() => {
|
|
this.isSending = false;
|
|
});
|
|
}
|
|
|
|
@action
|
|
revoke(event) {
|
|
event?.preventDefault();
|
|
|
|
const invite = this.args.invite;
|
|
const email = invite.email;
|
|
const notifications = this.notifications;
|
|
|
|
// reload the invite to get the most up-to-date information
|
|
invite.reload().then(() => {
|
|
invite.destroyRecord().then(() => {
|
|
notifications.showNotification('Invitation revoked', {key: 'invite.revoke.success', description: `${email}`});
|
|
}).catch((error) => {
|
|
notifications.showAPIError(error, {key: 'invite.revoke'});
|
|
});
|
|
}).catch((error) => {
|
|
if (isNotFoundError(error)) {
|
|
this.args.reload?.();
|
|
notifications.showAlert('This invite has been revoked or a user has already accepted the invitation.', {type: 'error', delayed: true, key: 'invite.revoke.already-accepted'});
|
|
} else {
|
|
throw error;
|
|
}
|
|
});
|
|
}
|
|
}
|