Ghost/ghost/admin/app/components/gh-launch-wizard/finalise.js
Rishabh Garg 208b4948ff Moved launch complete flag to new editor setting (#2135)
refs https://github.com/TryGhost/Team/issues/807
refs https://github.com/TryGhost/Ghost/pull/13703

The launch wizard completed flag was previously stored at per user level in accessibility column of user table, so an administrator still got the option to complete the launch wizard even if the owner had completed it previously, which is not expected pattern. This change moves the launch complete flag to be stored in new global setting for site.
2021-11-04 18:04:39 +05:30

63 lines
2.0 KiB
JavaScript

import Component from '@glimmer/component';
import {htmlSafe} from '@ember/template';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
export default class GhLaunchWizardFinaliseComponent extends Component {
@service feature;
@service notifications;
@service router;
@service settings;
willDestroy() {
super.willDestroy?.(...arguments);
// clear any unsaved settings changes when going back/forward/closing
this.settings.rollbackAttributes();
}
async saveProduct() {
const data = this.args.getData();
this.product = data?.product;
if (this.product) {
const monthlyAmount = data.monthlyAmount * 100;
const yearlyAmount = data.yearlyAmount * 100;
const currency = data.currency;
const monthlyPrice = {
nickname: 'Monthly',
amount: monthlyAmount,
active: 1,
currency: currency,
interval: 'month',
type: 'recurring'
};
const yearlyPrice = {
nickname: 'Yearly',
amount: yearlyAmount,
active: 1,
currency: currency,
interval: 'year',
type: 'recurring'
};
this.product.set('monthlyPrice', monthlyPrice);
this.product.set('yearlyPrice', yearlyPrice);
const savedProduct = await this.product.save();
return savedProduct;
}
}
@task
*finaliseTask() {
const data = this.args.getData();
if (data?.product) {
yield this.saveProduct();
this.settings.set('editorIsLaunchComplete', true);
yield this.settings.save();
}
this.router.transitionTo('dashboard');
this.notifications.showNotification(
'Launch complete!',
{type: 'success', actions: htmlSafe('<a href="#/posts">Start creating content</a>')}
);
}
}