2021-02-04 21:35:19 +03:00
|
|
|
import Component from '@glimmer/component';
|
2021-05-12 14:33:36 +03:00
|
|
|
import {htmlSafe} from '@ember/template';
|
2021-02-04 21:35:19 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task} from 'ember-concurrency-decorators';
|
|
|
|
|
|
|
|
export default class GhLaunchWizardFinaliseComponent extends Component {
|
|
|
|
@service feature;
|
2021-02-23 13:18:37 +03:00
|
|
|
@service notifications;
|
2021-02-04 21:35:19 +03:00
|
|
|
@service router;
|
2021-05-04 18:47:50 +03:00
|
|
|
@service settings;
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
// clear any unsaved settings changes when going back/forward/closing
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
}
|
2021-02-04 21:35:19 +03:00
|
|
|
|
2021-05-20 14:30:52 +03:00
|
|
|
async saveProduct() {
|
2021-05-04 18:47:50 +03:00
|
|
|
const data = this.args.getData();
|
2021-05-20 14:30:52 +03:00
|
|
|
this.product = data?.product;
|
|
|
|
if (this.product) {
|
|
|
|
const monthlyAmount = data.monthlyAmount * 100;
|
|
|
|
const yearlyAmount = data.yearlyAmount * 100;
|
|
|
|
const currency = data.currency;
|
2021-06-04 10:52:20 +03:00
|
|
|
const monthlyPrice = {
|
|
|
|
nickname: 'Monthly',
|
|
|
|
amount: monthlyAmount,
|
|
|
|
active: 1,
|
|
|
|
currency: currency,
|
|
|
|
interval: 'month',
|
|
|
|
type: 'recurring'
|
2021-05-20 14:30:52 +03:00
|
|
|
};
|
2021-06-04 10:52:20 +03:00
|
|
|
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;
|
2021-05-20 14:30:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*finaliseTask() {
|
|
|
|
const data = this.args.getData();
|
|
|
|
if (data?.product) {
|
|
|
|
yield this.saveProduct();
|
2021-05-04 18:47:50 +03:00
|
|
|
yield this.settings.save();
|
|
|
|
}
|
2021-02-04 21:35:19 +03:00
|
|
|
yield this.feature.set('launchComplete', true);
|
|
|
|
this.router.transitionTo('dashboard');
|
2021-02-23 13:18:37 +03:00
|
|
|
this.notifications.showNotification(
|
|
|
|
'Launch complete!',
|
|
|
|
{type: 'success', actions: htmlSafe('<a href="#/posts">Start creating content</a>')}
|
|
|
|
);
|
2021-02-04 21:35:19 +03:00
|
|
|
}
|
2021-02-23 13:18:37 +03:00
|
|
|
}
|