From 942ad319e8979addd42cce66586b649ffe14b997 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 19 May 2021 22:35:55 +0530 Subject: [PATCH] Updated complimentary subscription assignment to member no refs With custom products, we added a new modal to add a complimentary price to a member. Since we want to handle the comp prices implicitly with new changes, this change updates the comp subscription assignment to a member directly without opening a modal, by using the old `comped` flag in API. The `comped` flag takes care of creating the right complimentary subscription for member. In case a member already has a comped subscription, we hide the option to add another subscription. --- .../components/gh-member-settings-form-cp.hbs | 23 +++++++++++-------- .../components/gh-member-settings-form-cp.js | 13 +++++++++++ ghost/admin/app/controllers/member.js | 2 +- ghost/admin/app/templates/member.hbs | 1 + 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ghost/admin/app/components/gh-member-settings-form-cp.hbs b/ghost/admin/app/components/gh-member-settings-form-cp.hbs index 38e7aca033..15f89c3473 100644 --- a/ghost/admin/app/components/gh-member-settings-form-cp.hbs +++ b/ghost/admin/app/components/gh-member-settings-form-cp.hbs @@ -109,9 +109,11 @@
This member doesn't have subscriptions.
{{#unless this.member.isNew}} - + {{#if this.isAddComplimentaryAllowed}} + + {{/if}} {{/unless}}
@@ -121,7 +123,7 @@

- {{product.name}} + {{product.name}} {{#unless (eq product.subscriptions.length 1)}} {{product.subscriptions.length}} subscriptions {{/unless}} @@ -177,12 +179,13 @@

{{/each}} - - + {{#if this.isAddComplimentaryAllowed}} + + {{/if}}
{{/each}} diff --git a/ghost/admin/app/components/gh-member-settings-form-cp.js b/ghost/admin/app/components/gh-member-settings-form-cp.js index c518e3fd37..50280dae14 100644 --- a/ghost/admin/app/components/gh-member-settings-form-cp.js +++ b/ghost/admin/app/components/gh-member-settings-form-cp.js @@ -29,6 +29,14 @@ export default class extends Component { return !this.member.get('isNew') && this.membersUtils.isStripeEnabled; } + get isAddComplimentaryAllowed() { + let subscriptions = this.member.get('subscriptions') || []; + const hasZeroPriceSub = subscriptions.find((sub) => { + return !sub?.price?.amount; + }); + return !hasZeroPriceSub; + } + get products() { let products = this.member.get('products') || []; let subscriptions = this.member.get('subscriptions') || []; @@ -95,6 +103,11 @@ export default class extends Component { continueSubscription(subscriptionId) { this.continueSubscriptionTask.perform(subscriptionId); } + @action + addCompedSubscription() { + this.args.setProperty('comped', true); + this.args.saveMember(); + } @task({drop: true}) *cancelSubscriptionTask(subscriptionId) { diff --git a/ghost/admin/app/controllers/member.js b/ghost/admin/app/controllers/member.js index 4f9b40dcef..e7813f53b0 100644 --- a/ghost/admin/app/controllers/member.js +++ b/ghost/admin/app/controllers/member.js @@ -159,7 +159,7 @@ export default class MemberController extends Controller { _saveMemberProperty(propKey, newValue) { let currentValue = this.member.get(propKey); - if (newValue) { + if (newValue && typeof newValue === 'string') { newValue = newValue.trim(); } diff --git a/ghost/admin/app/templates/member.hbs b/ghost/admin/app/templates/member.hbs index 1d4ed3d0b7..fdfe6793ae 100644 --- a/ghost/admin/app/templates/member.hbs +++ b/ghost/admin/app/templates/member.hbs @@ -31,6 +31,7 @@ @member={{this.member}} @scratchMember={{this.scratchMember}} @setProperty={{this.setProperty}} + @saveMember={{this.save}} @isLoading={{this.isLoading}} />