Ghost/ghost/admin/app/routes/pro.js
Kevin Ansfield 7b443d4b63 Removed need for .get() with config service
no issue

The `config` service has been a source of confusion when writing with modern Ember patterns because it's use of the deprecated `ProxyMixin` forced all property access/setting to go via `.get()` and `.set()` whereas the rest of the system has mostly (there are a few other uses of ProxyObjects remaining) eliminated the use of the non-native get/set methods.

- removed use of `ProxyMixin` in the `config` service by grabbing the API response after fetching and using `Object.defineProperty()` to add native getters/setters that pass through to a tracked object holding the API response data. Ember's autotracking automatically works across the native getters/setters so we can then use the service as if it was any other native object
- updated all code to use `config.{attrName}` directly for getting/setting instead of `.get()` and `.set()`
- removed unnecessary async around `config.availableTimezones` which wasn't making any async calls
2022-10-07 16:14:57 +01:00

58 lines
1.5 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class ProRoute extends AuthenticatedRoute {
@service billing;
@service session;
@service config;
queryParams = {
action: {refreshModel: true}
};
beforeModel(transition) {
super.beforeModel(...arguments);
// allow non-owner users to access the BMA when we're in a force upgrade state
if (!this.session.user.isOwnerOnly && !this.config.hostSettings?.forceUpgrade) {
return this.transitionTo('home');
}
this.billing.set('previousTransition', transition);
}
model(params) {
if (params.action) {
this.billing.set('action', params.action);
}
this.billing.toggleProWindow(true);
}
@action
willTransition(transition) {
let isBillingTransition = false;
if (transition) {
let destinationUrl = (typeof transition.to === 'string')
? transition.to
: (transition.intent
? transition.intent.url
: '');
if (destinationUrl?.includes('/pro')) {
isBillingTransition = true;
}
}
this.billing.toggleProWindow(isBillingTransition);
}
buildRouteInfoMetadata() {
return {
titleToken: 'Ghost(Pro)'
};
}
}