2019-02-22 14:31:45 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
|
|
import {alias} from '@ember/object/computed';
|
2020-07-24 17:02:42 +03:00
|
|
|
import {computed} from '@ember/object';
|
2020-07-27 14:27:26 +03:00
|
|
|
import {reads} from '@ember/object/computed';
|
2020-05-26 19:17:35 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2019-02-22 14:31:45 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
|
|
|
export default ModalComponent.extend({
|
2020-05-26 19:17:35 +03:00
|
|
|
membersStats: service(),
|
|
|
|
|
2020-07-24 17:02:42 +03:00
|
|
|
shouldCancelSubscriptions: false,
|
|
|
|
|
2019-12-13 14:38:37 +03:00
|
|
|
// Allowed actions
|
|
|
|
confirm: () => {},
|
2019-02-22 14:31:45 +03:00
|
|
|
|
2019-12-13 14:38:37 +03:00
|
|
|
member: alias('model'),
|
2019-02-22 14:31:45 +03:00
|
|
|
|
2020-07-27 14:27:26 +03:00
|
|
|
cancelSubscriptions: reads('shouldCancelSubscriptions'),
|
|
|
|
|
2020-07-24 17:02:42 +03:00
|
|
|
hasActiveStripeSubscriptions: computed('member', function () {
|
|
|
|
let subscriptions = this.member.get('stripe');
|
|
|
|
|
|
|
|
if (!subscriptions || subscriptions.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let firstActiveStripeSubscription = subscriptions.find((subscription) => {
|
2020-10-27 12:57:31 +03:00
|
|
|
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
2020-07-24 17:02:42 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return firstActiveStripeSubscription !== undefined;
|
|
|
|
}),
|
|
|
|
|
2019-02-22 14:31:45 +03:00
|
|
|
actions: {
|
|
|
|
confirm() {
|
|
|
|
this.deleteMember.perform();
|
2020-07-24 17:02:42 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleShouldCancelSubscriptions() {
|
2020-07-27 14:27:26 +03:00
|
|
|
this.set('shouldCancelSubscriptions', !this.shouldCancelSubscriptions);
|
2019-02-22 14:31:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteMember: task(function* () {
|
|
|
|
try {
|
2020-07-24 17:02:42 +03:00
|
|
|
yield this.confirm(this.shouldCancelSubscriptions);
|
2020-05-26 19:17:35 +03:00
|
|
|
this.membersStats.invalidate();
|
2019-02-22 14:31:45 +03:00
|
|
|
} finally {
|
|
|
|
this.send('closeModal');
|
|
|
|
}
|
|
|
|
}).drop()
|
|
|
|
});
|