diff --git a/app/controllers/custom_wizard/admin/subscription.rb b/app/controllers/custom_wizard/admin/subscription.rb index 141b283a..7b596ec6 100644 --- a/app/controllers/custom_wizard/admin/subscription.rb +++ b/app/controllers/custom_wizard/admin/subscription.rb @@ -3,7 +3,12 @@ class CustomWizard::SubscriptionController < ::Admin::AdminController before_action :ensure_admin def index - subscription = CustomWizard::Subscription.new + if params[:update_from_remote] + subscription = CustomWizard::Subscription.new(true) + else + subscription = CustomWizard::Subscription.new + end + render_json_dump( subscribed: subscription.subscribed?, subscription_type: subscription.type, diff --git a/assets/javascripts/discourse/components/wizard-subscription-badge.js b/assets/javascripts/discourse/components/wizard-subscription-badge.js index 39b6cf81..f2115fdb 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-badge.js +++ b/assets/javascripts/discourse/components/wizard-subscription-badge.js @@ -39,7 +39,7 @@ export default class WizardSubscriptionBadge extends Component { update() { this.updating = true; this.updateIcon = "check"; - this.subscription.retrieveSubscriptionStatus().finally(() => { + this.subscription.updateSubscriptionStatus().finally(() => { this.updating = false; setTimeout(() => { this.updateIcon = null; diff --git a/assets/javascripts/discourse/services/subscription.js b/assets/javascripts/discourse/services/subscription.js index 7ee5454c..0a784519 100644 --- a/assets/javascripts/discourse/services/subscription.js +++ b/assets/javascripts/discourse/services/subscription.js @@ -36,6 +36,19 @@ export default class SubscriptionService extends Service { this.standardSubscription = this.subscriptionType === "standard"; } + async updateSubscriptionStatus() { + 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"; + } + get subscriptionLink() { return this.subscriptionLandingUrl; } diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 47c7599c..8d9d122e 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -106,8 +106,11 @@ class CustomWizard::Subscription attr_accessor :product_id, :product_slug - def initialize - ::DiscourseSubscriptionClient::Subscriptions.update + def initialize(update = false) + if update + ::DiscourseSubscriptionClient::Subscriptions.update + end + result = ::DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") if result&.any?