mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
6d324e31f1
closes https://github.com/TryGhost/Team/issues/546 Since https://github.com/TryGhost/Ghost/commit/26ee6483 and https://github.com/TryGhost/Admin/commit/fbd42ef3 member subscriptions have not been on the `stripe` property. This meant that all members were considered to not have subscriptions, and so the modal would not display to option to cancel subscriptions.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {alias} from '@ember/object/computed';
|
|
import {computed} from '@ember/object';
|
|
import {reads} from '@ember/object/computed';
|
|
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()
|
|
});
|