From 148fea821718d3d7b8f61d2a34b93b575de9ee41 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 19 Aug 2022 16:47:55 +0530 Subject: [PATCH] Wired expiring comp subscriptions on Admin refs https://github.com/TryGhost/Team/issues/1727 - adds alpha feature flag for expiring comped subs - adds duration to complimentary subs to set expiry - shows details for expiring comped subs --- .../components/gh-member-settings-form.hbs | 3 ++ .../app/components/gh-member-settings-form.js | 5 ++ .../app/components/modal-member-tier.hbs | 18 +++++++ .../admin/app/components/modal-member-tier.js | 51 +++++++++++++++++-- ghost/admin/app/services/feature.js | 1 + ghost/admin/app/templates/settings/labs.hbs | 13 +++++ 6 files changed, 88 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/components/gh-member-settings-form.hbs b/ghost/admin/app/components/gh-member-settings-form.hbs index 132632bc9b..cf4e301e59 100644 --- a/ghost/admin/app/components/gh-member-settings-form.hbs +++ b/ghost/admin/app/components/gh-member-settings-form.hbs @@ -158,6 +158,9 @@ {{else if sub.cancel_at_period_end}} Has access until {{sub.validUntil}} Cancelled + {{else if sub.compExpiry}} + Expires {{sub.compExpiry}} + Active {{else if sub.trialUntil}} Ends {{sub.trialUntil}} Active diff --git a/ghost/admin/app/components/gh-member-settings-form.js b/ghost/admin/app/components/gh-member-settings-form.js index 266906d329..555f554930 100644 --- a/ghost/admin/app/components/gh-member-settings-form.js +++ b/ghost/admin/app/components/gh-member-settings-form.js @@ -89,6 +89,11 @@ export default class extends Component { data.trialUntil = moment(sub.trial_end_at).format('D MMM YYYY'); } } + + if (!sub.id && this.feature.get('compExpiring') && sub.tier?.expiry_at) { + data.compExpiry = moment(sub.tier.expiry_at).format('D MMM YYYY'); + } + return data; }); return tiers.map((tier) => { diff --git a/ghost/admin/app/components/modal-member-tier.hbs b/ghost/admin/app/components/modal-member-tier.hbs index 44277cae40..ade1f372a4 100644 --- a/ghost/admin/app/components/modal-member-tier.hbs +++ b/ghost/admin/app/components/modal-member-tier.hbs @@ -41,6 +41,24 @@ {{/each}} + {{#if (feature 'compExpiring')}} + + + + + {{svg-jar "arrow-down-small"}} + + + + {{/if}} {{/if}} diff --git a/ghost/admin/app/components/modal-member-tier.js b/ghost/admin/app/components/modal-member-tier.js index da2fde67b9..b01e9f7bc7 100644 --- a/ghost/admin/app/components/modal-member-tier.js +++ b/ghost/admin/app/components/modal-member-tier.js @@ -1,4 +1,5 @@ import ModalComponent from 'ghost-admin/components/modal-base'; +import moment from 'moment'; import {action} from '@ember/object'; import {inject as service} from '@ember/service'; import {task} from 'ember-concurrency'; @@ -14,6 +15,30 @@ export default class ModalMemberTier extends ModalComponent { @tracked tiers = []; @tracked selectedTier = null; @tracked loadingTiers = false; + @tracked expiryAt = 'forever'; + + @tracked expiryOptions = [ + { + label: 'Forever', + duration: 'forever' + }, + { + label: '1 Week', + duration: 'week' + }, + { + label: '1 Month', + duration: 'month' + }, + { + label: '6 Months', + duration: 'half-year' + }, + { + label: '1 Year', + duration: 'year' + } + ]; @task({drop: true}) *fetchTiers() { @@ -67,6 +92,11 @@ export default class ModalMemberTier extends ModalComponent { this.closeModal(); } + @action + updateExpiry(expiryDuration) { + this.expiryAt = expiryDuration; + } + @task({drop: true}) *addTier() { const url = `${this.ghostPaths.url.api(`members/${this.member.get('id')}`)}?include=tiers`; @@ -82,14 +112,29 @@ export default class ModalMemberTier extends ModalComponent { }); } + let expiryAt = null; + + if (this.expiryAt === 'week') { + expiryAt = moment.utc().add(7, 'days').startOf('day').toISOString(); + } else if (this.expiryAt === 'month') { + expiryAt = moment.utc().add(1, 'month').startOf('day').toISOString(); + } else if (this.expiryAt === 'half-year') { + expiryAt = moment.utc().add(6, 'months').startOf('day').toISOString(); + } else if (this.expiryAt === 'year') { + expiryAt = moment.utc().add(1, 'year').startOf('day').toISOString(); + } + const tiersData = { + id: this.selectedTier + }; + if (expiryAt) { + tiersData.expiry_at = expiryAt; + } const response = yield this.ajax.put(url, { data: { members: [{ id: this.member.get('id'), email: this.member.get('email'), - tiers: [{ - id: this.selectedTier - }] + tiers: [tiersData] }] } }); diff --git a/ghost/admin/app/services/feature.js b/ghost/admin/app/services/feature.js index 5105f3fcda..8a046bfb30 100644 --- a/ghost/admin/app/services/feature.js +++ b/ghost/admin/app/services/feature.js @@ -61,6 +61,7 @@ export default class FeatureService extends Service { @feature('beforeAfterCard') beforeAfterCard; @feature('newsletterPaywall') newsletterPaywall; @feature('freeTrial') freeTrial; + @feature('compExpiring') compExpiring; @feature('memberAttribution') memberAttribution; @feature('searchHelper') searchHelper; diff --git a/ghost/admin/app/templates/settings/labs.hbs b/ghost/admin/app/templates/settings/labs.hbs index 120ebb6439..de2ae3d3ef 100644 --- a/ghost/admin/app/templates/settings/labs.hbs +++ b/ghost/admin/app/templates/settings/labs.hbs @@ -239,6 +239,19 @@ +
+
+
+

Cardless trials

+

+ Add support for expiring complimentary subscriptions +

+
+
+ +
+
+