mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
4147663cde
fixes https://github.com/TryGhost/Team/issues/2670 "Also cancel subscription in Stripe" checkbox was not showing up when deleting a member with active subscriptions.
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class DeleteMemberModal extends Component {
|
|
@service notifications;
|
|
|
|
@tracked shouldCancelSubscriptions = false;
|
|
|
|
get member() {
|
|
return this.args.data.member;
|
|
}
|
|
|
|
get hasActiveStripeSubscriptions() {
|
|
const subscriptions = this.member.get('subscriptions');
|
|
|
|
if (!subscriptions || subscriptions.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
const firstActiveStripeSubscription = subscriptions.find((subscription) => {
|
|
return ['active', 'trialing', 'unpaid', 'past_due'].includes(subscription.status);
|
|
});
|
|
|
|
return firstActiveStripeSubscription !== undefined;
|
|
}
|
|
|
|
@task({drop: true})
|
|
*deleteMemberTask() {
|
|
const options = {
|
|
adapterOptions: {
|
|
cancel: this.shouldCancelSubscriptions
|
|
}
|
|
};
|
|
|
|
try {
|
|
yield this.member.destroyRecord(options);
|
|
this.args.data.afterDelete?.();
|
|
this.args.close(true);
|
|
} catch (e) {
|
|
this.notifications.showAPIError(e, {key: 'member.delete'});
|
|
this.args.close(false);
|
|
throw e;
|
|
}
|
|
}
|
|
}
|