import { Component, EventEmitter, Input, Output } from "@angular/core"; import { lastValueFrom } from "rxjs"; import { DialogService } from "@bitwarden/components"; import { EditBillingAddressDialogComponent } from "@bitwarden/web-vault/app/billing/payment/components/edit-billing-address-dialog.component"; import { AddressPipe } from "@bitwarden/web-vault/app/billing/payment/pipes"; import { BillingAddress } from "@bitwarden/web-vault/app/billing/payment/types"; import { BitwardenSubscriber } from "@bitwarden/web-vault/app/billing/types"; import { TaxIdWarningType, TaxIdWarningTypes, } from "@bitwarden/web-vault/app/billing/warnings/types"; import { SharedModule } from "@bitwarden/web-vault/app/shared"; // 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: "app-display-billing-address", template: `

{{ "billingAddress" | i18n }} @if (showMissingTaxIdBadge) { {{ "missingTaxId" | i18n }} }

@if (billingAddress) {

{{ billingAddress | address }}

@if (billingAddress.taxId) {

{{ "taxId" | i18n: billingAddress.taxId.value }} @if (showTaxIdPendingVerificationBadge) { {{ "pendingVerification" | i18n }} } @if (showUnverifiedTaxIdBadge) { {{ "unverified" | i18n }} }

} } @else {

{{ "noBillingAddress" | i18n }}

} @let key = billingAddress ? "editBillingAddress" : "addBillingAddress";
`, standalone: true, imports: [AddressPipe, SharedModule], }) export class DisplayBillingAddressComponent { // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals // eslint-disable-next-line @angular-eslint/prefer-signals @Input({ required: true }) subscriber!: BitwardenSubscriber; // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals // eslint-disable-next-line @angular-eslint/prefer-signals @Input({ required: true }) billingAddress!: BillingAddress | null; // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals // eslint-disable-next-line @angular-eslint/prefer-signals @Input() taxIdWarning?: TaxIdWarningType; // FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals // eslint-disable-next-line @angular-eslint/prefer-output-emitter-ref @Output() updated = new EventEmitter(); constructor(private dialogService: DialogService) {} editBillingAddress = async (): Promise => { const dialogRef = EditBillingAddressDialogComponent.open(this.dialogService, { data: { subscriber: this.subscriber, billingAddress: this.billingAddress, taxIdWarning: this.taxIdWarning, }, }); const result = await lastValueFrom(dialogRef.closed); if (result?.type === "success") { this.updated.emit(result.billingAddress); } }; get showMissingTaxIdBadge(): boolean { return this.subscriber.type !== "account" && this.taxIdWarning === TaxIdWarningTypes.Missing; } get showTaxIdPendingVerificationBadge(): boolean { return ( this.subscriber.type !== "account" && this.taxIdWarning === TaxIdWarningTypes.PendingVerification ); } get showUnverifiedTaxIdBadge(): boolean { return ( this.subscriber.type !== "account" && this.taxIdWarning === TaxIdWarningTypes.FailedVerification ); } }