From b1fddc33a747e4ff59ade646f1d2763ba21e1c09 Mon Sep 17 00:00:00 2001 From: merefield Date: Sat, 23 Sep 2023 22:52:46 +0100 Subject: [PATCH] evolve service --- .../components/wizard-subscription-status.js | 7 +++- .../discourse/services/subscription.js | 35 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-subscription-status.js b/assets/javascripts/discourse/components/wizard-subscription-status.js index ddd5c282..22493f9e 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-status.js +++ b/assets/javascripts/discourse/components/wizard-subscription-status.js @@ -7,6 +7,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; export default class WizardSubscriptionStatus extends Component { @service siteSettings; + @service subscription; @tracked supplierId = null; @tracked authorized = false; @tracked unauthorizing = false; @@ -17,6 +18,9 @@ export default class WizardSubscriptionStatus extends Component { ajax(`${this.basePath}`).then((result) => { this.supplierId = result.suppliers[0].id; this.authorized = result.suppliers[0].authorized; + }) + .finally(() => { + this.subscription.retrieveSubscriptionStatus(); }); } @@ -41,7 +45,8 @@ export default class WizardSubscriptionStatus extends Component { }) .finally(() => { this.unauthorizing = false; - window.location.reload(); + this.subscription.retrieveSubscriptionStatus(); + //window.location.reload(); }) .catch(popupAjaxError); } diff --git a/assets/javascripts/discourse/services/subscription.js b/assets/javascripts/discourse/services/subscription.js index 9525a928..606b62f0 100644 --- a/assets/javascripts/discourse/services/subscription.js +++ b/assets/javascripts/discourse/services/subscription.js @@ -1,5 +1,9 @@ import Service from '@ember/service'; import { getOwner } from "discourse-common/lib/get-owner"; +import { tracked } from "@glimmer/tracking"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { equal } from "@ember/object/computed"; const PRODUCT_PAGE = "https://custom-wizard.pavilion.tech"; const SUPPORT_MESSAGE = @@ -8,13 +12,32 @@ const MANAGER_CATEGORY = "https://discourse.pluginmanager.org/c/discourse-custom-wizard"; export default class SubscriptionService extends Service { + @tracked subscribed = false; + @tracked subscriptionType = ""; + @tracked businessSubscription = false; + @tracked communitySubscription = false; + @tracked standardSubscription = false; + @tracked subscriptionAttributes = {}; subscriptionLandingUrl = PRODUCT_PAGE; - subscribed = this.adminWizards.subscribed; - subscriptionType = this.adminWizards.subscriptionType; - businessSubscription = this.adminWizards.businessSubscription; - communitySubscription = this.adminWizards.communitySubscription; - standardSubscription = this.adminWizards.standardSubscription; - subscriptionAttributes = this.adminWizards.subscriptionAttributes; + + init() { + super.init(...arguments); + debugger; + this.retrieveSubscriptionStatus(); + } + + retrieveSubscriptionStatus() { + ajax("/admin/wizards").then(result => { + this.subscribed = result.subscribed; + this.subscriptionType = result.subscription_type; + this.subscriptionAttributes = result.subscription_attributes; + this.businessSubscription = equal(this.subscriptionType, "business"); + this.communitySubscription = equal(this.subscriptionType, "community"); + this.standardSubscription = equal(this.subscriptionType, "standard"); + }) + .catch(popupAjaxError); + }; + get adminWizards() { return getOwner(this).lookup("controller:admin-wizards");