mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Refactored members email settings screen
no issue - simplified query params as they are only used to display a notification - removed all controller knowledge and associated reset behaviour for query params - moved notification display from `setupController` to `beforeModel` so the raw query params can be pulled off of the transition object - removed unused service injections from `<GhMembersEmailSetting>` - removed unused service injections and properties from members-email controller that were left over from a copy/paste - converted members-email controller to a native class - fixed "leave settings" confirmation modal behaviour that wasn't moved across in the the settings screen re-org
This commit is contained in:
parent
284b012083
commit
7b340929ef
5 changed files with 80 additions and 94 deletions
|
@ -194,13 +194,6 @@
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if this.showLeaveSettingsModal}}
|
|
||||||
<GhFullscreenModal @modal="leave-settings"
|
|
||||||
@confirm={{action "leavePortalSettings"}}
|
|
||||||
@close={{action "closeLeaveSettingsModal"}}
|
|
||||||
@modifier="action wide" />
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if this.showEmailDesignSettings}}
|
{{#if this.showEmailDesignSettings}}
|
||||||
<GhFullscreenModal @modifier="full-overlay portal-settings">
|
<GhFullscreenModal @modifier="full-overlay portal-settings">
|
||||||
<ModalEmailDesignSettings
|
<ModalEmailDesignSettings
|
||||||
|
|
|
@ -19,9 +19,7 @@ const REPLY_ADDRESSES = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
feature: service(),
|
|
||||||
config: service(),
|
config: service(),
|
||||||
mediaQueries: service(),
|
|
||||||
ghostPaths: service(),
|
ghostPaths: service(),
|
||||||
ajax: service(),
|
ajax: service(),
|
||||||
settings: service(),
|
settings: service(),
|
||||||
|
@ -30,9 +28,7 @@ export default Component.extend({
|
||||||
showFromAddressConfirmation: false,
|
showFromAddressConfirmation: false,
|
||||||
showSupportAddressConfirmation: false,
|
showSupportAddressConfirmation: false,
|
||||||
showEmailDesignSettings: false,
|
showEmailDesignSettings: false,
|
||||||
showLeaveSettingsModal: false,
|
|
||||||
|
|
||||||
// passed in actions
|
|
||||||
mailgunIsConfigured: reads('config.mailgunIsConfigured'),
|
mailgunIsConfigured: reads('config.mailgunIsConfigured'),
|
||||||
emailTrackOpens: reads('settings.emailTrackOpens'),
|
emailTrackOpens: reads('settings.emailTrackOpens'),
|
||||||
|
|
||||||
|
@ -136,10 +132,6 @@ export default Component.extend({
|
||||||
const newReplyAddress = event.value;
|
const newReplyAddress = event.value;
|
||||||
|
|
||||||
this.set('settings.membersReplyAddress', newReplyAddress);
|
this.set('settings.membersReplyAddress', newReplyAddress);
|
||||||
},
|
|
||||||
|
|
||||||
closeLeaveSettingsModal() {
|
|
||||||
this.set('showLeaveSettingsModal', false);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,44 +1,48 @@
|
||||||
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
||||||
import Controller from '@ember/controller';
|
import Controller from '@ember/controller';
|
||||||
import {computed} from '@ember/object';
|
import {action} from '@ember/object';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
import {task} from 'ember-concurrency';
|
import {task} from 'ember-concurrency-decorators';
|
||||||
|
import {tracked} from '@glimmer/tracking';
|
||||||
|
|
||||||
export default Controller.extend({
|
export default class MembersEmailController extends Controller {
|
||||||
ajax: service(),
|
@service config;
|
||||||
config: service(),
|
@service session;
|
||||||
feature: service(),
|
@service settings;
|
||||||
ghostPaths: service(),
|
|
||||||
notifications: service(),
|
|
||||||
session: service(),
|
|
||||||
settings: service(),
|
|
||||||
|
|
||||||
queryParams: ['fromAddressUpdate', 'supportAddressUpdate'],
|
// from/supportAddress are set here so that they can be reset to saved values on save
|
||||||
fromAddressUpdate: null,
|
// to avoid it looking like they've been saved when they have a separate update process
|
||||||
supportAddressUpdate: null,
|
@tracked fromAddress = '';
|
||||||
importErrors: null,
|
@tracked supportAddress = '';
|
||||||
importSuccessful: false,
|
|
||||||
showDeleteAllModal: false,
|
|
||||||
submitting: false,
|
|
||||||
uploadButtonText: 'Import',
|
|
||||||
|
|
||||||
importMimeType: null,
|
@tracked showLeaveSettingsModal = false;
|
||||||
jsonExtension: null,
|
|
||||||
jsonMimeType: null,
|
|
||||||
yamlExtension: null,
|
|
||||||
yamlMimeType: null,
|
|
||||||
|
|
||||||
yamlAccept: null,
|
@action
|
||||||
|
setEmailAddress(property, email) {
|
||||||
|
this[property] = email;
|
||||||
|
}
|
||||||
|
|
||||||
fromAddress: computed(function () {
|
leaveRoute(transition) {
|
||||||
return this.parseEmailAddress(this.settings.get('membersFromAddress'));
|
if (this.settings.get('hasDirtyAttributes')) {
|
||||||
}),
|
transition.abort();
|
||||||
|
this.leaveSettingsTransition = transition;
|
||||||
|
this.showLeaveSettingsModal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
supportAddress: computed(function () {
|
@action
|
||||||
return this.parseEmailAddress(this.settings.get('membersSupportAddress'));
|
async confirmLeave() {
|
||||||
}),
|
this.settings.rollbackAttributes();
|
||||||
|
this.showLeaveSettingsModal = false;
|
||||||
|
this.leaveSettingsTransition.retry();
|
||||||
|
}
|
||||||
|
|
||||||
blogDomain: computed('config.blogDomain', function () {
|
@action
|
||||||
|
cancelLeave() {
|
||||||
|
this.showLeaveSettingsModal = false;
|
||||||
|
this.leaveSettingsTransition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get blogDomain() {
|
||||||
let blogDomain = this.config.blogDomain || '';
|
let blogDomain = this.config.blogDomain || '';
|
||||||
const domainExp = blogDomain.replace('https://', '').replace('http://', '').match(new RegExp('^([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
const domainExp = blogDomain.replace('https://', '').replace('http://', '').match(new RegExp('^([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
||||||
const domain = (domainExp && domainExp[1]) || '';
|
const domain = (domainExp && domainExp[1]) || '';
|
||||||
|
@ -46,13 +50,7 @@ export default Controller.extend({
|
||||||
return domain.replace(/^(www)\.(?=[^/]*\..{2,5})/, '');
|
return domain.replace(/^(www)\.(?=[^/]*\..{2,5})/, '');
|
||||||
}
|
}
|
||||||
return domain;
|
return domain;
|
||||||
}),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
setEmailAddress(type, emailAddress) {
|
|
||||||
this.set(type, emailAddress);
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
parseEmailAddress(address) {
|
parseEmailAddress(address) {
|
||||||
const emailAddress = address || 'noreply';
|
const emailAddress = address || 'noreply';
|
||||||
|
@ -61,18 +59,17 @@ export default Controller.extend({
|
||||||
return `${emailAddress}@${this.blogDomain}`;
|
return `${emailAddress}@${this.blogDomain}`;
|
||||||
}
|
}
|
||||||
return emailAddress;
|
return emailAddress;
|
||||||
},
|
|
||||||
|
|
||||||
saveSettings: task(function* () {
|
|
||||||
const response = yield this.settings.save();
|
|
||||||
// Reset from address value on save
|
|
||||||
this.set('fromAddress', this.parseEmailAddress(this.settings.get('membersFromAddress')));
|
|
||||||
this.set('supportAddress', this.parseEmailAddress(this.settings.get('membersSupportAddress')));
|
|
||||||
return response;
|
|
||||||
}).drop(),
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.set('fromAddressUpdate', null);
|
|
||||||
this.set('supportAddressUpdate', null);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
resetEmailAddresses() {
|
||||||
|
this.fromAddress = this.parseEmailAddress(this.settings.get('membersFromAddress'));
|
||||||
|
this.supportAddress = this.parseEmailAddress(this.settings.get('membersSupportAddress'));
|
||||||
|
}
|
||||||
|
|
||||||
|
@task({drop: true})
|
||||||
|
*saveSettings() {
|
||||||
|
const response = yield this.settings.save();
|
||||||
|
this.resetEmailAddresses();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,22 +3,27 @@ import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
||||||
settings: service(),
|
|
||||||
notifications: service(),
|
notifications: service(),
|
||||||
queryParams: {
|
settings: service(),
|
||||||
fromAddressUpdate: {
|
|
||||||
replace: true
|
|
||||||
},
|
|
||||||
supportAddressUpdate: {
|
|
||||||
replace: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel(transition) {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
return this.get('session.user')
|
return this.get('session.user')
|
||||||
.then(this.transitionAuthor())
|
.then(this.transitionAuthor())
|
||||||
.then(this.transitionEditor());
|
.then(this.transitionEditor())
|
||||||
|
.then(() => {
|
||||||
|
if (transition.to.queryParams?.fromAddressUpdate === 'success') {
|
||||||
|
this.notifications.showAlert(
|
||||||
|
`Newsletter email address has been updated`.htmlSafe(),
|
||||||
|
{type: 'success', key: 'members.settings.from-address.updated'}
|
||||||
|
);
|
||||||
|
} else if (transition.to.queryParams?.supportAddressUpdate === 'success') {
|
||||||
|
this.notifications.showAlert(
|
||||||
|
`Support email address has been updated`.htmlSafe(),
|
||||||
|
{type: 'success', key: 'members.settings.support-address.updated'}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
|
@ -26,22 +31,12 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller) {
|
setupController(controller) {
|
||||||
if (controller.fromAddressUpdate === 'success') {
|
controller.resetEmailAddresses();
|
||||||
this.notifications.showAlert(
|
|
||||||
`Newsletter email address has been updated`.htmlSafe(),
|
|
||||||
{type: 'success', key: 'members.settings.from-address.updated'}
|
|
||||||
);
|
|
||||||
} else if (controller.supportAddressUpdate === 'success') {
|
|
||||||
this.notifications.showAlert(
|
|
||||||
`Support email address has been updated`.htmlSafe(),
|
|
||||||
{type: 'success', key: 'members.settings.support-address.updated'}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
resetController(controller, isExiting) {
|
actions: {
|
||||||
if (isExiting) {
|
willTransition(transition) {
|
||||||
controller.reset();
|
return this.controller.leaveRoute(transition);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,19 @@
|
||||||
@settings={{this.settings}}
|
@settings={{this.settings}}
|
||||||
@fromAddress={{this.fromAddress}}
|
@fromAddress={{this.fromAddress}}
|
||||||
@supportAddress={{this.supportAddress}}
|
@supportAddress={{this.supportAddress}}
|
||||||
@setEmailAddress={{action "setEmailAddress"}}
|
@setEmailAddress={{this.setEmailAddress}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{{#if this.showLeaveSettingsModal}}
|
||||||
|
<GhFullscreenModal
|
||||||
|
@modal="leave-settings"
|
||||||
|
@confirm={{this.confirmLeave}}
|
||||||
|
@close={{this.cancelLeave}}
|
||||||
|
@modifier="action wide"
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
</section>
|
</section>
|
Loading…
Add table
Reference in a new issue