2022-07-05 21:53:27 -04:00
|
|
|
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";
|
2022-07-05 21:53:27 -04:00
|
|
|
|
|
|
|
export default Route.extend({
|
2022-10-17 14:42:40 -04:00
|
|
|
dialog: service(),
|
2023-12-01 13:30:36 -05:00
|
|
|
router: service(),
|
2022-07-05 21:53:27 -04:00
|
|
|
model() {
|
|
|
|
return UserSubscription.findAll();
|
|
|
|
},
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateCard(subscriptionId) {
|
2023-12-01 13:30:36 -05:00
|
|
|
this.router.transitionTo("user.billing.subscriptions.card", subscriptionId);
|
2022-07-05 21:53:27 -04:00
|
|
|
},
|
|
|
|
@action
|
|
|
|
cancelSubscription(subscription) {
|
2022-10-17 14:42:40 -04:00
|
|
|
this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t(
|
2022-07-05 21:53:27 -04:00
|
|
|
"discourse_subscriptions.user.subscriptions.operations.destroy.confirm"
|
|
|
|
),
|
2022-10-17 14:42:40 -04:00
|
|
|
didConfirm: () => {
|
|
|
|
subscription.set("loading", true);
|
2022-07-05 21:53:27 -04:00
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2022-07-05 21:53:27 -04:00
|
|
|
},
|
|
|
|
});
|