From baf75c39cf5e08154cf84fa391acf64f2ef83e74 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 19 Apr 2022 21:56:13 +0100 Subject: [PATCH] Added auto-subscribe newsletter count when confirming newsletter creation refs https://github.com/TryGhost/Team/issues/1528 - used the already-loaded newsletters list to pass the slugs of active newsletters to the confirm modal, this allows use of the `{{members-count-fetcher}}` resource with the query `/members/?filter=newsletters:[...slugs]` to fetch a member and full count metadata - added inclusion of `{{join}}` helper from `ember-composable-helpers` addon --- ghost/admin/app/components/modals/edit-newsletter.js | 12 +++++++++++- .../modals/edit-newsletter/confirm-create.hbs | 9 ++------- ghost/admin/ember-cli-build.js | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ghost/admin/app/components/modals/edit-newsletter.js b/ghost/admin/app/components/modals/edit-newsletter.js index bf6d399fd8..d37faf2af4 100644 --- a/ghost/admin/app/components/modals/edit-newsletter.js +++ b/ghost/admin/app/components/modals/edit-newsletter.js @@ -8,6 +8,7 @@ import {tracked} from '@glimmer/tracking'; export default class EditNewsletterModal extends Component { @service modals; + @service store; static modalOptions = { className: 'fullscreen-modal-full-overlay fullscreen-modal-portal-settings' @@ -16,6 +17,14 @@ export default class EditNewsletterModal extends Component { @tracked tab = 'settings'; @tracked optInExisting = this.args.data.newsletter.isNew; + get activeNewsletterSlugs() { + const activeNewsletters = this.store.peekAll('newsletter').filter((n) => { + return n.status === 'active' && !n.isNew && !n.isDestroyed; + }); + + return activeNewsletters.map(n => n.slug); + } + willDestroy() { super.willDestroy(...arguments); this.args.data.newsletter.rollbackAttributes(); @@ -48,7 +57,8 @@ export default class EditNewsletterModal extends Component { const shouldCreate = yield this.modals.open(ConfirmCreateModal, { optInExisting, - newsletter: this.args.data.newsletter + newsletter: this.args.data.newsletter, + activeNewsletterSlugs: this.activeNewsletterSlugs }); if (!shouldCreate) { diff --git a/ghost/admin/app/components/modals/edit-newsletter/confirm-create.hbs b/ghost/admin/app/components/modals/edit-newsletter/confirm-create.hbs index a54a081c76..8bc2c6c373 100644 --- a/ghost/admin/app/components/modals/edit-newsletter/confirm-create.hbs +++ b/ghost/admin/app/components/modals/edit-newsletter/confirm-create.hbs @@ -7,17 +7,12 @@