Updated newsletter management for switch to nullable `sender_name`

refs https://github.com/TryGhost/Team/issues/1513

- `sender_name` is now nullable with a fallback to the site title
- updated new-newsletter route
  - removed default setting of site title in `senderName` of the new newsletter instance
  - removed extra checks when showing unsaved changes modal as we no longer need to compare the `senderName` attribute against the site title
- updated newsletter preview so the sender name falls back to the site title
- updated sender name input placeholder to show the site title
- removed not-empty validation
- fixed the switch to "multiple newsletter" state in the background of the new-newsletter modal
  - problem was `displayingDefault` getter was looking at all active newsletters rather than just the filtered ones so it was counting the new-but-unsaved newsletter even though it wasn't displayed in the list
  - fixes layout glitch when the new-newsletter modal animates out after cancelling creation
This commit is contained in:
Kevin Ansfield 2022-04-15 09:43:10 +01:00
parent 296be159b5
commit 98270704d3
6 changed files with 6 additions and 24 deletions

View File

@ -2,7 +2,7 @@
<div class="gh-members-emailpreview-container">
<div class="gh-members-emailpreview-faux">
<p>
<span class="strong">{{@newsletter.senderName}}</span> &lt;{{full-email-address (or @newsletter.senderEmail "noreply")}}&gt;
<span class="strong">{{or @newsletter.senderName this.settings.title}}</span> &lt;{{full-email-address (or @newsletter.senderEmail "noreply")}}&gt;
</p>
<p><span class="dark">To:</span> Jamie Larson &lt;jamie@example.com&gt;</p>
</div>

View File

@ -33,6 +33,7 @@
type="text"
class="gh-input miw-100 form-text"
value={{@newsletter.senderName}}
placeholder={{this.settings.title}}
{{on "input" (fn this.onInput "senderName")}}
/>
<GhErrorMessage @errors={{@newsletter.errors}} @property="senderName" />

View File

@ -35,7 +35,7 @@ export default class NewsletterManagementComponent extends Component {
}
get displayingDefault() {
return this.statusFilter === 'active' && this.activeNewsletters.length === 1;
return this.statusFilter === 'active' && this.filteredNewsletters.length === 1;
}
@action

View File

@ -13,9 +13,7 @@ export default class NewNewsletterRoute extends AdminRoute {
newsletterModal = null;
model() {
return this.store.createRecord('newsletter', {
senderName: this.settings.get('title')
});
return this.store.createRecord('newsletter');
}
setupController(controller, model) {
@ -69,19 +67,7 @@ export default class NewNewsletterRoute extends AdminRoute {
async confirmUnsavedChanges() {
const newsletter = this.newsletterModal?._data.newsletter;
if (newsletter?.hasDirtyAttributes) {
// first, check that we're not dirty just because we set the default senderName
// TODO: remove when senderName is nullable
const changedAttributes = newsletter.changedAttributes();
const changedKeys = Object.keys(changedAttributes);
const onlyDefaultChanged = changedKeys.length === 1
&& changedKeys[0] === 'senderName'
&& newsletter.senderName === this.settings.get('title');
if (onlyDefaultChanged) {
return true;
}
if (newsletter && newsletter.hasDirtyAttributes && Object.keys(newsletter.changedAttributes()).length > 0) {
this.confirmModal = this.modals.open(ConfirmUnsavedChangesModal)
.then((discardChanges) => {
if (discardChanges === true) {

View File

@ -20,11 +20,6 @@ export default BaseValidator.create({
},
senderName(model) {
if (isBlank(model.senderName)) {
model.errors.add('senderName', 'Please enter a sender name.');
this.invalidate();
}
if (!validator.isLength(model.senderName || '', 0, 191)) {
model.errors.add('senderName', 'Cannot be longer than 191 characters.');
this.invalidate();

View File

@ -16,7 +16,7 @@ export default function (server) {
slug: 'site-title',
description: 'Default newsletter created during setup',
senderName: 'Site title',
senderName: null,
senderEmail: null,
senderReplyTo: 'newsletter',