mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
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.
This commit is contained in:
parent
a2e3e0c570
commit
942ad319e8
4 changed files with 28 additions and 11 deletions
|
@ -109,9 +109,11 @@
|
||||||
<div class="gh-cp-memberproduct-noproduct">
|
<div class="gh-cp-memberproduct-noproduct">
|
||||||
<div class="mb2">This member doesn't have subscriptions.</div>
|
<div class="mb2">This member doesn't have subscriptions.</div>
|
||||||
{{#unless this.member.isNew}}
|
{{#unless this.member.isNew}}
|
||||||
<button type="button" class="gh-btn gh-btn-text green gh-btn-icon gh-btn-addproduct" {{action (toggle "showMemberProductModal" this)}}>
|
{{#if this.isAddComplimentaryAllowed}}
|
||||||
<span>{{svg-jar "add"}} Add complimentary subscription</span>
|
<button type="button" class="gh-btn gh-btn-text green gh-btn-icon gh-btn-addproduct" {{action "addCompedSubscription"}}>
|
||||||
</button>
|
<span>{{svg-jar "add"}} Add complimentary subscription</span>
|
||||||
|
</button>
|
||||||
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -177,12 +179,13 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
{{#if this.isAddComplimentaryAllowed}}
|
||||||
<div class="gh-memberproduct-list-footer">
|
<div class="gh-memberproduct-list-footer">
|
||||||
<button type="button" class="gh-btn gh-btn-text green gh-btn-icon gh-btn-addproduct" {{action (toggle "showMemberProductModal" this)}}>
|
<button type="button" class="gh-btn gh-btn-text green gh-btn-icon gh-btn-addproduct" {{action "addCompedSubscription"}}>
|
||||||
<span>{{svg-jar "add"}} Add complimentary subscription</span>
|
<span>{{svg-jar "add"}} Add complimentary subscription</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -29,6 +29,14 @@ export default class extends Component {
|
||||||
return !this.member.get('isNew') && this.membersUtils.isStripeEnabled;
|
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() {
|
get products() {
|
||||||
let products = this.member.get('products') || [];
|
let products = this.member.get('products') || [];
|
||||||
let subscriptions = this.member.get('subscriptions') || [];
|
let subscriptions = this.member.get('subscriptions') || [];
|
||||||
|
@ -95,6 +103,11 @@ export default class extends Component {
|
||||||
continueSubscription(subscriptionId) {
|
continueSubscription(subscriptionId) {
|
||||||
this.continueSubscriptionTask.perform(subscriptionId);
|
this.continueSubscriptionTask.perform(subscriptionId);
|
||||||
}
|
}
|
||||||
|
@action
|
||||||
|
addCompedSubscription() {
|
||||||
|
this.args.setProperty('comped', true);
|
||||||
|
this.args.saveMember();
|
||||||
|
}
|
||||||
|
|
||||||
@task({drop: true})
|
@task({drop: true})
|
||||||
*cancelSubscriptionTask(subscriptionId) {
|
*cancelSubscriptionTask(subscriptionId) {
|
||||||
|
|
|
@ -159,7 +159,7 @@ export default class MemberController extends Controller {
|
||||||
_saveMemberProperty(propKey, newValue) {
|
_saveMemberProperty(propKey, newValue) {
|
||||||
let currentValue = this.member.get(propKey);
|
let currentValue = this.member.get(propKey);
|
||||||
|
|
||||||
if (newValue) {
|
if (newValue && typeof newValue === 'string') {
|
||||||
newValue = newValue.trim();
|
newValue = newValue.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
@member={{this.member}}
|
@member={{this.member}}
|
||||||
@scratchMember={{this.scratchMember}}
|
@scratchMember={{this.scratchMember}}
|
||||||
@setProperty={{this.setProperty}}
|
@setProperty={{this.setProperty}}
|
||||||
|
@saveMember={{this.save}}
|
||||||
@isLoading={{this.isLoading}} />
|
@isLoading={{this.isLoading}} />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue