From 38759d1e6c2a3ea1baf737e47333d6b736e74d8d Mon Sep 17 00:00:00 2001 From: Sanjeev Sharma <29539278+thesanjeevsharma@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:01:17 +0530 Subject: [PATCH] feat: use FormBuilder for access form --- apps/api/src/app/access/create-access.dto.ts | 4 ++ ...reate-or-update-access-dialog.component.ts | 23 ++++++- .../create-or-update-access-dialog.html | 68 ++++++++++--------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/apps/api/src/app/access/create-access.dto.ts b/apps/api/src/app/access/create-access.dto.ts index 055cb6610..c3dad1109 100644 --- a/apps/api/src/app/access/create-access.dto.ts +++ b/apps/api/src/app/access/create-access.dto.ts @@ -8,4 +8,8 @@ export class CreateAccessDto { @IsOptional() @IsString() granteeUserId?: string; + + @IsOptional() + @IsString() + type?: string; } diff --git a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts index 1727191e8..2aa38f4d7 100644 --- a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts +++ b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts @@ -4,7 +4,9 @@ import { Inject, OnDestroy } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto'; import { Subject } from 'rxjs'; import { CreateOrUpdateAccessDialogParams } from './interfaces/interfaces'; @@ -17,19 +19,36 @@ import { CreateOrUpdateAccessDialogParams } from './interfaces/interfaces'; templateUrl: 'create-or-update-access-dialog.html' }) export class CreateOrUpdateAccessDialog implements OnDestroy { + public accessForm: FormGroup; + private unsubscribeSubject = new Subject(); public constructor( + @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccessDialogParams, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccessDialogParams + private formBuilder: FormBuilder ) {} - ngOnInit() {} + ngOnInit() { + this.accessForm = this.formBuilder.group({ + alias: [this.data.access.alias], + type: [this.data.access.type, Validators.required] + }); + } public onCancel() { this.dialogRef.close(); } + public onSubmit() { + const access: CreateAccessDto = { + alias: this.accessForm.controls['alias'].value, + type: this.accessForm.controls['type'].value + }; + + this.dialogRef.close({ access }); + } + public ngOnDestroy() { this.unsubscribeSubject.next(); this.unsubscribeSubject.complete(); diff --git a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html index 5142a7f6b..cf3b44e5e 100644 --- a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html +++ b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.html @@ -1,35 +1,39 @@ -
-

Grant access

-
-
- - Alias - - + +

Grant access

+
+
+ + Alias + + +
+
+ + Type + + Public + + +
-
- - Type - - Public - - +
+ +
-
-
- - -