2023-09-24 12:58:20 +02:00
|
|
|
import Service from "@ember/service";
|
2023-09-23 23:52:46 +02:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-09-23 19:30:11 +02:00
|
|
|
|
|
|
|
const PRODUCT_PAGE = "https://custom-wizard.pavilion.tech";
|
|
|
|
const SUPPORT_MESSAGE =
|
|
|
|
"https://coop.pavilion.tech/new-message?username=support&title=Custom%20Wizard%20Support";
|
|
|
|
const MANAGER_CATEGORY =
|
|
|
|
"https://discourse.pluginmanager.org/c/discourse-custom-wizard";
|
|
|
|
|
2023-09-23 19:33:18 +02:00
|
|
|
export default class SubscriptionService extends Service {
|
2023-09-24 12:58:20 +02:00
|
|
|
@tracked subscribed = false;
|
|
|
|
@tracked subscriptionType = "";
|
|
|
|
@tracked businessSubscription = false;
|
|
|
|
@tracked communitySubscription = false;
|
|
|
|
@tracked standardSubscription = false;
|
|
|
|
@tracked subscriptionAttributes = {};
|
|
|
|
subscriptionLandingUrl = PRODUCT_PAGE;
|
2023-09-23 23:52:46 +02:00
|
|
|
|
2023-09-24 12:58:20 +02:00
|
|
|
init() {
|
|
|
|
super.init(...arguments);
|
|
|
|
this.retrieveSubscriptionStatus();
|
|
|
|
}
|
2023-09-23 23:52:46 +02:00
|
|
|
|
2023-09-24 12:58:20 +02:00
|
|
|
retrieveSubscriptionStatus() {
|
|
|
|
ajax("/admin/wizards/subscription")
|
|
|
|
.then((result) => {
|
2023-09-23 23:52:46 +02:00
|
|
|
this.subscribed = result.subscribed;
|
|
|
|
this.subscriptionType = result.subscription_type;
|
|
|
|
this.subscriptionAttributes = result.subscription_attributes;
|
2023-09-25 16:41:01 +02:00
|
|
|
this.businessSubscription = this.subscriptionType === "business";
|
|
|
|
this.communitySubscription = this.subscriptionType === "community";
|
|
|
|
this.standardSubscription = this.subscriptionType === "standard";
|
2023-09-23 23:52:46 +02:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
2023-09-24 12:58:20 +02:00
|
|
|
}
|
2023-09-23 23:52:46 +02:00
|
|
|
|
2023-09-24 12:58:20 +02:00
|
|
|
get subscriptionLink() {
|
|
|
|
return this.subscriptionLandingUrl;
|
|
|
|
}
|
2023-09-23 19:30:11 +02:00
|
|
|
|
2023-09-24 12:58:20 +02:00
|
|
|
get subscriptionCtaLink() {
|
|
|
|
switch (this.subscriptionType) {
|
|
|
|
case "none":
|
|
|
|
return PRODUCT_PAGE;
|
|
|
|
case "standard":
|
|
|
|
return SUPPORT_MESSAGE;
|
|
|
|
case "business":
|
|
|
|
return SUPPORT_MESSAGE;
|
|
|
|
case "community":
|
|
|
|
return MANAGER_CATEGORY;
|
|
|
|
default:
|
|
|
|
return PRODUCT_PAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|