2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-03-14 13:52:04 +03:00
|
|
|
import CustomIntegrationLimitsModal from '../../../components/modals/limits/custom-integration';
|
|
|
|
import NewCustomIntegrationModal from '../../../components/modals/new-custom-integration';
|
2022-01-13 16:16:13 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
export default class NewIntegrationRoute extends AdminRoute {
|
2022-01-13 16:16:13 +03:00
|
|
|
@service limit;
|
|
|
|
@service modals;
|
2022-03-11 22:10:44 +03:00
|
|
|
@service router;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-01-13 16:16:13 +03:00
|
|
|
modal = null;
|
|
|
|
|
|
|
|
async model() {
|
|
|
|
if (this.limit.limiter?.isLimited('customIntegrations')) {
|
|
|
|
try {
|
|
|
|
await this.limit.limiter.errorIfWouldGoOverLimit('customIntegrations');
|
|
|
|
} catch (error) {
|
2022-03-14 13:52:04 +03:00
|
|
|
this.modal = this.modals.open(CustomIntegrationLimitsModal, {
|
2022-01-13 16:16:13 +03:00
|
|
|
message: error.message
|
|
|
|
}, {
|
|
|
|
beforeClose: this.beforeModalClose
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
2022-01-13 16:16:13 +03:00
|
|
|
|
2022-03-14 13:52:04 +03:00
|
|
|
this.modal = this.modals.open(NewCustomIntegrationModal, {}, {
|
2022-01-13 16:16:13 +03:00
|
|
|
beforeClose: this.beforeModalClose
|
|
|
|
});
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
deactivate() {
|
2022-01-13 16:16:13 +03:00
|
|
|
// ensure we don't try to redirect on modal close if we're already transitioning away
|
|
|
|
this.isLeaving = true;
|
|
|
|
this.modal?.close();
|
|
|
|
|
|
|
|
this.modal = null;
|
|
|
|
this.isLeaving = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
beforeModalClose() {
|
2022-03-11 22:10:44 +03:00
|
|
|
if (this.modal && !this.isLeaving) {
|
|
|
|
this.router.transitionTo('settings.integrations');
|
2022-01-13 16:16:13 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
2022-01-13 16:16:13 +03:00
|
|
|
}
|