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,
|
2021-06-29 21:49:25 +03:00
|
|
|
copiedSignupInterval: null,
|
|
|
|
selectedProduct: null,
|
|
|
|
products: null,
|
2021-05-07 19:37:42 +03:00
|
|
|
|
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
|
|
|
}),
|
2021-06-29 21:49:25 +03:00
|
|
|
selectedProductIdPath: computed('selectedProduct', function () {
|
2022-01-21 22:25:47 +03:00
|
|
|
const selectedProduct = this.selectedProduct;
|
2021-06-29 21:49:25 +03:00
|
|
|
if (selectedProduct) {
|
|
|
|
return `/${selectedProduct.name}`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}),
|
|
|
|
|
|
|
|
productOptions: computed('products.[]', function () {
|
2022-01-21 22:25:47 +03:00
|
|
|
if (this.products) {
|
|
|
|
return this.products.map((product) => {
|
2021-06-29 21:49:25 +03:00
|
|
|
return {
|
|
|
|
label: product.name,
|
|
|
|
name: product.id
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}),
|
2020-07-30 16:12:44 +03:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.siteUrl = this.config.get('blogUrl');
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleShowLinks() {
|
|
|
|
this.toggleProperty('isLink');
|
2021-06-29 21:49:25 +03:00
|
|
|
},
|
|
|
|
setSelectedProduct(product) {
|
|
|
|
this.set('selectedProduct', product);
|
2020-07-30 16:12:44 +03:00
|
|
|
}
|
|
|
|
},
|
2021-06-29 21:49:25 +03:00
|
|
|
fetchProducts: task(function* () {
|
2022-01-17 21:53:43 +03:00
|
|
|
const products = yield this.store.query('product', {filter: 'type:paid', include: 'monthly_price,yearly_price'}) || [];
|
2021-06-29 21:49:25 +03:00
|
|
|
this.set('products', products);
|
|
|
|
if (products.length > 0) {
|
|
|
|
this.set('selectedProduct', {
|
|
|
|
name: products.firstObject.id,
|
|
|
|
label: products.firstObject.name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
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-06-29 21:49:25 +03:00
|
|
|
copyProductSignupLink: task(function* (interval) {
|
|
|
|
this.set('copiedSignupInterval', interval);
|
2021-05-07 19:37:42 +03:00
|
|
|
let data = '';
|
|
|
|
if (this.isLink) {
|
2021-06-29 21:49:25 +03:00
|
|
|
data = `#/portal/signup${this.selectedProductIdPath}/${interval}`;
|
2021-05-07 19:37:42 +03:00
|
|
|
} else {
|
2021-06-29 21:49:25 +03:00
|
|
|
data = `data-portal="signup${this.selectedProductIdPath}/${interval}"`;
|
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-06-04 10:47:17 +03:00
|
|
|
})
|
2020-07-30 16:12:44 +03:00
|
|
|
});
|