mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
[PM-27206] fix: redirect from premium page if user has premium (#16990)
This commit is contained in:
@@ -1,21 +1,29 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, DestroyRef, inject } from "@angular/core";
|
import { Component, DestroyRef, inject } from "@angular/core";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { combineLatest, firstValueFrom, map, Observable, of, shareReplay, switchMap } from "rxjs";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
|
import {
|
||||||
|
combineLatest,
|
||||||
|
firstValueFrom,
|
||||||
|
from,
|
||||||
|
map,
|
||||||
|
Observable,
|
||||||
|
of,
|
||||||
|
shareReplay,
|
||||||
|
switchMap,
|
||||||
|
} from "rxjs";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { SyncService } from "@bitwarden/common/platform/sync";
|
import { SyncService } from "@bitwarden/common/platform/sync";
|
||||||
import {
|
import {
|
||||||
DialogService,
|
|
||||||
ToastService,
|
|
||||||
SectionComponent,
|
|
||||||
BadgeModule,
|
BadgeModule,
|
||||||
TypographyModule,
|
DialogService,
|
||||||
LinkModule,
|
LinkModule,
|
||||||
|
SectionComponent,
|
||||||
|
TypographyModule,
|
||||||
} from "@bitwarden/components";
|
} from "@bitwarden/components";
|
||||||
import { PricingCardComponent } from "@bitwarden/pricing";
|
import { PricingCardComponent } from "@bitwarden/pricing";
|
||||||
import { I18nPipe } from "@bitwarden/ui-common";
|
import { I18nPipe } from "@bitwarden/ui-common";
|
||||||
@@ -69,14 +77,14 @@ export class PremiumVNextComponent {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
private i18nService: I18nService,
|
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
private platformUtilsService: PlatformUtilsService,
|
private platformUtilsService: PlatformUtilsService,
|
||||||
private syncService: SyncService,
|
private syncService: SyncService,
|
||||||
private toastService: ToastService,
|
|
||||||
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
||||||
private subscriptionPricingService: SubscriptionPricingService,
|
private subscriptionPricingService: SubscriptionPricingService,
|
||||||
|
private router: Router,
|
||||||
|
private activatedRoute: ActivatedRoute,
|
||||||
) {
|
) {
|
||||||
this.isSelfHost = this.platformUtilsService.isSelfHost();
|
this.isSelfHost = this.platformUtilsService.isSelfHost();
|
||||||
|
|
||||||
@@ -107,6 +115,23 @@ export class PremiumVNextComponent {
|
|||||||
this.hasPremiumPersonally$,
|
this.hasPremiumPersonally$,
|
||||||
]).pipe(map(([hasOrgPremium, hasPersonalPremium]) => !hasOrgPremium && !hasPersonalPremium));
|
]).pipe(map(([hasOrgPremium, hasPersonalPremium]) => !hasOrgPremium && !hasPersonalPremium));
|
||||||
|
|
||||||
|
// redirect to user subscription page if they already have premium personally
|
||||||
|
// redirect to individual vault if they already have premium from an org
|
||||||
|
combineLatest([this.hasPremiumFromAnyOrganization$, this.hasPremiumPersonally$])
|
||||||
|
.pipe(
|
||||||
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
switchMap(([hasPremiumFromOrg, hasPremiumPersonally]) => {
|
||||||
|
if (hasPremiumPersonally) {
|
||||||
|
return from(this.navigateToSubscriptionPage());
|
||||||
|
}
|
||||||
|
if (hasPremiumFromOrg) {
|
||||||
|
return from(this.navigateToIndividualVault());
|
||||||
|
}
|
||||||
|
return of(true);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.subscribe();
|
||||||
|
|
||||||
this.personalPricingTiers$ =
|
this.personalPricingTiers$ =
|
||||||
this.subscriptionPricingService.getPersonalSubscriptionPricingTiers$();
|
this.subscriptionPricingService.getPersonalSubscriptionPricingTiers$();
|
||||||
|
|
||||||
@@ -141,6 +166,11 @@ export class PremiumVNextComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private navigateToSubscriptionPage = (): Promise<boolean> =>
|
||||||
|
this.router.navigate(["../user-subscription"], { relativeTo: this.activatedRoute });
|
||||||
|
|
||||||
|
private navigateToIndividualVault = (): Promise<boolean> => this.router.navigate(["/vault"]);
|
||||||
|
|
||||||
finalizeUpgrade = async () => {
|
finalizeUpgrade = async () => {
|
||||||
await this.apiService.refreshIdentityToken();
|
await this.apiService.refreshIdentityToken();
|
||||||
await this.syncService.fullSync(true);
|
await this.syncService.fullSync(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user