mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
2a6d7226d2
refs https://github.com/TryGhost/Team/issues/644 Updates site setup to create custom Monthly/Yearly prices in default product as part of launch wizard. Also updates available portal plans based on user selection.
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {htmlSafe} from '@ember/string';
|
|
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() {
|
|
// clear any unsaved settings changes when going back/forward/closing
|
|
this.settings.rollbackAttributes();
|
|
}
|
|
|
|
@task
|
|
*finaliseTask() {
|
|
const data = this.args.getData();
|
|
if (data && data.product) {
|
|
const updatedProduct = yield data.product.save();
|
|
const monthlyPrice = updatedProduct.get('stripePrices').find(d => d.nickname === 'Monthly');
|
|
const yearlyPrice = updatedProduct.get('stripePrices').find(d => d.nickname === 'Yearly');
|
|
const portalPlans = this.settings.get('portalPlans') || [];
|
|
let allowedPlans = [...portalPlans];
|
|
if (data.isMonthlyChecked && monthlyPrice) {
|
|
allowedPlans.push(monthlyPrice.id);
|
|
}
|
|
|
|
if (data.isYearlyChecked && yearlyPrice) {
|
|
allowedPlans.push(yearlyPrice.id);
|
|
}
|
|
this.settings.set('portalPlans', allowedPlans);
|
|
yield this.settings.save();
|
|
}
|
|
yield this.feature.set('launchComplete', true);
|
|
this.router.transitionTo('dashboard');
|
|
this.notifications.showNotification(
|
|
'Launch complete!',
|
|
{type: 'success', actions: htmlSafe('<a href="#/posts">Start creating content</a>')}
|
|
);
|
|
}
|
|
}
|