Skip to content

Commit

Permalink
Hide the product subscription name on delegation (#1113)
Browse files Browse the repository at this point in the history
closes #787
  • Loading branch information
ygrik authored Jan 12, 2021
1 parent 6d7c900 commit 87791e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
<form>
<div class="table">
<div class="table-row">
<!-- ko ifnot: delegationEnabled -->
<div class="col-5">
<input type="text" class="form-control" placeholder="Your new product subscription name" data-bind="textInput: subscriptionName" />
</div>
<!-- /ko -->
<!-- ko if: termsOfUse -->
<div class="col-4 form-inline">
<!-- ko if: termsOfUse -->
<div class="form-check">
<input id="consentCheckbox" type="checkbox" class="form-check-input" data-bind="checked: consented" />
<label for="consentCheckbox" class="form-check-label"> I agree to the Terms of Use. &nbsp;<a href="#" data-bind="click: toggleTermsOfUser, text: showHideLabel"></a></label>
</div>
<!-- /ko -->
</div>
<div class="col-3">
<!-- /ko -->
<div class="col-3" >
<button class="button button-primary" data-bind="click: $component.subscribe, enable: canSubscribe">Subscribe</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RouteHelper } from "../../../../../routing/routeHelper";
template: template
})
export class ProductSubscribe {
public delegationEnabled: boolean;
public readonly working: ko.Observable<boolean>;
public readonly product: ko.Observable<Product>;
public readonly showTermsOfUse: ko.Observable<boolean>;
Expand Down Expand Up @@ -48,7 +49,7 @@ export class ProductSubscribe {
this.isUserSignedIn = ko.observable(false);

this.canSubscribe = ko.pureComputed((): boolean => {
return this.subscriptionName().length > 0 && ((this.termsOfUse() && this.consented()) || !!!this.termsOfUse());
return (this.delegationEnabled || this.subscriptionName().length > 0) && ((this.termsOfUse() && this.consented()) || !!!this.termsOfUse());
});
}

Expand All @@ -67,6 +68,8 @@ export class ProductSubscribe {
this.showTermsOfUse(false);
this.working(true);

this.delegationEnabled = await this.isDelegationEnabled();

const productName = this.routeHelper.getProductName();

if (!productName) {
Expand Down Expand Up @@ -116,18 +119,9 @@ export class ProductSubscribe {
this.limitReached(limitReached);
}

private async isDelegationEnabled(userId: string, productId: string): Promise<boolean> {
private async isDelegationEnabled(): Promise<boolean> {
const isDelegationEnabled = await this.tenantService.isSubscriptionDelegationEnabled();
if (isDelegationEnabled) {
const delegation = new URLSearchParams();
delegation.append(DelegationParameters.ProductId, Utils.getResourceName("products", productId));
delegation.append(DelegationParameters.UserId, Utils.getResourceName("users", userId));
this.router.navigateTo(`/${DelegationAction.subscribe}?${delegation.toString()}`);

return true;
}

return false;
return isDelegationEnabled;
}

public async subscribe(): Promise<void> {
Expand All @@ -151,8 +145,11 @@ export class ProductSubscribe {
this.working(true);

try {
const isDelegationEnabled = await this.isDelegationEnabled(userId, productId);
if (isDelegationEnabled) {
if (this.delegationEnabled) {
const delegation = new URLSearchParams();
delegation.append(DelegationParameters.ProductId, Utils.getResourceName("products", productId));
delegation.append(DelegationParameters.UserId, Utils.getResourceName("users", userId));
await this.router.navigateTo(`/${DelegationAction.subscribe}?${delegation.toString()}`);
return;
}

Expand Down

0 comments on commit 87791e0

Please sign in to comment.