From 4e128a0bd0c33a650ebbf68fc3ae4942524a2346 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 19 Oct 2021 00:19:14 +0530 Subject: [PATCH] Updated repeating duration offer for monthly cadence only closes https://github.com/TryGhost/Team/issues/1126 - Offer duration can only allow multiple months for the monthly Cadence --- ghost/admin/app/controllers/offer.js | 45 ++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/controllers/offer.js b/ghost/admin/app/controllers/offer.js index 286897c444..5adbe5011a 100644 --- a/ghost/admin/app/controllers/offer.js +++ b/ghost/admin/app/controllers/offer.js @@ -118,19 +118,21 @@ export default class OffersController extends Controller { }); this.cadences = cadences; const defaultCadence = this.cadences[0]?.name; + const [,interval, defaultCurrency] = (defaultCadence || '').split('-'); + + this.updateDurations(interval); if (this.offer && !this.offer.tier) { this.defaultProps = {}; - this.updateCadence(this.cadences[0]?.name, this.defaultProps); + this.updateCadence(defaultCadence, this.defaultProps); this.updatePortalPreview({forceRefresh: false}); } else if (defaultCadence) { - const [,, currency] = (defaultCadence || '').split('-'); this.offertypes = [ { label: '%', offertype: 'percent' }, { - label: currency.toUpperCase(), + label: defaultCurrency.toUpperCase(), offertype: 'fixed' } ]; @@ -370,6 +372,42 @@ export default class OffersController extends Controller { return this.displayCurrency.length; } + @action + updateDurations(cadence) { + if (cadence) { + if (cadence === 'month') { + this.durations = [ + { + label: 'Once', + duration: 'once' + }, + { + label: 'Forever', + duration: 'forever' + }, + { + label: 'Multiple months', + duration: 'repeating' + } + ]; + } else { + this.durations = [ + { + label: 'Forever', + duration: 'forever' + }, + { + label: 'Once', + duration: 'once' + } + ]; + if (this.offer.duration === 'repeating') { + this._saveOfferProperty('duration', 'once'); + } + } + } + } + @action updateCadence(cadence, offerObj) { offerObj = offerObj || this.offer; @@ -390,6 +428,7 @@ export default class OffersController extends Controller { offertype: 'fixed' } ]; + this.updateDurations(tierCadence); this.updatePortalPreview({forceRefresh: false}); } }