0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Re-ordered memberships controller code

no issue

- put setup and leave methods at the beginning so it's clearer what is happening when the screen is navigated to / away from
- move "private" method to the end to keep it out of the way
This commit is contained in:
Kevin Ansfield 2021-05-19 18:20:07 +01:00
parent 32c9ee003f
commit 5a3c9a54b1

View file

@ -56,6 +56,12 @@ export default class MembersAccessController extends Controller {
return envConfig.environment !== 'development' && !/^https:/.test(siteUrl);
}
@action
setup() {
this.fetchDefaultProduct.perform();
this.updatePortalPreview();
}
leaveRoute(transition) {
if (this.settings.get('hasDirtyAttributes')) {
transition.abort();
@ -64,29 +70,17 @@ export default class MembersAccessController extends Controller {
}
}
_validateSignupRedirect(url, type) {
const siteUrl = this.config.get('blogUrl');
let errMessage = `Please enter a valid URL`;
this.settings.get('errors').remove(type);
this.settings.get('hasValidated').removeObject(type);
if (url === null) {
this.settings.get('errors').add(type, errMessage);
this.settings.get('hasValidated').pushObject(type);
return false;
@action
async confirmLeave() {
this.settings.rollbackAttributes();
this.resetPrices();
this.leaveSettingsTransition.retry();
}
if (url === undefined) {
// Not initialised
return;
}
if (url.href.startsWith(siteUrl)) {
const path = url.href.replace(siteUrl, '');
this.settings.set(type, path);
} else {
this.settings.set(type, url.href);
}
@action
cancelLeave() {
this.showLeaveRouteModal = false;
this.leaveSettingsTransition = null;
}
@action
@ -168,18 +162,6 @@ export default class MembersAccessController extends Controller {
this.showLeavePortalModal = false;
}
@action
async confirmLeave() {
this.settings.rollbackAttributes();
this.leaveSettingsTransition.retry();
}
@action
cancelLeave() {
this.showLeaveRouteModal = false;
this.leaveSettingsTransition = null;
}
@action
updatePortalPreview() {
// TODO: can these be worked out from settings in membersUtils?
@ -243,12 +225,6 @@ export default class MembersAccessController extends Controller {
}
}
@action
setup() {
this.fetchDefaultProduct.perform();
this.updatePortalPreview();
}
async saveProduct() {
if (this.product) {
const stripePrices = this.product.stripePrices || [];
@ -392,4 +368,29 @@ export default class MembersAccessController extends Controller {
this.showLeavePortalModal = false;
this.showPortalSettings = false;
}
_validateSignupRedirect(url, type) {
const siteUrl = this.config.get('blogUrl');
let errMessage = `Please enter a valid URL`;
this.settings.get('errors').remove(type);
this.settings.get('hasValidated').removeObject(type);
if (url === null) {
this.settings.get('errors').add(type, errMessage);
this.settings.get('hasValidated').pushObject(type);
return false;
}
if (url === undefined) {
// Not initialised
return;
}
if (url.href.startsWith(siteUrl)) {
const path = url.href.replace(siteUrl, '');
this.settings.set(type, path);
} else {
this.settings.set(type, url.href);
}
}
}