@ducna01120/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
64 lines (53 loc) • 1.64 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class SettingsWindowComponent extends Component {
currentUser;
store;
notifications;
intl;
isSaving = false;
isLoading = false;
company;
onLoad() {
if (typeof this.args.onLoad === 'function') {
this.args.onLoad(...arguments);
}
this.fetchCurrentCompany();
}
fetchCurrentCompany() {
this.isLoading = true;
this.store
.findRecord('company', this.currentUser.companyId)
.then((company) => {
company.options = this.createDefaultSettings(company.options);
this.company = company;
})
.finally(() => {
this.isLoading = false;
});
}
createDefaultSettings(settings) {
if (!settings) {
settings = {
fleetops: {
adhoc_distance: 6000,
},
storefront: {},
};
}
return settings;
}
saveSettings() {
this.isSaving = true;
return this.company
.save()
.then(() => {
this.notifications.success(this.intl.t('fleet-ops.component.settings-window.success-message'));
})
.finally(() => {
this.isSaving = false;
});
}
}