diff --git a/apps/client/src/app/components/admin-tag/admin-tag.component.ts b/apps/client/src/app/components/admin-tag/admin-tag.component.ts index a8bb7720a..787d2274d 100644 --- a/apps/client/src/app/components/admin-tag/admin-tag.component.ts +++ b/apps/client/src/app/components/admin-tag/admin-tag.component.ts @@ -142,9 +142,7 @@ export class AdminTagComponent implements OnInit, OnDestroy { dialogRef .afterClosed() .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((data) => { - const tag: CreateTagDto = data?.tag; - + .subscribe((tag: CreateTagDto) => { if (tag) { this.adminService .postTag(tag) diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts index aaa5a0221..014934cd5 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.component.ts @@ -1,4 +1,13 @@ -import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; +import { CreateTagDto } from '@ghostfolio/api/app/tag/create-tag.dto'; +import { validateObjectForForm } from '@ghostfolio/client/util/form.util'; + +import { + ChangeDetectionStrategy, + Component, + Inject, + OnDestroy +} from '@angular/core'; +import { FormBuilder, FormGroup } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Subject } from 'rxjs'; @@ -11,13 +20,36 @@ import { CreateOrUpdateTagDialogParams } from './interfaces/interfaces'; styleUrls: ['./create-or-update-tag-dialog.scss'], templateUrl: 'create-or-update-tag-dialog.html' }) -export class CreateOrUpdateTagDialog { +export class CreateOrUpdateTagDialog implements OnDestroy { + public tagForm: FormGroup; private unsubscribeSubject = new Subject(); public constructor( @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTagDialogParams, - public dialogRef: MatDialogRef - ) {} + public dialogRef: MatDialogRef, + private formBuilder: FormBuilder + ) { + this.tagForm = this.formBuilder.group({ + name: [this.data.tag.name] + }); + } + + public async onSubmit() { + try { + const tag: CreateTagDto = { + name: this.tagForm.get('name')?.value + }; + + await validateObjectForForm({ + classDto: CreateTagDto, + form: this.tagForm, + object: tag + }); + this.dialogRef.close(tag); + } catch (error) { + console.error(error); + } + } public onCancel() { this.dialogRef.close(); diff --git a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html index c2e8f4ee1..02583c365 100644 --- a/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html +++ b/apps/client/src/app/components/admin-tag/create-or-update-tag-dialog/create-or-update-tag-dialog.html @@ -1,11 +1,20 @@ -
+

Update tag

Add tag

Name - +
@@ -14,8 +23,8 @@