diff --git a/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 new file mode 100644 index 0000000..6d5402e --- /dev/null +++ b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 @@ -0,0 +1,7 @@ +export default { + resource: 'user', + path: 'users/:username', + map() { + this.route('billing'); + } +}; \ No newline at end of file diff --git a/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 new file mode 100644 index 0000000..1242ca8 --- /dev/null +++ b/assets/javascripts/discourse/helpers/user-viewing-self.js.es6 @@ -0,0 +1,9 @@ +import { registerUnbound } from 'discourse-common/lib/helpers'; + +export default registerUnbound('user-viewing-self', function(model) { + if (Discourse.User.current()){ + return Discourse.User.current().username.toLowerCase() === model.username.toLowerCase(); + } + + return false; +}); diff --git a/assets/javascripts/discourse/routes/user-billing.js.es6 b/assets/javascripts/discourse/routes/user-billing.js.es6 new file mode 100644 index 0000000..8b2ee5b --- /dev/null +++ b/assets/javascripts/discourse/routes/user-billing.js.es6 @@ -0,0 +1,16 @@ + +export default Discourse.Route.extend({ + model() { + console.log('billing'); + return {}; + }, + + setupController(controller, model) { + if (this.currentUser.id !== this.modelFor("user").id) { + this.replaceWith("userActivity"); + } + else { + controller.setProperties({ model }); + }; + } +}); diff --git a/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs b/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs new file mode 100644 index 0000000..b225547 --- /dev/null +++ b/assets/javascripts/discourse/templates/connectors/user-main-nav/billing.hbs @@ -0,0 +1,3 @@ +{{#if (user-viewing-self model)}} + {{#link-to 'user.billing'}}{{d-icon "credit-card"}}{{I18n 'discourse_patrons.navigation.billing'}}{{/link-to}} +{{/if}} diff --git a/assets/javascripts/discourse/templates/user/billing.hbs b/assets/javascripts/discourse/templates/user/billing.hbs new file mode 100644 index 0000000..de05057 --- /dev/null +++ b/assets/javascripts/discourse/templates/user/billing.hbs @@ -0,0 +1,3 @@ + + +user/billing diff --git a/plugin.rb b/plugin.rb index 4b34b96..a0a6b8c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -12,6 +12,7 @@ gem 'stripe', '5.7.1' register_asset "stylesheets/common/discourse-patrons.scss" register_asset "stylesheets/mobile/discourse-patrons.scss" +register_svg_icon "credit-card" if respond_to?(:register_svg_icon) register_html_builder('server:before-head-close') do "" @@ -33,6 +34,7 @@ Discourse::Application.routes.append do get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index' get '/admin/plugins/discourse-patrons/plans' => 'admin/plugins#index' get '/admin/plugins/discourse-patrons/plans/:plan_id' => 'admin/plugins#index' + get 'u/:username/billing' => 'users#show', constraints: {username: USERNAME_ROUTE_FORMAT} end after_initialize do