discourse-subscriptions/assets/javascripts/discourse/routes/user-billing-subscriptions-...

41 lines
1.1 KiB
JavaScript
Raw Normal View History

import { action } from "@ember/object";
2024-01-16 11:51:44 -05:00
import Route from "@ember/routing/route";
2024-11-19 05:31:14 -05:00
import { service } from "@ember/service";
2024-01-16 11:51:44 -05:00
import I18n from "I18n";
import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription";
export default Route.extend({
2022-10-17 14:42:40 -04:00
dialog: service(),
router: service(),
model() {
return UserSubscription.findAll();
},
@action
updateCard(subscriptionId) {
this.router.transitionTo("user.billing.subscriptions.card", subscriptionId);
},
@action
cancelSubscription(subscription) {
2022-10-17 14:42:40 -04:00
this.dialog.yesNoConfirm({
message: I18n.t(
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
),
2022-10-17 14:42:40 -04:00
didConfirm: () => {
subscription.set("loading", true);
2022-10-17 14:42:40 -04:00
subscription
.destroy()
.then((result) => subscription.set("status", result.status))
.catch((data) =>
this.dialog.alert(data.jqXHR.responseJSON.errors.join("\n"))
)
.finally(() => {
subscription.set("loading", false);
this.refresh();
});
},
});
},
});