From 24ca942cd6f3f9809c0caac77ff481641d4f87a4 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:28:40 +0100 Subject: [PATCH] [PM-14861]Vault items fail to load (#11974) * Resolve the vault items fail to load * Remove the hasSubscription * Replace with hasSubscription from metadata * Resolve the failing popup --- .../vault/individual-vault/vault.component.ts | 20 +++++++++++++++---- .../app/vault/org-vault/vault.component.ts | 17 ++++++++++++---- .../organization-billing-metadata.response.ts | 2 ++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/web/src/app/vault/individual-vault/vault.component.ts b/apps/web/src/app/vault/individual-vault/vault.component.ts index 688cbfbf9f..ce61cd51fc 100644 --- a/apps/web/src/app/vault/individual-vault/vault.component.ts +++ b/apps/web/src/app/vault/individual-vault/vault.component.ts @@ -16,6 +16,7 @@ import { from, lastValueFrom, Observable, + of, Subject, } from "rxjs"; import { @@ -184,12 +185,17 @@ export class VaultComponent implements OnInit, OnDestroy { private refresh$ = new BehaviorSubject(null); private destroy$ = new Subject(); private extensionRefreshEnabled: boolean; + private hasSubscription$ = new BehaviorSubject(false); private vaultItemDialogRef?: DialogRef | undefined; private readonly unpaidSubscriptionDialog$ = this.organizationService.organizations$.pipe( filter((organizations) => organizations.length === 1), - switchMap(([organization]) => + map(([organization]) => organization), + switchMap((organization) => from(this.billingApiService.getOrganizationBillingMetadata(organization.id)).pipe( + tap((organizationMetaData) => { + this.hasSubscription$.next(organizationMetaData.hasSubscription); + }), switchMap((organizationMetaData) => from( this.trialFlowService.handleUnpaidSubscriptionDialog( @@ -417,11 +423,17 @@ export class VaultComponent implements OnInit, OnDestroy { this.unpaidSubscriptionDialog$.pipe(takeUntil(this.destroy$)).subscribe(); - const organizationsPaymentStatus$ = this.organizationService.organizations$.pipe( - switchMap((allOrganizations) => { + const organizationsPaymentStatus$ = combineLatest([ + this.organizationService.organizations$, + this.hasSubscription$, + ]).pipe( + switchMap(([allOrganizations, hasSubscription]) => { + if (!allOrganizations || allOrganizations.length === 0 || !hasSubscription) { + return of([]); + } return combineLatest( allOrganizations - .filter((org) => org.isOwner) + .filter((org) => org.isOwner && hasSubscription) .map((org) => combineLatest([ this.organizationApiService.getSubscription(org.id), diff --git a/apps/web/src/app/vault/org-vault/vault.component.ts b/apps/web/src/app/vault/org-vault/vault.component.ts index dee584f3a4..64318047b9 100644 --- a/apps/web/src/app/vault/org-vault/vault.component.ts +++ b/apps/web/src/app/vault/org-vault/vault.component.ts @@ -178,6 +178,7 @@ export class VaultComponent implements OnInit, OnDestroy { protected selectedCollection: TreeNode | undefined; protected isEmpty: boolean; protected showCollectionAccessRestricted: boolean; + private hasSubscription$ = new BehaviorSubject(false); protected currentSearchText$: Observable; protected freeTrial$: Observable; /** @@ -197,10 +198,15 @@ export class VaultComponent implements OnInit, OnDestroy { protected addAccessStatus$ = new BehaviorSubject(0); private extensionRefreshEnabled: boolean; private vaultItemDialogRef?: DialogRef | undefined; + private readonly unpaidSubscriptionDialog$ = this.organizationService.organizations$.pipe( filter((organizations) => organizations.length === 1), - switchMap(([organization]) => + map(([organization]) => organization), + switchMap((organization) => from(this.billingApiService.getOrganizationBillingMetadata(organization.id)).pipe( + tap((organizationMetaData) => { + this.hasSubscription$.next(organizationMetaData.hasSubscription); + }), switchMap((organizationMetaData) => from( this.trialFlowService.handleUnpaidSubscriptionDialog( @@ -580,9 +586,12 @@ export class VaultComponent implements OnInit, OnDestroy { this.unpaidSubscriptionDialog$.pipe(takeUntil(this.destroy$)).subscribe(); - this.freeTrial$ = organization$.pipe( - filter((org) => org.isOwner), - switchMap((org) => + this.freeTrial$ = combineLatest([ + organization$, + this.hasSubscription$.pipe(filter((hasSubscription) => hasSubscription !== null)), + ]).pipe( + filter(([org, hasSubscription]) => org.isOwner && hasSubscription), + switchMap(([org]) => combineLatest([ of(org), this.organizationApiService.getSubscription(org.id), diff --git a/libs/common/src/billing/models/response/organization-billing-metadata.response.ts b/libs/common/src/billing/models/response/organization-billing-metadata.response.ts index ae6d1ac92c..d9733aa80f 100644 --- a/libs/common/src/billing/models/response/organization-billing-metadata.response.ts +++ b/libs/common/src/billing/models/response/organization-billing-metadata.response.ts @@ -5,6 +5,7 @@ export class OrganizationBillingMetadataResponse extends BaseResponse { isManaged: boolean; isOnSecretsManagerStandalone: boolean; isSubscriptionUnpaid: boolean; + hasSubscription: boolean; constructor(response: any) { super(response); @@ -12,5 +13,6 @@ export class OrganizationBillingMetadataResponse extends BaseResponse { this.isManaged = this.getResponseProperty("IsManaged"); this.isOnSecretsManagerStandalone = this.getResponseProperty("IsOnSecretsManagerStandalone"); this.isSubscriptionUnpaid = this.getResponseProperty("IsSubscriptionUnpaid"); + this.hasSubscription = this.getResponseProperty("HasSubscription"); } }