Browse Source

Improve usability

pull/7662/head
Thomas Kaul 2 weeks ago
parent
commit
e16be979b4
  1. 37
      apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.component.ts
  2. 2
      apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.html

37
apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.component.ts

@ -2,7 +2,13 @@ import { TransferBalanceDto } from '@ghostfolio/common/dtos';
import { AccountWithPlatform } from '@ghostfolio/common/types'; import { AccountWithPlatform } from '@ghostfolio/common/types';
import { GfAccountSelectorComponent } from '@ghostfolio/ui/account-selector'; import { GfAccountSelectorComponent } from '@ghostfolio/ui/account-selector';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
computed,
inject,
signal
} from '@angular/core';
import { import {
FormControl, FormControl,
FormGroup, FormGroup,
@ -48,11 +54,22 @@ export class GfTransferBalanceDialogComponent {
protected readonly labelFrom = $localize`From`; protected readonly labelFrom = $localize`From`;
protected readonly labelTo = $localize`To`; protected readonly labelTo = $localize`To`;
protected readonly toAccounts = computed(() => {
const fromAccountId = this.fromAccountId();
return this.accounts.filter(({ id }) => {
return id !== fromAccountId;
});
});
protected readonly transferBalanceForm: TransferBalanceForm = new FormGroup( protected readonly transferBalanceForm: TransferBalanceForm = new FormGroup(
{ {
balance: new FormControl<number | string | null>('', Validators.required), balance: new FormControl<number | string | null>('', Validators.required),
fromAccount: new FormControl<string | null>('', Validators.required), fromAccount: new FormControl<string | null>('', Validators.required),
toAccount: new FormControl<string | null>('', Validators.required) toAccount: new FormControl<string | null>(
{ disabled: true, value: '' },
Validators.required
)
}, },
{ {
validators: this.compareAccounts validators: this.compareAccounts
@ -62,14 +79,30 @@ export class GfTransferBalanceDialogComponent {
private readonly dialogRef = private readonly dialogRef =
inject<MatDialogRef<GfTransferBalanceDialogComponent>>(MatDialogRef); inject<MatDialogRef<GfTransferBalanceDialogComponent>>(MatDialogRef);
private readonly fromAccountId = signal<string | null>(null);
public ngOnInit() { public ngOnInit() {
this.transferBalanceForm.controls.fromAccount.valueChanges.subscribe( this.transferBalanceForm.controls.fromAccount.valueChanges.subscribe(
(id) => { (id) => {
this.fromAccountId.set(id);
const currency = this.getAccountById(id)?.currency; const currency = this.getAccountById(id)?.currency;
if (currency) { if (currency) {
this.currency = currency; this.currency = currency;
} }
const toAccountControl = this.transferBalanceForm.controls.toAccount;
if (id) {
if (toAccountControl.value === id) {
toAccountControl.setValue(null);
}
toAccountControl.enable();
} else {
toAccountControl.disable();
}
} }
); );
} }

2
apps/client/src/app/pages/accounts/transfer-balance/transfer-balance-dialog.html

@ -16,7 +16,7 @@
<div> <div>
<gf-account-selector <gf-account-selector
formControlName="toAccount" formControlName="toAccount"
[accounts]="accounts" [accounts]="toAccounts()"
[label]="labelTo" [label]="labelTo"
/> />
</div> </div>

Loading…
Cancel
Save