1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Hide bank account for premium and when non-premium selects non-US country (#15707)

This commit is contained in:
Alex Morask
2025-07-21 15:06:02 -05:00
committed by GitHub
parent 83f9061474
commit 1f20bcecf0
2 changed files with 21 additions and 16 deletions

View File

@@ -28,7 +28,11 @@ type DialogResult =
{{ "changePaymentMethod" | i18n }} {{ "changePaymentMethod" | i18n }}
</span> </span>
<div bitDialogContent> <div bitDialogContent>
<app-enter-payment-method [group]="formGroup" [includeBillingAddress]="true"> <app-enter-payment-method
[group]="formGroup"
[showBankAccount]="dialogParams.owner.type !== 'account'"
[includeBillingAddress]="true"
>
</app-enter-payment-method> </app-enter-payment-method>
</div> </div>
<ng-container bitDialogFooter> <ng-container bitDialogFooter>

View File

@@ -1,6 +1,6 @@
import { Component, Input, OnInit } from "@angular/core"; import { Component, Input, OnInit } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms"; import { FormControl, FormGroup, Validators } from "@angular/forms";
import { BehaviorSubject, startWith, Subject, takeUntil } from "rxjs"; import { map, Observable, of, startWith, Subject, takeUntil } from "rxjs";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
@@ -48,7 +48,7 @@ type PaymentMethodFormGroup = FormGroup<{
{{ "creditCard" | i18n }} {{ "creditCard" | i18n }}
</bit-label> </bit-label>
</bit-radio-button> </bit-radio-button>
@if (showBankAccount) { @if (showBankAccount$ | async) {
<bit-radio-button id="bank-payment-method" [value]="'bankAccount'"> <bit-radio-button id="bank-payment-method" [value]="'bankAccount'">
<bit-label> <bit-label>
<i class="bwi bwi-fw bwi-billing" aria-hidden="true"></i> <i class="bwi bwi-fw bwi-billing" aria-hidden="true"></i>
@@ -226,20 +226,12 @@ type PaymentMethodFormGroup = FormGroup<{
export class EnterPaymentMethodComponent implements OnInit { export class EnterPaymentMethodComponent implements OnInit {
@Input({ required: true }) group!: PaymentMethodFormGroup; @Input({ required: true }) group!: PaymentMethodFormGroup;
private showBankAccountSubject = new BehaviorSubject<boolean>(true); @Input() private showBankAccount = true;
showBankAccount$ = this.showBankAccountSubject.asObservable(); @Input() showPayPal = true;
@Input() @Input() showAccountCredit = false;
set showBankAccount(value: boolean) { @Input() includeBillingAddress = false;
this.showBankAccountSubject.next(value);
}
get showBankAccount(): boolean {
return this.showBankAccountSubject.value;
}
@Input() showPayPal: boolean = true;
@Input() showAccountCredit: boolean = false;
@Input() includeBillingAddress: boolean = false;
protected showBankAccount$!: Observable<boolean>;
protected selectableCountries = selectableCountries; protected selectableCountries = selectableCountries;
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
@@ -267,7 +259,16 @@ export class EnterPaymentMethodComponent implements OnInit {
} }
if (!this.includeBillingAddress) { if (!this.includeBillingAddress) {
this.showBankAccount$ = of(this.showBankAccount);
this.group.controls.billingAddress.disable(); this.group.controls.billingAddress.disable();
} else {
this.group.controls.billingAddress.patchValue({
country: "US",
});
this.showBankAccount$ = this.group.controls.billingAddress.controls.country.valueChanges.pipe(
startWith(this.group.controls.billingAddress.controls.country.value),
map((country) => this.showBankAccount && country === "US"),
);
} }
this.group.controls.type.valueChanges this.group.controls.type.valueChanges