DEV: fix linter issues

This commit is contained in:
spirobel 2023-07-13 14:17:19 +08:00 committed by Blake Erickson
parent ff981f76e8
commit bf7079928e
6 changed files with 69 additions and 59 deletions

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
module StripeDiscourseSubscriptions module StripeDiscourseSubscriptions
class PricingtableController < ::ApplicationController class PricingtableController < ::ApplicationController
def index def index
head 200 head 200
end
end end
end end
end

View File

@ -1,35 +1,37 @@
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import Ember from 'ember'; import Ember from "ember";
import { htmlSafe } from "@ember/template";
import I18n from "I18n"; import I18n from "I18n";
export default Controller.extend({ export default Controller.extend({
init() { init() {
// Perform any initialization logic here // Perform any initialization logic here
this._super(...arguments); this._super(...arguments);
// Additional custom initialization code // Additional custom initialization code
if(this.currentUser){ if (this.currentUser) {
this.currentUser.checkEmail().then((r)=>this.set('email',this.currentUser.email)) this.currentUser
} .checkEmail()
.then(() => this.set("email", this.currentUser.email));
}, }
pricingTable: Ember.computed('email', function() { },
try{ pricingTable: Ember.computed("email", function () {
const pricing_table_info = JSON.parse(this.siteSettings.discourse_subscriptions_pricing_table) try {
if(this.currentUser){ const pricing_table_info = JSON.parse(
return`<stripe-pricing-table this.siteSettings.discourse_subscriptions_pricing_table
);
if (this.currentUser) {
return htmlSafe(`<stripe-pricing-table
pricing-table-id="${pricing_table_info.pricingTableId}" pricing-table-id="${pricing_table_info.pricingTableId}"
publishable-key="${pricing_table_info.publishableKey}" publishable-key="${pricing_table_info.publishableKey}"
customer-email="${this.email}"></stripe-pricing-table>`; customer-email="${this.email}"></stripe-pricing-table>`);
} else { } else {
return`<stripe-pricing-table return htmlSafe(`<stripe-pricing-table
pricing-table-id="${pricing_table_info.pricingTableId}" pricing-table-id="${pricing_table_info.pricingTableId}"
publishable-key="${pricing_table_info.publishableKey}" publishable-key="${pricing_table_info.publishableKey}"
></stripe-pricing-table>`; ></stripe-pricing-table>`);
} }
} catch (error) {
return I18n.t("discourse_subscriptions.subscribe.no_products");
} catch(error){ }
return I18n.t("discourse_subscriptions.subscribe.no_products") }),
}
}),
}); });

View File

@ -23,29 +23,35 @@ export default {
href: `/u/${user.username}/billing/subscriptions`, href: `/u/${user.username}/billing/subscriptions`,
content: "Billing", content: "Billing",
}); });
if(user.admin){ if (user.admin) {
api.modifyClassStatic('model:site-setting', { api.modifyClassStatic("model:site-setting", {
pluginId: 'discourse-subscriptions', pluginId: "discourse-subscriptions",
update(key, value, opts = {}) { update(key, value, opts = {}) {
if(key ==="discourse_subscriptions_pricing_table"){ if (key === "discourse_subscriptions_pricing_table") {
const inputString = value; const inputString = value;
// Extract pricing-table-id // Extract pricing-table-id
const pricingTableIdRegex = /pricing-table-id="([^"]+)"/; const pricingTableIdRegex = /pricing-table-id="([^"]+)"/;
const pricingTableIdMatch = inputString.match(pricingTableIdRegex); const pricingTableIdMatch =
const pricingTableId = pricingTableIdMatch ? pricingTableIdMatch[1] : null; inputString.match(pricingTableIdRegex);
const pricingTableId = pricingTableIdMatch
// Extract publishable-key ? pricingTableIdMatch[1]
const publishableKeyRegex = /publishable-key="([^"]+)"/; : null;
const publishableKeyMatch = inputString.match(publishableKeyRegex);
const publishableKey = publishableKeyMatch ? publishableKeyMatch[1] : null; // Extract publishable-key
if(pricingTableId && publishableKey){ const publishableKeyRegex = /publishable-key="([^"]+)"/;
value = JSON.stringify({pricingTableId,publishableKey}) const publishableKeyMatch =
} inputString.match(publishableKeyRegex);
const publishableKey = publishableKeyMatch
? publishableKeyMatch[1]
: null;
if (pricingTableId && publishableKey) {
value = JSON.stringify({ pricingTableId, publishableKey });
} }
this._super(key, value, opts);
} }
}); this._super(key, value, opts);
},
});
} }
} }
}); });

View File

@ -1,3 +1,3 @@
export default function () { export default function () {
this.route("subscriptions") this.route("subscriptions");
} }

View File

@ -1,3 +1,3 @@
<div class="container"> <div class="container">
{{{pricingTable}}} {{pricingTable}}
</div> </div>

View File

@ -70,16 +70,16 @@ after_initialize do
module ::StripeDiscourseSubscriptions module ::StripeDiscourseSubscriptions
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
engine_name 'stripe-discourse-subscriptions' engine_name "stripe-discourse-subscriptions"
isolate_namespace StripeDiscourseSubscriptions isolate_namespace StripeDiscourseSubscriptions
end end
end end
StripeDiscourseSubscriptions::Engine.routes.draw do StripeDiscourseSubscriptions::Engine.routes.draw { get "/" => "pricingtable#index" }
get "/" => "pricingtable#index"
end
require_relative "app/controllers/discourse_subscriptions/pricingtable_controller.rb" require_relative "app/controllers/discourse_subscriptions/pricingtable_controller.rb"
Discourse::Application.routes.append { mount ::StripeDiscourseSubscriptions::Engine, at: "subscriptions" } Discourse::Application.routes.append do
mount ::StripeDiscourseSubscriptions::Engine, at: "subscriptions"
end
::Stripe.set_app_info( ::Stripe.set_app_info(
"Discourse Subscriptions", "Discourse Subscriptions",