mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 16:14:25 +03:00
57b1ab4800
no issue - part of ember upgrades - removed all unnecessary usage of `.get` - cleaned up imports where we had imports from the same module across multiple lines - standardized on importing specific computed helpers rather than using `computed.foo` - switched tests from using `wait()` to `settled()`
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {alias, reads} from '@ember/object/computed';
|
|
import {computed} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default ModalComponent.extend({
|
|
membersStats: service(),
|
|
|
|
shouldCancelSubscriptions: false,
|
|
|
|
// Allowed actions
|
|
confirm: () => {},
|
|
|
|
member: alias('model'),
|
|
|
|
cancelSubscriptions: reads('shouldCancelSubscriptions'),
|
|
|
|
hasActiveStripeSubscriptions: computed('member', function () {
|
|
let subscriptions = this.member.get('subscriptions');
|
|
|
|
if (!subscriptions || subscriptions.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
let firstActiveStripeSubscription = subscriptions.find((subscription) => {
|
|
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
|
});
|
|
|
|
return firstActiveStripeSubscription !== undefined;
|
|
}),
|
|
|
|
actions: {
|
|
confirm() {
|
|
this.deleteMember.perform();
|
|
},
|
|
|
|
toggleShouldCancelSubscriptions() {
|
|
this.set('shouldCancelSubscriptions', !this.shouldCancelSubscriptions);
|
|
}
|
|
},
|
|
|
|
deleteMember: task(function* () {
|
|
try {
|
|
yield this.confirm(this.shouldCancelSubscriptions);
|
|
this.membersStats.invalidate();
|
|
} finally {
|
|
this.send('closeModal');
|
|
}
|
|
}).drop()
|
|
});
|