mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
* Updated billing state provider to not rely on ActiveUserStateProvider * Updated usages * Resolved browser build * Resolved web build * Resolved CLI build * resolved desktop build * Update apps/cli/src/tools/send/commands/create.command.ts Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Move subscription visibility logic from component to service * Resolved unit test failures. Using existing userIds where present * Simplified activeUserId access * Resolved typescript strict errors * Resolved broken unit test * Resolved ts strict error --------- Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Directive, OnDestroy, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
|
import { of, Subject, switchMap, takeUntil } from "rxjs";
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
|
|
|
/**
|
|
* Only shows the element if the user has premium.
|
|
*/
|
|
@Directive({
|
|
selector: "[appPremium]",
|
|
})
|
|
export class PremiumDirective implements OnInit, OnDestroy {
|
|
private directiveIsDestroyed$ = new Subject<boolean>();
|
|
|
|
constructor(
|
|
private templateRef: TemplateRef<any>,
|
|
private viewContainer: ViewContainerRef,
|
|
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
|
private accountService: AccountService,
|
|
) {}
|
|
|
|
async ngOnInit(): Promise<void> {
|
|
this.accountService.activeAccount$
|
|
.pipe(
|
|
switchMap((account) =>
|
|
account
|
|
? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
|
|
: of(false),
|
|
),
|
|
takeUntil(this.directiveIsDestroyed$),
|
|
)
|
|
.subscribe((premium: boolean) => {
|
|
if (premium) {
|
|
this.viewContainer.createEmbeddedView(this.templateRef);
|
|
} else {
|
|
this.viewContainer.clear();
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.directiveIsDestroyed$.next(true);
|
|
this.directiveIsDestroyed$.complete();
|
|
}
|
|
}
|