Browse Source

feat(client): resolve errors

pull/6858/head
KenTandrian 1 day ago
parent
commit
affea1563d
  1. 47
      apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts

47
apps/client/src/app/pages/portfolio/activities/import-activities-dialog/import-activities-dialog.component.ts

@ -26,7 +26,7 @@ import {
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { import {
FormBuilder, FormControl,
FormGroup, FormGroup,
ReactiveFormsModule, ReactiveFormsModule,
Validators Validators
@ -84,7 +84,6 @@ import { ImportActivitiesDialogParams } from './interfaces/interfaces';
export class GfImportActivitiesDialogComponent { export class GfImportActivitiesDialogComponent {
public accounts: CreateAccountWithBalancesDto[] = []; public accounts: CreateAccountWithBalancesDto[] = [];
public activities: Activity[] = []; public activities: Activity[] = [];
public assetProfileForm: FormGroup;
public assetProfiles: CreateAssetProfileWithMarketDataDto[] = []; public assetProfiles: CreateAssetProfileWithMarketDataDto[] = [];
public dataSource: MatTableDataSource<Activity>; public dataSource: MatTableDataSource<Activity>;
public details: any[] = []; public details: any[] = [];
@ -104,13 +103,18 @@ export class GfImportActivitiesDialogComponent {
public tags: CreateTagDto[] = []; public tags: CreateTagDto[] = [];
public totalItems: number; public totalItems: number;
protected readonly assetProfileForm = new FormGroup({
assetProfileIdentifier: new FormControl<PortfolioPosition | null>(null, {
validators: [Validators.required]
})
});
public constructor( public constructor(
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@Inject(MAT_DIALOG_DATA) public data: ImportActivitiesDialogParams, @Inject(MAT_DIALOG_DATA) public data: ImportActivitiesDialogParams,
private dataService: DataService, private dataService: DataService,
private destroyRef: DestroyRef, private destroyRef: DestroyRef,
private deviceDetectorService: DeviceDetectorService, private deviceDetectorService: DeviceDetectorService,
private formBuilder: FormBuilder,
public dialogRef: MatDialogRef<GfImportActivitiesDialogComponent>, public dialogRef: MatDialogRef<GfImportActivitiesDialogComponent>,
private importActivitiesService: ImportActivitiesService, private importActivitiesService: ImportActivitiesService,
private snackBar: MatSnackBar private snackBar: MatSnackBar
@ -123,10 +127,6 @@ export class GfImportActivitiesDialogComponent {
this.stepperOrientation = this.stepperOrientation =
this.deviceType === 'mobile' ? 'vertical' : 'horizontal'; this.deviceType === 'mobile' ? 'vertical' : 'horizontal';
this.assetProfileForm = this.formBuilder.group({
assetProfileIdentifier: [undefined, Validators.required]
});
if ( if (
this.data?.activityTypes?.length === 1 && this.data?.activityTypes?.length === 1 &&
this.data?.activityTypes?.[0] === 'DIVIDEND' this.data?.activityTypes?.[0] === 'DIVIDEND'
@ -135,7 +135,7 @@ export class GfImportActivitiesDialogComponent {
this.dialogTitle = $localize`Import Dividends`; this.dialogTitle = $localize`Import Dividends`;
this.mode = 'DIVIDEND'; this.mode = 'DIVIDEND';
this.assetProfileForm.get('assetProfileIdentifier').disable(); this.assetProfileForm.controls.assetProfileIdentifier.disable();
this.dataService this.dataService
.fetchPortfolioHoldings({ .fetchPortfolioHoldings({
@ -156,7 +156,7 @@ export class GfImportActivitiesDialogComponent {
this.holdings = sortBy(holdings, ({ name }) => { this.holdings = sortBy(holdings, ({ name }) => {
return name.toLowerCase(); return name.toLowerCase();
}); });
this.assetProfileForm.get('assetProfileIdentifier').enable(); this.assetProfileForm.controls.assetProfileIdentifier.enable();
this.isLoading = false; this.isLoading = false;
@ -225,11 +225,14 @@ export class GfImportActivitiesDialogComponent {
} }
public onLoadDividends(aStepper: MatStepper) { public onLoadDividends(aStepper: MatStepper) {
this.assetProfileForm.get('assetProfileIdentifier').disable(); this.assetProfileForm.controls.assetProfileIdentifier.disable();
const { dataSource, symbol } = this.assetProfileForm.get( const { dataSource, symbol } =
'assetProfileIdentifier' this.assetProfileForm.controls.assetProfileIdentifier.value ?? {};
).value;
if (!dataSource || !symbol) {
return;
}
this.dataService this.dataService
.fetchDividendsImport({ .fetchDividendsImport({
@ -258,7 +261,7 @@ export class GfImportActivitiesDialogComponent {
this.errorMessages = []; this.errorMessages = [];
this.importStep = ImportStep.SELECT_ACTIVITIES; this.importStep = ImportStep.SELECT_ACTIVITIES;
this.pageIndex = 0; this.pageIndex = 0;
this.assetProfileForm.get('assetProfileIdentifier').enable(); this.assetProfileForm.controls.assetProfileIdentifier.enable();
aStepper.reset(); aStepper.reset();
} }
@ -270,8 +273,10 @@ export class GfImportActivitiesDialogComponent {
input.onchange = (event) => { input.onchange = (event) => {
// Getting the file reference // Getting the file reference
const file = (event.target as HTMLInputElement).files[0]; const file = (event.target as HTMLInputElement).files?.[0];
this.handleFile({ file, stepper }); if (file) {
this.handleFile({ file, stepper });
}
}; };
input.click(); input.click();
@ -283,13 +288,7 @@ export class GfImportActivitiesDialogComponent {
}); });
} }
private async handleFile({ private handleFile({ file, stepper }: { file: File; stepper: MatStepper }) {
file,
stepper
}: {
file: File;
stepper: MatStepper;
}): Promise<void> {
this.snackBar.open('⏳ ' + $localize`Validating data...`); this.snackBar.open('⏳ ' + $localize`Validating data...`);
// Setting up the reader // Setting up the reader
@ -297,7 +296,7 @@ export class GfImportActivitiesDialogComponent {
reader.readAsText(file, 'UTF-8'); reader.readAsText(file, 'UTF-8');
reader.onload = async (readerEvent) => { reader.onload = async (readerEvent) => {
const fileContent = readerEvent.target.result as string; const fileContent = readerEvent.target?.result as string;
const fileExtension = file.name.split('.').pop()?.toLowerCase(); const fileExtension = file.name.split('.').pop()?.toLowerCase();
try { try {

Loading…
Cancel
Save