2020-07-30 16:12:44 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-07-30 16:12:44 +03:00
|
|
|
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {action, computed} from '@ember/object';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2020-07-30 16:12:44 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-01 12:34:03 +03:00
|
|
|
import {tagName} from '@ember-decorators/component';
|
2020-07-30 16:12:44 +03:00
|
|
|
import {task, timeout} from 'ember-concurrency';
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class GhPortalLinks extends Component {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service store;
|
|
|
|
@service settings;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
2022-11-03 14:14:36 +03:00
|
|
|
@inject config;
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
isLink = true;
|
|
|
|
prices = null;
|
|
|
|
copiedPrice = null;
|
|
|
|
copiedSignupInterval = null;
|
2022-05-11 20:11:54 +03:00
|
|
|
selectedTier = null;
|
|
|
|
tiers = null;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@computed('isLink')
|
|
|
|
get toggleValue() {
|
2020-08-26 18:10:19 +03:00
|
|
|
return this.isLink ? 'Data attributes' : 'Links';
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('isLink')
|
|
|
|
get sectionHeaderLabel() {
|
2020-08-26 18:10:19 +03:00
|
|
|
return this.isLink ? 'Link' : 'Data attribute';
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
@computed('selectedTier')
|
|
|
|
get selectedTierIdPath() {
|
|
|
|
const selectedTier = this.selectedTier;
|
|
|
|
if (selectedTier) {
|
|
|
|
return `/${selectedTier.name}`;
|
2021-06-29 21:49:25 +03:00
|
|
|
}
|
|
|
|
return '';
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-06-29 21:49:25 +03:00
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
@computed('tiers.[]')
|
|
|
|
get tierOptions() {
|
|
|
|
if (this.tiers) {
|
|
|
|
return this.tiers.map((tier) => {
|
2021-06-29 21:49:25 +03:00
|
|
|
return {
|
2022-05-11 20:11:54 +03:00
|
|
|
label: tier.name,
|
|
|
|
name: tier.id
|
2021-06-29 21:49:25 +03:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
|
2022-11-03 14:14:36 +03:00
|
|
|
get siteUrl() {
|
|
|
|
return this.config.blogUrl;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
toggleShowLinks() {
|
|
|
|
this.toggleProperty('isLink');
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-05-11 20:11:54 +03:00
|
|
|
setSelectedTier(tier) {
|
|
|
|
this.set('selectedTier', tier);
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@task(function* () {
|
2022-09-06 12:25:19 +03:00
|
|
|
const tiers = yield this.store.query('tier', {filter: 'type:paid+active:true', include: 'monthly_price,yearly_price'}) || [];
|
2022-05-11 20:11:54 +03:00
|
|
|
this.set('tiers', tiers);
|
|
|
|
if (tiers.length > 0) {
|
|
|
|
this.set('selectedTier', {
|
|
|
|
name: tiers.firstObject.id,
|
|
|
|
label: tiers.firstObject.name
|
2021-06-29 21:49:25 +03:00
|
|
|
});
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
2022-05-11 20:11:54 +03:00
|
|
|
fetchTiers;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@task(function* (id) {
|
2021-05-07 19:37:42 +03:00
|
|
|
this.set('copiedPrice', id);
|
|
|
|
let data = '';
|
|
|
|
if (this.isLink) {
|
|
|
|
data = id ? `#/portal/${id}` : `#/portal/`;
|
2022-02-22 16:00:36 +03:00
|
|
|
data = this.siteUrl + `/` + data;
|
2021-05-07 19:37:42 +03:00
|
|
|
} else {
|
|
|
|
data = id ? `data-portal="${id}"` : `data-portal`;
|
|
|
|
}
|
2020-07-30 16:12:44 +03:00
|
|
|
copyTextToClipboard(data);
|
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
2022-02-10 13:41:36 +03:00
|
|
|
copyStaticLink;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
@task(function* (interval) {
|
2021-06-29 21:49:25 +03:00
|
|
|
this.set('copiedSignupInterval', interval);
|
2021-05-07 19:37:42 +03:00
|
|
|
let data = '';
|
|
|
|
if (this.isLink) {
|
2022-05-11 20:11:54 +03:00
|
|
|
data = `#/portal/signup${this.selectedTierIdPath}/${interval}`;
|
2022-02-22 16:00:36 +03:00
|
|
|
data = this.siteUrl + `/` + data;
|
2021-05-07 19:37:42 +03:00
|
|
|
} else {
|
2022-05-11 20:11:54 +03:00
|
|
|
data = `data-portal="signup${this.selectedTierIdPath}/${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
|
|
|
})
|
2022-05-11 20:11:54 +03:00
|
|
|
copyTierSignupLink;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|