From 54a9e9470e389aa482dc94108ea03c512eda50a3 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 9 Jul 2024 11:24:40 +0200 Subject: [PATCH] Add login button when no_access reason is requiresLogin --- .../components/custom-wizard-no-access.js.es6 | 12 ++++++++++++ .../components/custom-wizard-no-access.hbs | 16 +++++++++++----- assets/stylesheets/common/wizard/wizard.scss | 7 ++++++- config/locales/client.en.yml | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-wizard-no-access.js.es6 b/assets/javascripts/discourse/components/custom-wizard-no-access.js.es6 index b3b2e26c..4a7f4889 100644 --- a/assets/javascripts/discourse/components/custom-wizard-no-access.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-no-access.js.es6 @@ -3,6 +3,8 @@ import discourseComputed from "discourse-common/utils/decorators"; import Component from "@ember/component"; import { dasherize } from "@ember/string"; import getURL from "discourse-common/lib/get-url"; +import cookie from "discourse/lib/cookie"; +import { getOwner } from "@ember/application"; export default Component.extend({ classNameBindings: [":wizard-no-access", "reasonClass"], @@ -17,6 +19,11 @@ export default Component.extend({ return this.siteSettings.title || ""; }, + @discourseComputed("reason") + showLoginButton(reason) { + return reason === "requiresLogin"; + }, + actions: { skip() { if (this.currentUser) { @@ -25,5 +32,10 @@ export default Component.extend({ window.location = getURL("/"); } }, + + showLogin() { + cookie("destination_url", getURL(`/w/${this.get("wizardId")}`)); + getOwner(this).lookup("route:application").send("showLogin"); + } }, }); diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-no-access.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-no-access.hbs index cb9f59f1..5ba51a61 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-no-access.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-no-access.hbs @@ -1,11 +1,17 @@
{{text}}
- + + {{#if showLoginButton}} +
\ No newline at end of file diff --git a/assets/stylesheets/common/wizard/wizard.scss b/assets/stylesheets/common/wizard/wizard.scss index 4c8f2357..e4a8ef77 100644 --- a/assets/stylesheets/common/wizard/wizard.scss +++ b/assets/stylesheets/common/wizard/wizard.scss @@ -158,7 +158,12 @@ body.custom-wizard { .no-access-gutter { margin-top: 10px; display: flex; - justify-content: flex-end; + justify-content: space-between; + + .return-to-site { + display: flex; + align-items: center; + } } .powered-by-discourse { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3e7feba1..15a78ed3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5,7 +5,7 @@ en: completed: "You have completed this wizard." not_permitted: "You are not permitted to access this wizard." none: "There is no wizard here." - return_to_site: "Return to {{siteName}}" + return_to_site: "Return to {{siteName}}." requires_login: "You need to be logged in to access this wizard." reset: "Reset this wizard." step_not_permitted: "You're not permitted to view this step."