Skip to content

Commit

Permalink
[PM-14861]Vault items fail to load (#11974)
Browse files Browse the repository at this point in the history
* Resolve the vault items fail to load

* Remove the hasSubscription

* Replace with hasSubscription from metadata

* Resolve the failing popup
  • Loading branch information
cyprain-okeke authored Nov 13, 2024
1 parent 84b2b02 commit 24ca942
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
20 changes: 16 additions & 4 deletions apps/web/src/app/vault/individual-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
from,
lastValueFrom,
Observable,
of,
Subject,
} from "rxjs";
import {
Expand Down Expand Up @@ -184,12 +185,17 @@ export class VaultComponent implements OnInit, OnDestroy {
private refresh$ = new BehaviorSubject<void>(null);
private destroy$ = new Subject<void>();
private extensionRefreshEnabled: boolean;
private hasSubscription$ = new BehaviorSubject<boolean>(false);

private vaultItemDialogRef?: DialogRef<VaultItemDialogResult> | 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(
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 13 additions & 4 deletions apps/web/src/app/vault/org-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class VaultComponent implements OnInit, OnDestroy {
protected selectedCollection: TreeNode<CollectionAdminView> | undefined;
protected isEmpty: boolean;
protected showCollectionAccessRestricted: boolean;
private hasSubscription$ = new BehaviorSubject<boolean>(false);
protected currentSearchText$: Observable<string>;
protected freeTrial$: Observable<FreeTrial>;
/**
Expand All @@ -197,10 +198,15 @@ export class VaultComponent implements OnInit, OnDestroy {
protected addAccessStatus$ = new BehaviorSubject<AddAccessStatusType>(0);
private extensionRefreshEnabled: boolean;
private vaultItemDialogRef?: DialogRef<VaultItemDialogResult> | 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(
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export class OrganizationBillingMetadataResponse extends BaseResponse {
isManaged: boolean;
isOnSecretsManagerStandalone: boolean;
isSubscriptionUnpaid: boolean;
hasSubscription: boolean;

constructor(response: any) {
super(response);
this.isEligibleForSelfHost = this.getResponseProperty("IsEligibleForSelfHost");
this.isManaged = this.getResponseProperty("IsManaged");
this.isOnSecretsManagerStandalone = this.getResponseProperty("IsOnSecretsManagerStandalone");
this.isSubscriptionUnpaid = this.getResponseProperty("IsSubscriptionUnpaid");
this.hasSubscription = this.getResponseProperty("HasSubscription");
}
}

0 comments on commit 24ca942

Please sign in to comment.