From 686dadbedaaa3c3f65eb2ca12f8ba7eaa4eb8e2c Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 17 May 2021 12:40:08 +0100 Subject: [PATCH] Fixed errors when closing portal settings modal no issue - added actions for handling close/confirm/cancel of portal settings rather than re-using the route-level leave modal because the portal settings modal does not need any knowledge of the route - added controller reset that is called when the route is exited to ensure no modals are shown when navigating back to the membership screen - fixed "cannot set on destroyed" error when portal settings are opened and closed quickly - removed usage of old `{{action}}` helper - this has been replaced with `{{on}}` and `{{fn}}` --- .../app/components/modal-portal-settings.js | 4 +- .../app/controllers/settings/membership.js | 48 ++++++++++++------- ghost/admin/app/routes/settings/membership.js | 6 +++ .../app/templates/settings/membership.hbs | 24 +++++++--- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ghost/admin/app/components/modal-portal-settings.js b/ghost/admin/app/components/modal-portal-settings.js index d189c3ffe6..5c4c50108d 100644 --- a/ghost/admin/app/components/modal-portal-settings.js +++ b/ghost/admin/app/components/modal-portal-settings.js @@ -153,7 +153,9 @@ export default ModalComponent.extend({ this._super(...arguments); this.get('settings.errors').clear(); run.later(this, function () { - this.set('hidePreviewFrame', false); + if (!this.isDestroyed && !this.isDestroying) { + this.set('hidePreviewFrame', false); + } }, 1200); }, diff --git a/ghost/admin/app/controllers/settings/membership.js b/ghost/admin/app/controllers/settings/membership.js index 57bfc7962d..dc35efd665 100644 --- a/ghost/admin/app/controllers/settings/membership.js +++ b/ghost/admin/app/controllers/settings/membership.js @@ -7,7 +7,8 @@ import {tracked} from '@glimmer/tracking'; export default class MembersAccessController extends Controller { @service settings; - @tracked showLeaveSettingsModal = false; + @tracked showLeavePortalModal = false; + @tracked showLeaveRouteModal = false; @tracked showPortalSettings = false; queryParams = ['showPortalSettings']; @@ -16,15 +17,35 @@ export default class MembersAccessController extends Controller { if (this.settings.get('hasDirtyAttributes')) { transition.abort(); this.leaveSettingsTransition = transition; - this.showLeaveSettingsModal = true; + this.showLeaveRouteModal = true; + } + } + + @action openPortalSettings() { + this.saveSettingsTask.perform(); + this.showPortalSettings = true; + } + + @action + closePortalSettings() { + const changedAttributes = this.settings.changedAttributes(); + if (changedAttributes && Object.keys(changedAttributes).length > 0) { + this.showLeavePortalModal = true; + } else { + this.showPortalSettings = false; } } @action - async leavePortalSettings() { + async confirmClosePortalSettings() { this.settings.rollbackAttributes(); this.showPortalSettings = false; - this.showLeaveSettingsModal = false; + this.showLeavePortalModal = false; + } + + @action + cancelClosePortalSettings() { + this.showLeavePortalModal = false; } @action @@ -32,26 +53,15 @@ export default class MembersAccessController extends Controller { // Open stripe settings here } - @action - closePortalSettings() { - const changedAttributes = this.settings.changedAttributes(); - if (changedAttributes && Object.keys(changedAttributes).length > 0) { - this.showLeaveSettingsModal = true; - } else { - this.showPortalSettings = false; - } - } - @action async confirmLeave() { this.settings.rollbackAttributes(); - this.showLeaveSettingsModal = false; this.leaveSettingsTransition.retry(); } @action cancelLeave() { - this.showLeaveSettingsModal = false; + this.showLeaveRouteModal = false; this.leaveSettingsTransition = null; } @@ -59,4 +69,10 @@ export default class MembersAccessController extends Controller { *saveSettingsTask() { return yield this.settings.save(); } + + reset() { + this.showLeaveRouteModal = false; + this.showLeavePortalModal = false; + this.showPortalSettings = false; + } } diff --git a/ghost/admin/app/routes/settings/membership.js b/ghost/admin/app/routes/settings/membership.js index 7448b24b48..fe954ac0b5 100644 --- a/ghost/admin/app/routes/settings/membership.js +++ b/ghost/admin/app/routes/settings/membership.js @@ -19,4 +19,10 @@ export default class MembershipSettingsRoute extends AuthenticatedRoute { titleToken: 'Settings - Membership' }; } + + resetController(controller, isExiting) { + if (isExiting) { + controller.reset(); + } + } } diff --git a/ghost/admin/app/templates/settings/membership.hbs b/ghost/admin/app/templates/settings/membership.hbs index 768181ef2a..95733e5f34 100644 --- a/ghost/admin/app/templates/settings/membership.hbs +++ b/ghost/admin/app/templates/settings/membership.hbs @@ -33,14 +33,14 @@

-
- +
@@ -67,7 +67,7 @@

Free

Free membership signup settings

- +
{{#liquid-if this.freeOpen}} @@ -94,7 +94,7 @@

Premium

Customise prices and premium signup options

- +
{{#liquid-if this.paidOpen}} @@ -144,7 +144,7 @@
- {{#if this.showLeaveSettingsModal}} + {{#if this.showLeaveRouteModal}} {{/if}} + {{#if this.showPortalSettings}} {{/if}} + + {{#if this.showLeavePortalModal}} + + {{/if}} \ No newline at end of file