From 186c6f3c421800837f7c77014e19f82f0ff21df4 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 1 Jul 2024 14:53:49 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20unexpected=20leave=20con?= =?UTF-8?q?firmation=20after=20Cmd+S=20on=20member=20profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix https://linear.app/tryghost/issue/ENG-779/%F0%9F%90%9B-cmds-does-not-save-member-profile-changes - previously, pressing Cmd+S on a member profile would save the profile, but the dirty attributes weren't being cleaned, so the application would trigger the leave confirmation when exiting - now, we've fixed the code to keep a dynamic scratch member, - long term, we should get rid of the scratch model, but this still allows us to fix the bug for now --- ghost/admin/app/controllers/member.js | 13 +++++++------ ghost/admin/app/routes/member.js | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ghost/admin/app/controllers/member.js b/ghost/admin/app/controllers/member.js index 0978126d08..a6606ec8bf 100644 --- a/ghost/admin/app/controllers/member.js +++ b/ghost/admin/app/controllers/member.js @@ -29,6 +29,7 @@ export default class MemberController extends Controller { @tracked showImpersonateMemberModal = false; @tracked modalLabel = null; @tracked showLabelModal = false; + @tracked scratchMember = null; _previousLabels = null; _previousNewsletters = null; @@ -56,6 +57,12 @@ export default class MemberController extends Controller { set member(member) { this.model = member; + + if (member !== this.scratchMember?.member) { + const scratchMember = EmberObject.create({member}); + SCRATCH_PROPS.forEach(prop => defineProperty(scratchMember, prop, boundOneWay(`member.${prop}`))); + this.scratchMember = scratchMember; + } } get dirtyAttributes() { @@ -92,12 +99,6 @@ export default class MemberController extends Controller { return options; } - get scratchMember() { - let scratchMember = EmberObject.create({member: this.member}); - SCRATCH_PROPS.forEach(prop => defineProperty(scratchMember, prop, boundOneWay(`member.${prop}`))); - return scratchMember; - } - get subscribedAt() { let memberSince = moment(this.member.createdAtUTC).from(moment()); let createdDate = moment(this.member.createdAtUTC).format('D MMM YYYY'); diff --git a/ghost/admin/app/routes/member.js b/ghost/admin/app/routes/member.js index ab9bdc8c75..3f70cd7bf5 100644 --- a/ghost/admin/app/routes/member.js +++ b/ghost/admin/app/routes/member.js @@ -34,6 +34,7 @@ export default class MembersRoute extends AdminRoute { setupController(controller, member, transition) { super.setupController(...arguments); + controller.member = member; controller.setInitialRelationshipValues();