2022-03-31 13:06:21 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-04-04 21:26:49 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes';
|
2022-04-27 12:36:43 +03:00
|
|
|
import VerifyNewsletterEmail from '../../components/modals/newsletters/verify-newsletter-email';
|
2022-03-31 13:06:21 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class MembersEmailLabsRoute extends AdminRoute {
|
|
|
|
@service feature;
|
2022-04-04 21:26:49 +03:00
|
|
|
@service modals;
|
2022-03-31 13:06:21 +03:00
|
|
|
@service notifications;
|
|
|
|
@service settings;
|
|
|
|
|
2022-04-13 21:34:48 +03:00
|
|
|
queryParams = {
|
|
|
|
verifyEmail: {
|
|
|
|
replace: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-04 21:26:49 +03:00
|
|
|
confirmModal = null;
|
|
|
|
hasConfirmed = false;
|
|
|
|
|
2022-03-31 13:06:21 +03:00
|
|
|
model() {
|
|
|
|
return this.settings.reload();
|
|
|
|
}
|
|
|
|
|
2022-04-13 21:34:48 +03:00
|
|
|
afterModel(model, transition) {
|
|
|
|
if (transition.to.queryParams.verifyEmail) {
|
|
|
|
this.modals.open(VerifyNewsletterEmail, {
|
|
|
|
token: transition.to.queryParams.verifyEmail
|
|
|
|
});
|
|
|
|
|
|
|
|
// clear query param so it doesn't linger and cause problems re-entering route
|
|
|
|
transition.abort();
|
2022-05-05 14:36:16 +03:00
|
|
|
return this.transitionTo('settings.newsletters', {queryParams: {verifyEmail: null}});
|
2022-04-13 21:34:48 +03:00
|
|
|
}
|
2022-03-31 13:06:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
willTransition(transition) {
|
2022-04-04 21:26:49 +03:00
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// always abort when not confirmed because Ember's router doesn't automatically wait on promises
|
|
|
|
transition.abort();
|
|
|
|
|
|
|
|
this.confirmUnsavedChanges().then((shouldLeave) => {
|
|
|
|
if (shouldLeave) {
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this.confirmModal = null;
|
|
|
|
this.hasConfirmed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmUnsavedChanges() {
|
2022-10-07 16:23:21 +03:00
|
|
|
if (!this.settings.hasDirtyAttributes) {
|
2022-04-04 21:26:49 +03:00
|
|
|
return Promise.resolve(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.confirmModal) {
|
|
|
|
this.confirmModal = this.modals.open(ConfirmUnsavedChangesModal)
|
|
|
|
.then((discardChanges) => {
|
|
|
|
if (discardChanges === true) {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
}
|
|
|
|
return discardChanges;
|
|
|
|
}).finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.confirmModal;
|
2022-03-31 13:06:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Settings - Email newsletter'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|