2022-03-14 13:52:04 +03:00
|
|
|
import ArchiveOfferModal from '../components/modals/offers/archive';
|
2021-10-06 17:29:15 +03:00
|
|
|
import Controller, {inject as controller} from '@ember/controller';
|
2022-03-14 13:52:04 +03:00
|
|
|
import UnarchiveOfferModal from '../components/modals/offers/unarchive';
|
2021-10-07 23:13:59 +03:00
|
|
|
import config from 'ghost-admin/config/environment';
|
|
|
|
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
|
2021-10-04 14:01:12 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-10-06 18:11:35 +03:00
|
|
|
import {getSymbol} from 'ghost-admin/utils/currency';
|
|
|
|
import {ghPriceAmount} from '../helpers/gh-price-amount';
|
2021-10-04 16:00:41 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-11 11:03:30 +03:00
|
|
|
import {slugify} from '@tryghost/string';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-10-07 23:13:59 +03:00
|
|
|
import {timeout} from 'ember-concurrency';
|
2021-10-04 16:00:41 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-10-04 14:01:12 +03:00
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
export default class OffersController extends Controller {
|
|
|
|
@controller offers;
|
2021-10-04 16:00:41 +03:00
|
|
|
@service config;
|
|
|
|
@service settings;
|
|
|
|
@service store;
|
2021-10-13 18:46:43 +03:00
|
|
|
@service modals;
|
2021-10-21 20:29:16 +03:00
|
|
|
@service feature;
|
2021-10-18 12:01:29 +03:00
|
|
|
@service membersUtils;
|
2021-10-06 17:29:15 +03:00
|
|
|
@service notifications;
|
|
|
|
|
2021-10-04 16:00:41 +03:00
|
|
|
@tracked cadences = [];
|
|
|
|
@tracked products = [];
|
2021-10-18 12:01:29 +03:00
|
|
|
@tracked portalPreviewUrl = '';
|
2021-10-07 23:13:59 +03:00
|
|
|
@tracked showUnsavedChangesModal = false;
|
|
|
|
|
2021-10-19 16:57:33 +03:00
|
|
|
@tracked defaultSiteUrl = this.config.get('blogUrl');
|
|
|
|
|
2021-10-05 15:34:19 +03:00
|
|
|
@tracked durations = [
|
|
|
|
{
|
|
|
|
label: 'Forever',
|
|
|
|
duration: 'forever'
|
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'First-payment',
|
2021-10-05 15:34:19 +03:00
|
|
|
duration: 'once'
|
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'Multiple-months',
|
2021-10-07 23:13:59 +03:00
|
|
|
duration: 'repeating'
|
2021-10-05 15:34:19 +03:00
|
|
|
}
|
|
|
|
];
|
2021-10-04 16:00:41 +03:00
|
|
|
|
2021-10-08 13:48:41 +03:00
|
|
|
@tracked offertypes = [
|
|
|
|
{
|
|
|
|
label: '%',
|
|
|
|
offertype: 'percent'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'USD',
|
|
|
|
offertype: 'fixed'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-10-11 11:03:30 +03:00
|
|
|
@tracked defaultProps = null;
|
2021-10-22 13:18:57 +03:00
|
|
|
@tracked isDisplayTitleEdited = false;
|
2021-10-11 11:03:30 +03:00
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
leaveScreenTransition = null;
|
2021-10-18 12:01:29 +03:00
|
|
|
portalPreviewGuid = Date.now().valueOf();
|
2021-10-06 17:29:15 +03:00
|
|
|
|
2021-10-04 16:00:41 +03:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2021-10-07 23:13:59 +03:00
|
|
|
if (this.isTesting === undefined) {
|
|
|
|
this.isTesting = config.environment === 'test';
|
|
|
|
}
|
2021-10-04 16:00:41 +03:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
get offer() {
|
|
|
|
return this.model;
|
|
|
|
}
|
|
|
|
|
|
|
|
set offer(offer) {
|
|
|
|
this.model = offer;
|
|
|
|
}
|
|
|
|
|
|
|
|
get scratchOffer() {
|
|
|
|
return {
|
|
|
|
...this.offer
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get cadence() {
|
|
|
|
if (this.offer.tier && this.offer.cadence) {
|
2021-10-15 10:04:35 +03:00
|
|
|
const product = this.products.findBy('id', this.offer.tier.id);
|
|
|
|
return `${this.offer.tier.id}-${this.offer.cadence}-${product?.monthlyPrice?.currency}`;
|
2021-10-11 11:03:30 +03:00
|
|
|
} else if (this.defaultProps) {
|
2021-10-15 10:04:35 +03:00
|
|
|
const product = this.products.findBy('id', this.defaultProps.tier.id);
|
|
|
|
return `${this.defaultProps.tier.id}-${this.defaultProps.cadence}-${product?.monthlyPrice?.currency}`;
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2021-10-07 23:13:59 +03:00
|
|
|
get isDiscountSectionDisabled() {
|
|
|
|
return !this.offer.isNew;
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
// Tasks -------------------------------------------------------------------
|
|
|
|
|
2021-10-04 16:00:41 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*fetchProducts() {
|
2022-03-24 12:26:44 +03:00
|
|
|
this.products = yield this.store.query('product', {filter: 'type:paid+active:true', include: 'monthly_price,yearly_price'});
|
2021-12-01 15:15:55 +03:00
|
|
|
this.products = this.products.filter((d) => {
|
|
|
|
return d.monthlyPrice && d.yearlyPrice;
|
|
|
|
});
|
2021-10-07 23:13:59 +03:00
|
|
|
const cadences = [];
|
2021-10-04 16:00:41 +03:00
|
|
|
this.products.forEach((product) => {
|
2021-10-07 23:13:59 +03:00
|
|
|
let monthlyLabel;
|
|
|
|
let yearlyLabel;
|
|
|
|
const productCurrency = product.monthlyPrice.currency;
|
2021-10-08 13:48:41 +03:00
|
|
|
const productCurrencySymbol = productCurrency.toUpperCase();
|
2021-10-21 20:29:16 +03:00
|
|
|
if (this.feature.get('multipleProducts')) {
|
|
|
|
monthlyLabel = `${product.name} - Monthly (${ghPriceAmount(product.monthlyPrice.amount)} ${productCurrencySymbol})`;
|
|
|
|
yearlyLabel = `${product.name} - Yearly (${ghPriceAmount(product.yearlyPrice.amount)} ${productCurrencySymbol})`;
|
|
|
|
} else {
|
|
|
|
monthlyLabel = `Monthly (${ghPriceAmount(product.monthlyPrice.amount)} ${productCurrencySymbol})`;
|
|
|
|
yearlyLabel = `Yearly (${ghPriceAmount(product.yearlyPrice.amount)} ${productCurrencySymbol})`;
|
|
|
|
}
|
2021-10-07 23:13:59 +03:00
|
|
|
|
2021-10-06 18:49:45 +03:00
|
|
|
cadences.push({
|
2021-10-07 23:13:59 +03:00
|
|
|
label: monthlyLabel,
|
|
|
|
name: `${product.id}-month-${productCurrency}`
|
2021-10-06 18:49:45 +03:00
|
|
|
});
|
2021-10-06 18:11:35 +03:00
|
|
|
|
2021-10-06 18:49:45 +03:00
|
|
|
cadences.push({
|
2021-10-07 23:13:59 +03:00
|
|
|
label: yearlyLabel,
|
|
|
|
name: `${product.id}-year-${productCurrency}`
|
2021-10-06 18:49:45 +03:00
|
|
|
});
|
2021-10-04 16:00:41 +03:00
|
|
|
});
|
|
|
|
this.cadences = cadences;
|
2021-10-18 12:01:29 +03:00
|
|
|
const defaultCadence = this.cadences[0]?.name;
|
2021-10-18 21:49:14 +03:00
|
|
|
const [,interval, defaultCurrency] = (defaultCadence || '').split('-');
|
|
|
|
|
|
|
|
this.updateDurations(interval);
|
2021-10-07 23:13:59 +03:00
|
|
|
if (this.offer && !this.offer.tier) {
|
2021-10-11 11:03:30 +03:00
|
|
|
this.defaultProps = {};
|
2021-10-18 21:49:14 +03:00
|
|
|
this.updateCadence(defaultCadence, this.defaultProps);
|
2021-10-18 12:01:29 +03:00
|
|
|
this.updatePortalPreview({forceRefresh: false});
|
|
|
|
} else if (defaultCadence) {
|
|
|
|
this.offertypes = [
|
|
|
|
{
|
|
|
|
label: '%',
|
|
|
|
offertype: 'percent'
|
|
|
|
},
|
|
|
|
{
|
2021-10-18 21:49:14 +03:00
|
|
|
label: defaultCurrency.toUpperCase(),
|
2021-10-18 12:01:29 +03:00
|
|
|
offertype: 'fixed'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
this.updatePortalPreview({forceRefresh: false});
|
2021-10-07 23:13:59 +03:00
|
|
|
}
|
2021-10-04 16:00:41 +03:00
|
|
|
}
|
|
|
|
|
2021-10-07 23:13:59 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*copyOfferUrl() {
|
|
|
|
copyTextToClipboard(this.offerUrl);
|
|
|
|
yield timeout(this.isTesting ? 50 : 500);
|
2021-10-05 16:03:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
@task({drop: true})
|
|
|
|
*saveTask() {
|
|
|
|
let {offer} = this;
|
|
|
|
|
2021-10-11 11:03:30 +03:00
|
|
|
if (!offer.tier && this.defaultProps) {
|
|
|
|
this.offer.tier = {
|
|
|
|
id: this.defaultProps?.tier.id
|
|
|
|
};
|
|
|
|
this.offer.cadence = this.defaultProps.cadence;
|
|
|
|
this.offer.currency = this.defaultProps.currency;
|
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
|
|
|
|
try {
|
2021-10-19 10:35:18 +03:00
|
|
|
yield this.offer.validate();
|
2021-10-06 17:29:15 +03:00
|
|
|
yield offer.save();
|
|
|
|
|
|
|
|
// replace 'offer.new' route with 'offer' route
|
|
|
|
this.replaceRoute('offer', offer);
|
|
|
|
|
|
|
|
return offer;
|
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'offer.save'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@task
|
|
|
|
*fetchOfferTask(offerId) {
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
this.offer = yield this.store.queryRecord('offer', {
|
|
|
|
id: offerId
|
|
|
|
});
|
|
|
|
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
|
2021-10-18 12:01:29 +03:00
|
|
|
@action
|
2021-10-18 15:24:22 +03:00
|
|
|
portalPreviewInserted(iframe) {
|
|
|
|
this.portalPreviewIframe = iframe;
|
|
|
|
|
|
|
|
if (!this.portalMessageListener) {
|
|
|
|
this.portalMessageListener = (event) => {
|
|
|
|
const resizeEvents = ['portal-ready', 'portal-preview-updated'];
|
2022-03-14 13:28:58 +03:00
|
|
|
if (resizeEvents.includes(event.data.type) && event.data.payload?.height && this.portalPreviewIframe?.parentNode) {
|
2021-10-18 15:24:22 +03:00
|
|
|
this.portalPreviewIframe.parentNode.style.height = `${event.data.payload.height}px`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('message', this.portalMessageListener, true);
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 12:01:29 +03:00
|
|
|
|
|
|
|
@action
|
2021-10-18 15:24:22 +03:00
|
|
|
portalPreviewDestroyed() {
|
|
|
|
this.portalPreviewIframe = null;
|
|
|
|
|
|
|
|
if (this.portalMessageListener) {
|
|
|
|
window.removeEventListener('message', this.portalMessageListener);
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 12:01:29 +03:00
|
|
|
|
|
|
|
@action
|
|
|
|
updatePortalPreview({forceRefresh} = {forceRefresh: false}) {
|
|
|
|
const newUrl = new URL(this.membersUtils.getOfferPortalPreviewUrl({
|
|
|
|
name: this.offer.name || 'No Name',
|
|
|
|
code: this.offer.code || 'no-code',
|
|
|
|
displayTitle: this.offer.displayTitle,
|
|
|
|
displayDescription: this.offer.displayDescription,
|
|
|
|
type: this.offer.type,
|
|
|
|
cadence: this.offer.cadence || this.defaultProps?.cadence,
|
|
|
|
amount: this.offer.amount,
|
|
|
|
duration: this.offer.duration,
|
2021-10-21 23:19:48 +03:00
|
|
|
durationInMonths: this.offer.durationInMonths,
|
2021-10-18 12:01:29 +03:00
|
|
|
currency: this.offer.currency || this.defaultProps?.currency,
|
|
|
|
status: this.offer.currency,
|
|
|
|
tierId: this.offer?.tier?.id || this.defaultProps?.tier?.id
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (forceRefresh) {
|
|
|
|
this.portalPreviewGuid = Date.now().valueOf();
|
|
|
|
}
|
|
|
|
newUrl.searchParams.set('v', `${this.portalPreviewGuid}`);
|
|
|
|
|
|
|
|
this.portalPreviewUrl = newUrl;
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
return this.saveTask.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
leaveScreen() {
|
|
|
|
this.offer.rollbackAttributes();
|
|
|
|
return this.leaveScreenTransition.retry();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleUnsavedChangesModal(transition) {
|
|
|
|
let leaveTransition = this.leaveScreenTransition;
|
|
|
|
|
|
|
|
if (!transition && this.showUnsavedChangesModal) {
|
|
|
|
this.leaveScreenTransition = null;
|
|
|
|
this.showUnsavedChangesModal = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
|
|
|
|
this.leaveScreenTransition = transition;
|
|
|
|
|
|
|
|
// if a save is running, wait for it to finish then transition
|
|
|
|
if (this.save.isRunning) {
|
|
|
|
return this.save.last.then(() => {
|
|
|
|
transition.retry();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// we genuinely have unsaved data, show the modal
|
|
|
|
this.showUnsavedChangesModal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 16:00:41 +03:00
|
|
|
@action
|
|
|
|
setup() {
|
|
|
|
this.fetchProducts.perform();
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setProperty(propKey, value) {
|
|
|
|
this._saveOfferProperty(propKey, value);
|
2021-10-04 16:00:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setDiscountType(discountType) {
|
2021-10-07 23:13:59 +03:00
|
|
|
if (!this.isDiscountSectionDisabled) {
|
2021-10-22 07:39:56 +03:00
|
|
|
const amount = this.offer.amount || 0;
|
2021-10-07 23:13:59 +03:00
|
|
|
this._saveOfferProperty('type', discountType);
|
2021-10-18 12:01:29 +03:00
|
|
|
if (this.offer.type === 'fixed' && this.offer.amount !== '') {
|
2021-10-22 07:39:56 +03:00
|
|
|
this.offer.amount = amount * 100;
|
2021-10-18 12:01:29 +03:00
|
|
|
} else if (this.offer.amount !== '') {
|
2021-10-22 07:39:56 +03:00
|
|
|
this.offer.amount = amount / 100;
|
2021-10-18 12:01:29 +03:00
|
|
|
}
|
|
|
|
this.updatePortalPreview({forceRefresh: false});
|
2021-10-07 23:13:59 +03:00
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setDiscountAmount(e) {
|
2021-10-07 23:13:59 +03:00
|
|
|
let amount = e.target.value;
|
|
|
|
if (this.offer.type === 'fixed' && amount !== '') {
|
2021-10-19 10:38:31 +03:00
|
|
|
amount = parseFloat(amount) * 100;
|
2021-10-07 23:13:59 +03:00
|
|
|
}
|
|
|
|
this._saveOfferProperty('amount', amount);
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setOfferName(e) {
|
|
|
|
this._saveOfferProperty('name', e.target.value);
|
2021-10-22 13:18:57 +03:00
|
|
|
if (!this.isDisplayTitleEdited && this.offer.isNew) {
|
|
|
|
this._saveOfferProperty('displayTitle', e.target.value);
|
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setPortalTitle(e) {
|
2021-10-22 13:18:57 +03:00
|
|
|
this.isDisplayTitleEdited = true;
|
2021-10-06 17:29:15 +03:00
|
|
|
this._saveOfferProperty('displayTitle', e.target.value);
|
2021-10-04 16:00:41 +03:00
|
|
|
}
|
|
|
|
|
2021-10-05 15:34:19 +03:00
|
|
|
@action
|
2021-10-06 17:29:15 +03:00
|
|
|
setPortalDescription(e) {
|
|
|
|
this._saveOfferProperty('displayDescription', e.target.value);
|
2021-10-05 15:34:19 +03:00
|
|
|
}
|
|
|
|
|
2021-10-04 14:01:12 +03:00
|
|
|
@action
|
2021-10-06 17:29:15 +03:00
|
|
|
setOfferCode(e) {
|
|
|
|
this._saveOfferProperty('code', e.target.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setDurationInMonths(e) {
|
|
|
|
this._saveOfferProperty('durationInMonths', e.target.value);
|
2021-10-07 23:13:59 +03:00
|
|
|
}
|
|
|
|
|
2021-10-13 18:46:43 +03:00
|
|
|
@action
|
|
|
|
openConfirmArchiveModal() {
|
|
|
|
if (!this.offer.isNew) {
|
2022-03-14 13:52:04 +03:00
|
|
|
this.modals.open(ArchiveOfferModal, {
|
2021-10-13 18:46:43 +03:00
|
|
|
offer: this.offer
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
openConfirmUnarchiveModal() {
|
|
|
|
if (!this.offer.isNew) {
|
2022-03-14 13:52:04 +03:00
|
|
|
this.modals.open(UnarchiveOfferModal, {
|
2021-10-13 18:46:43 +03:00
|
|
|
offer: this.offer
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 23:13:59 +03:00
|
|
|
get offerUrl() {
|
|
|
|
const code = this.offer?.code || '';
|
|
|
|
if (code) {
|
|
|
|
const siteUrl = this.config.get('blogUrl');
|
2021-10-11 11:03:30 +03:00
|
|
|
return `${siteUrl}/${slugify(code)}`;
|
2021-10-07 23:13:59 +03:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
get displayCurrency() {
|
|
|
|
const tierId = this.offer?.tier?.id;
|
|
|
|
if (!tierId) {
|
|
|
|
return '$';
|
|
|
|
}
|
|
|
|
const product = this.products.findBy('id', tierId);
|
|
|
|
const productCurrency = product?.monthlyPrice?.currency || 'usd';
|
|
|
|
return getSymbol(productCurrency);
|
|
|
|
}
|
|
|
|
|
|
|
|
get currencyLength() {
|
|
|
|
return this.displayCurrency.length;
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:49:14 +03:00
|
|
|
@action
|
|
|
|
updateDurations(cadence) {
|
|
|
|
if (cadence) {
|
|
|
|
if (cadence === 'month') {
|
|
|
|
this.durations = [
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'First-payment',
|
2021-10-18 21:49:14 +03:00
|
|
|
duration: 'once'
|
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'Multiple-months',
|
|
|
|
duration: 'repeating'
|
2021-10-18 21:49:14 +03:00
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'Forever',
|
|
|
|
duration: 'forever'
|
2021-10-18 21:49:14 +03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
this.durations = [
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'First-payment',
|
|
|
|
duration: 'once'
|
2021-10-18 21:49:14 +03:00
|
|
|
},
|
|
|
|
{
|
2021-10-22 12:04:31 +03:00
|
|
|
label: 'Forever',
|
|
|
|
duration: 'forever'
|
2021-10-18 21:49:14 +03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
if (this.offer.duration === 'repeating') {
|
|
|
|
this._saveOfferProperty('duration', 'once');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:15 +03:00
|
|
|
@action
|
2021-10-11 11:03:30 +03:00
|
|
|
updateCadence(cadence, offerObj) {
|
|
|
|
offerObj = offerObj || this.offer;
|
2021-10-08 17:15:48 +03:00
|
|
|
if (cadence) {
|
|
|
|
const [tierId, tierCadence, currency] = cadence.split('-');
|
2021-10-11 11:03:30 +03:00
|
|
|
offerObj.tier = {
|
2021-10-08 17:15:48 +03:00
|
|
|
id: tierId
|
|
|
|
};
|
2021-10-11 11:03:30 +03:00
|
|
|
offerObj.cadence = tierCadence;
|
|
|
|
offerObj.currency = currency;
|
2021-10-08 17:15:48 +03:00
|
|
|
this.offertypes = [
|
|
|
|
{
|
|
|
|
label: '%',
|
|
|
|
offertype: 'percent'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: currency.toUpperCase(),
|
|
|
|
offertype: 'fixed'
|
|
|
|
}
|
|
|
|
];
|
2021-10-18 21:49:14 +03:00
|
|
|
this.updateDurations(tierCadence);
|
2021-10-18 12:01:29 +03:00
|
|
|
this.updatePortalPreview({forceRefresh: false});
|
2021-10-08 17:15:48 +03:00
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateDuration(duration) {
|
|
|
|
this._saveOfferProperty('duration', duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private -----------------------------------------------------------------
|
|
|
|
|
|
|
|
_saveOfferProperty(propKey, newValue) {
|
|
|
|
let currentValue = this.offer[propKey];
|
|
|
|
|
|
|
|
// avoid modifying empty values and triggering inadvertant unsaved changes modals
|
|
|
|
if (newValue !== false && !newValue && !currentValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.offer[propKey] = newValue;
|
2021-10-18 12:01:29 +03:00
|
|
|
this.updatePortalPreview({forceRefresh: false});
|
2021-10-04 16:00:41 +03:00
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|