0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-29 20:20:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/services/subscription.js

66 Zeilen
2,2 KiB
JavaScript

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";
const PRODUCT_PAGE = "https://custom-wizard.pavilion.tech/pricing";
const SUPPORT_MESSAGE =
"https://coop.pavilion.tech/new-message?username=support&title=Custom%20Wizard%20Support";
const MANAGER_CATEGORY =
2023-11-17 16:17:10 +01:00
"https://coop.pavilion.tech/c/support/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 = {};
2023-09-23 23:52:46 +02:00
2023-11-15 16:01:27 +01:00
async init() {
2023-09-24 12:58:20 +02:00
super.init(...arguments);
2023-11-15 16:01:27 +01:00
await this.retrieveSubscriptionStatus();
2023-09-24 12:58:20 +02:00
}
2023-09-23 23:52:46 +02:00
async retrieveSubscriptionStatus() {
2023-11-15 15:39:42 +01:00
let result = await ajax("/admin/wizards/subscription").catch(
popupAjaxError
);
this.subscribed = result.subscribed;
this.subscriptionType = result.subscription_type;
this.subscriptionAttributes = result.subscription_attributes;
this.businessSubscription = this.subscriptionType === "business";
this.communitySubscription = this.subscriptionType === "community";
this.standardSubscription = this.subscriptionType === "standard";
2023-09-24 12:58:20 +02:00
}
2023-09-23 23:52:46 +02:00
async updateSubscriptionStatus() {
2023-11-15 16:41:14 +01:00
let result = await ajax(
"/admin/wizards/subscription?update_from_remote=true"
).catch(popupAjaxError);
this.subscribed = result.subscribed;
this.subscriptionType = result.subscription_type;
this.subscriptionAttributes = result.subscription_attributes;
this.businessSubscription = this.subscriptionType === "business";
this.communitySubscription = this.subscriptionType === "community";
this.standardSubscription = this.subscriptionType === "standard";
}
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;
}
}
}