2020-07-30 16:12:44 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task, timeout} from 'ember-concurrency';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
config: service(),
|
2021-05-07 19:37:42 +03:00
|
|
|
store: service(),
|
|
|
|
settings: service(),
|
2020-07-30 16:12:44 +03:00
|
|
|
tagName: '',
|
|
|
|
isLink: true,
|
2021-05-07 19:37:42 +03:00
|
|
|
prices: null,
|
|
|
|
copiedPrice: null,
|
|
|
|
|
|
|
|
filteredPrices: computed('prices', 'settings.portalPlans.[]', function () {
|
|
|
|
const portalPlans = this.get('settings.portalPlans');
|
2021-05-18 19:35:29 +03:00
|
|
|
const monthlyPriceId = this.settings.get('membersMonthlyPriceId');
|
|
|
|
const yearlyPriceId = this.settings.get('membersYearlyPriceId');
|
2021-05-07 19:37:42 +03:00
|
|
|
const prices = this.prices || [];
|
|
|
|
return prices.filter((d) => {
|
2021-05-18 19:35:29 +03:00
|
|
|
return [monthlyPriceId, yearlyPriceId].includes(d.id);
|
|
|
|
}).filter((d) => {
|
2021-05-07 19:37:42 +03:00
|
|
|
return d.amount !== 0 && d.type === 'recurring';
|
|
|
|
}).map((price) => {
|
|
|
|
return {
|
|
|
|
...price,
|
2021-05-18 19:35:29 +03:00
|
|
|
oldId: price.interval === 'month' ? 'monthly' : 'yearly',
|
|
|
|
oldNickname: price.interval === 'month' ? 'Monthly' : 'Yearly',
|
2021-05-07 19:37:42 +03:00
|
|
|
checked: !!portalPlans.find(d => d === price.id)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}),
|
2020-07-30 16:12:44 +03:00
|
|
|
|
|
|
|
toggleValue: computed('isLink', function () {
|
2020-08-26 18:10:19 +03:00
|
|
|
return this.isLink ? 'Data attributes' : 'Links';
|
2020-07-30 16:12:44 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
sectionHeaderLabel: computed('isLink', function () {
|
2020-08-26 18:10:19 +03:00
|
|
|
return this.isLink ? 'Link' : 'Data attribute';
|
2020-07-30 16:12:44 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.siteUrl = this.config.get('blogUrl');
|
2021-05-07 19:37:42 +03:00
|
|
|
this.getAvailablePrices.perform();
|
2020-07-30 16:12:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleShowLinks() {
|
|
|
|
this.toggleProperty('isLink');
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 19:37:42 +03:00
|
|
|
copyStaticLink: task(function* (id) {
|
|
|
|
this.set('copiedPrice', id);
|
|
|
|
let data = '';
|
|
|
|
if (this.isLink) {
|
|
|
|
data = id ? `#/portal/${id}` : `#/portal/`;
|
|
|
|
} else {
|
|
|
|
data = id ? `data-portal="${id}"` : `data-portal`;
|
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
copyTextToClipboard(data);
|
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
|
|
|
}),
|
2021-05-07 19:37:42 +03:00
|
|
|
copySignupLink: task(function* (price) {
|
|
|
|
this.set('copiedPrice', price.id);
|
|
|
|
let data = '';
|
|
|
|
if (this.isLink) {
|
2021-05-07 20:29:59 +03:00
|
|
|
data = `#/portal/signup/${price.id}`;
|
2021-05-07 19:37:42 +03:00
|
|
|
} else {
|
2021-05-07 20:29:59 +03:00
|
|
|
data = `data-portal="signup/${price.id}"`;
|
2021-05-07 19:37:42 +03:00
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
copyTextToClipboard(data);
|
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
|
|
|
}),
|
2021-05-07 19:37:42 +03:00
|
|
|
getAvailablePrices: task(function* () {
|
|
|
|
const products = yield this.store.query('product', {include: 'stripe_prices'});
|
|
|
|
const product = products.firstObject;
|
|
|
|
const prices = product.get('stripePrices');
|
|
|
|
const activePrices = prices.filter((d) => {
|
|
|
|
return !!d.active;
|
|
|
|
});
|
|
|
|
this.set('prices', activePrices);
|
|
|
|
}).drop()
|
2020-07-30 16:12:44 +03:00
|
|
|
});
|