mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
66 lines
2.8 KiB
TypeScript
66 lines
2.8 KiB
TypeScript
import { CommonModule } from "@angular/common";
|
|
import { Component, Input } from "@angular/core";
|
|
import { firstValueFrom, Observable, of, switchMap } from "rxjs";
|
|
|
|
import { PremiumBadgeComponent } from "@bitwarden/angular/billing/components/premium-badge";
|
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
|
|
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
|
|
import { ButtonModule, DialogService, MenuModule } from "@bitwarden/components";
|
|
import { DefaultSendFormConfigService, SendAddEditDialogComponent } from "@bitwarden/send-ui";
|
|
|
|
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
|
|
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
|
|
@Component({
|
|
selector: "tools-new-send-dropdown",
|
|
templateUrl: "new-send-dropdown.component.html",
|
|
imports: [JslibModule, CommonModule, ButtonModule, MenuModule, PremiumBadgeComponent],
|
|
providers: [DefaultSendFormConfigService],
|
|
})
|
|
/**
|
|
* A dropdown component that allows the user to create a new Send of a specific type.
|
|
*/
|
|
export class NewSendDropdownComponent {
|
|
/** If true, the plus icon will be hidden */
|
|
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
|
// eslint-disable-next-line @angular-eslint/prefer-signals
|
|
@Input() hideIcon: boolean = false;
|
|
|
|
/** SendType provided for the markup to pass back the selected type of Send */
|
|
protected sendType = SendType;
|
|
|
|
/** Indicates whether the user can access premium features. */
|
|
protected canAccessPremium$: Observable<boolean>;
|
|
|
|
constructor(
|
|
private billingAccountProfileStateService: BillingAccountProfileStateService,
|
|
private accountService: AccountService,
|
|
private dialogService: DialogService,
|
|
private addEditFormConfigService: DefaultSendFormConfigService,
|
|
) {
|
|
this.canAccessPremium$ = this.accountService.activeAccount$.pipe(
|
|
switchMap((account) =>
|
|
account
|
|
? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
|
|
: of(false),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Opens the SendAddEditComponent for a new Send with the provided type.
|
|
* If has user does not have premium access and the type is File do nothing the PremiumBadgeComponent will handle the flow.
|
|
* @param type The type of Send to create.
|
|
*/
|
|
async createSend(type: SendType) {
|
|
if (!(await firstValueFrom(this.canAccessPremium$)) && type === SendType.File) {
|
|
return;
|
|
}
|
|
|
|
const formConfig = await this.addEditFormConfigService.buildConfig("add", undefined, type);
|
|
|
|
SendAddEditDialogComponent.open(this.dialogService, { formConfig });
|
|
}
|
|
}
|