From eecb17698f29e2e92880fbfb120030405ba754c9 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Wed, 2 Oct 2024 17:53:20 -0600 Subject: [PATCH] FIX: Redirect to the pricing table page when enabled (#239) If the pricing table is enabled the `/s` route should redirect to the pricing table route and vice versa. Co-authored-by: Jarek Radosz --- assets/javascripts/discourse/routes/subscribe.js | 15 ++++++++++++++- .../discourse/routes/subscriptions.js | 16 ++++++++++++++++ spec/system/pricing_table_spec.rb | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 assets/javascripts/discourse/routes/subscriptions.js diff --git a/assets/javascripts/discourse/routes/subscribe.js b/assets/javascripts/discourse/routes/subscribe.js index 0051f5c..2b5737b 100644 --- a/assets/javascripts/discourse/routes/subscribe.js +++ b/assets/javascripts/discourse/routes/subscribe.js @@ -1,3 +1,16 @@ import Route from "@ember/routing/route"; +import { service } from "@ember/service"; -export default Route.extend(); +export default class SubscribeRoute extends Route { + @service router; + @service siteSettings; + + beforeModel() { + const pricingTableEnabled = + this.siteSettings.discourse_subscriptions_pricing_table_enabled; + + if (pricingTableEnabled) { + this.router.transitionTo("subscriptions"); + } + } +} diff --git a/assets/javascripts/discourse/routes/subscriptions.js b/assets/javascripts/discourse/routes/subscriptions.js new file mode 100644 index 0000000..893c239 --- /dev/null +++ b/assets/javascripts/discourse/routes/subscriptions.js @@ -0,0 +1,16 @@ +import Route from "@ember/routing/route"; +import { service } from "@ember/service"; + +export default class SubscriptionsRoute extends Route { + @service router; + @service siteSettings; + + beforeModel() { + const pricingTableEnabled = + this.siteSettings.discourse_subscriptions_pricing_table_enabled; + + if (!pricingTableEnabled) { + this.router.transitionTo("subscribe"); + } + } +} diff --git a/spec/system/pricing_table_spec.rb b/spec/system/pricing_table_spec.rb index 880bc7d..dd4e605 100644 --- a/spec/system/pricing_table_spec.rb +++ b/spec/system/pricing_table_spec.rb @@ -102,4 +102,19 @@ RSpec.describe "Pricing Table", type: :system, js: true do text: "Log in or create an account to subscribe.", ) end + + it "Redirects to the pricing table page if enabled" do + sign_in(admin) + visit("/s") + + try_until_success { expect(current_url).to match("/s/subscriptions") } + end + + it "Redirects to /s if pricing table is not enabled" do + sign_in(admin) + SiteSetting.discourse_subscriptions_campaign_enabled = false + visit("/s/subscriptions") + + try_until_success { expect(current_url).to match("/s") } + end end