A platform for community discussion. Free, open, simple.
UX: Add loading state to button when confirming password (#32012)
Alan Guo Xiang Tan1fd553ccb0d7
diff --git a/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs b/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjsindex 6c7952d951d..492eeb7c5fa 100644--- a/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs+++ b/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs@@ -20,6 +20,7 @@ export default class ConfirmSession extends Component {@tracked errorMessage;@tracked resetEmailSent = null;+ @tracked isLoading = false;passwordLabel = i18n("user.password.title");instructions = i18n("user.confirm_access.instructions");@@ -64,22 +65,28 @@ export default class ConfirmSession extends Component {@actionasync submit() {- this.errorMessage = this.password- ? null- : i18n("user.confirm_access.incorrect_password");-- const result = await ajax("/u/confirm-session.json", {- type: "POST",- data: {- password: this.password,- },- });-- if (result.success) {- this.errorMessage = null;- this.dialog.didConfirmWrapped();- } else {- this.errorMessage = i18n("user.confirm_access.incorrect_password");+ try {+ this.isLoading = true;++ this.errorMessage = this.password+ ? null+ : i18n("user.confirm_access.incorrect_password");++ const result = await ajax("/u/confirm-session.json", {+ type: "POST",+ data: {+ password: this.password,+ },+ });++ if (result.success) {+ this.errorMessage = null;+ this.dialog.didConfirmWrapped();+ } else {+ this.errorMessage = i18n("user.confirm_access.incorrect_password");+ }+ } finally {+ this.isLoading = false;}}@@ -140,6 +147,7 @@ export default class ConfirmSession extends Component {autofocus="autofocus"/><DButton+ @isLoading={{this.isLoading}}class="btn-primary"@type="submit"@action={{this.submit}}diff --git a/spec/system/forgot_password_spec.rb b/spec/system/forgot_password_spec.rbindex d61b3987dcf..34885e492b6 100644--- a/spec/system/forgot_password_spec.rb+++ b/spec/system/forgot_password_spec.rb@@ -209,11 +209,11 @@ shared_examples "forgot password scenarios" doenddescribe "User resetting password", type: :system do- skip "when desktop" do+ describe "when desktop" doinclude_examples "forgot password scenarios"end- skip "when mobile", mobile: true do+ describe "when mobile", mobile: true doinclude_examples "forgot password scenarios"endenddiff --git a/spec/system/page_objects/pages/user_preferences_security.rb b/spec/system/page_objects/pages/user_preferences_security.rbindex 3253a22f795..fe1abed1b90 100644--- a/spec/system/page_objects/pages/user_preferences_security.rb+++ b/spec/system/page_objects/pages/user_preferences_security.rb@@ -10,9 +10,10 @@ module PageObjectsdef visit_second_factor(password)click_button "Manage Two-Factor Authentication"-- find(".dialog-body input#password").fill_in(with: password)- find(".dialog-body .btn-primary").click+ find(".confirm-session input#password").fill_in(with: password)+ find(".confirm-session .btn-primary:not([disabled])").click+ has_no_css?(".confirm-session")+ selfendendend