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';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-02-04 21:35:19 +03:00
|
|
|
|
|
|
|
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() {
|
2021-07-15 17:27:29 +03:00
|
|
|
super.willDestroy?.(...arguments);
|
2021-05-04 18:47:50 +03:00
|
|
|
// clear any unsaved settings changes when going back/forward/closing
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
}
|
2021-02-04 21:35:19 +03:00
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
async saveTier() {
|
2021-05-04 18:47:50 +03:00
|
|
|
const data = this.args.getData();
|
2022-05-11 20:11:54 +03:00
|
|
|
this.tier = data?.tier;
|
|
|
|
if (this.tier) {
|
2022-03-04 12:18:45 +03:00
|
|
|
const monthlyAmount = Math.round(data.monthlyAmount * 100);
|
|
|
|
const yearlyAmount = Math.round(data.yearlyAmount * 100);
|
2021-05-20 14:30:52 +03:00
|
|
|
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'
|
|
|
|
};
|
2022-05-11 20:11:54 +03:00
|
|
|
this.tier.set('monthlyPrice', monthlyPrice);
|
|
|
|
this.tier.set('yearlyPrice', yearlyPrice);
|
|
|
|
const savedTier = await this.tier.save();
|
|
|
|
return savedTier;
|
2021-05-20 14:30:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*finaliseTask() {
|
|
|
|
const data = this.args.getData();
|
2022-05-11 20:11:54 +03:00
|
|
|
if (data?.tier) {
|
|
|
|
yield this.saveTier();
|
2021-11-04 15:34:39 +03:00
|
|
|
this.settings.set('editorIsLaunchComplete', true);
|
2021-05-04 18:47:50 +03:00
|
|
|
yield this.settings.save();
|
|
|
|
}
|
2021-02-04 21:35:19 +03:00
|
|
|
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
|
|
|
}
|