2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-09-09 18:21:32 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes';
|
2022-07-15 15:44:26 +03:00
|
|
|
import VerifyEmail from '../../components/modals/settings/verify-email';
|
2022-09-09 18:21:32 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-03-29 14:49:09 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
export default class MembershipSettingsRoute extends AdminRoute {
|
2022-01-27 14:40:11 +03:00
|
|
|
@service notifications;
|
2021-03-29 14:49:09 +03:00
|
|
|
@service settings;
|
2022-07-15 15:44:26 +03:00
|
|
|
@service modals;
|
|
|
|
|
|
|
|
queryParams = {
|
|
|
|
verifyEmail: {
|
|
|
|
replace: true
|
|
|
|
}
|
|
|
|
};
|
2021-03-29 14:49:09 +03:00
|
|
|
|
2022-01-27 14:40:11 +03:00
|
|
|
beforeModel(transition) {
|
|
|
|
super.beforeModel(...arguments);
|
|
|
|
|
2022-07-15 15:44:26 +03:00
|
|
|
// @todo: remove in the future, but keep it for now because we might still have some old verification urls in emails
|
2022-01-27 14:40:11 +03:00
|
|
|
if (transition.to.queryParams?.supportAddressUpdate === 'success') {
|
|
|
|
this.notifications.showAlert(
|
|
|
|
`Support email address has been updated`,
|
|
|
|
{type: 'success', key: 'members.settings.support-address.updated'}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 14:49:09 +03:00
|
|
|
model() {
|
|
|
|
this.settings.reload();
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:44:26 +03:00
|
|
|
afterModel(model, transition) {
|
|
|
|
if (transition.to.queryParams.verifyEmail) {
|
|
|
|
this.modals.open(VerifyEmail, {
|
|
|
|
token: transition.to.queryParams.verifyEmail
|
|
|
|
});
|
|
|
|
|
|
|
|
// clear query param so it doesn't linger and cause problems re-entering route
|
|
|
|
transition.abort();
|
|
|
|
return this.transitionTo('settings.membership', {queryParams: {verifyEmail: null}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 18:21:32 +03:00
|
|
|
@action
|
|
|
|
async willTransition(transition) {
|
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return true;
|
2021-03-29 14:49:09 +03:00
|
|
|
}
|
2022-09-09 18:21:32 +03:00
|
|
|
|
|
|
|
transition.abort();
|
|
|
|
|
|
|
|
// wait for any existing confirm modal to be closed before allowing transition
|
|
|
|
if (this.confirmModal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
|
|
await this.controller.saveTask.last;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
|
|
|
|
if (shouldLeave) {
|
|
|
|
this.controller.reset();
|
|
|
|
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async confirmUnsavedChanges() {
|
|
|
|
if (this.controller.isDirty) {
|
|
|
|
this.confirmModal = this.modals
|
|
|
|
.open(ConfirmUnsavedChangesModal)
|
|
|
|
.finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.confirmModal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-29 14:49:09 +03:00
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
2021-05-14 17:35:07 +03:00
|
|
|
titleToken: 'Settings - Membership'
|
2021-03-29 14:49:09 +03:00
|
|
|
};
|
|
|
|
}
|
2021-05-17 14:40:08 +03:00
|
|
|
|
|
|
|
resetController(controller, isExiting) {
|
|
|
|
if (isExiting) {
|
|
|
|
controller.reset();
|
|
|
|
}
|
|
|
|
}
|
2021-03-29 14:49:09 +03:00
|
|
|
}
|