Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Support enter key press to submit access dialog form (#2437)

Sanjeev Sharmaf47c7313af7d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07b89aea6a..9acc0e0094 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Added
+
+- Supported enter key press to submit the form of the create or update access dialog
+
## 2.9.0 - 2023-10-08
### Added
diff --git a/apps/api/src/app/access/create-access.dto.ts b/apps/api/src/app/access/create-access.dto.ts
index 055cb66101..b9cf8892d4 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?: 'PUBLIC';
}
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 1727191e8f..2aa38f4d70 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<void>();
public constructor(
+ @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccessDialogParams,
public dialogRef: MatDialogRef<CreateOrUpdateAccessDialog>,
- @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 5142a7f6b5..c2afc51fba 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,33 +1,38 @@
-<form #addAccessForm="ngForm" class="d-flex flex-column h-100">
+<form
+ class="d-flex flex-column h-100"
+ [formGroup]="accessForm"
+ (keyup.enter)="accessForm.valid && onSubmit()"
+ (ngSubmit)="onSubmit()"
+>
<h1 i18n mat-dialog-title>Grant access</h1>
<div class="flex-grow-1 py-3" mat-dialog-content>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Alias</mat-label>
<input
+ formControlName="alias"
matInput
- name="alias"
type="text"
- [(ngModel)]="data.access.alias"
+ (keydown.enter)="$event.stopPropagation()"
/>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Type</mat-label>
- <mat-select name="type" required [(value)]="data.access.type">
+ <mat-select formControlName="type">
<mat-option i18n value="PUBLIC">Public</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div class="justify-content-end" mat-dialog-actions>
- <button i18n mat-button (click)="onCancel()">Cancel</button>
+ <button i18n mat-button type="button" (click)="onCancel()">Cancel</button>
<button
color="primary"
mat-flat-button
- [disabled]="!addAccessForm.form.valid"
- [mat-dialog-close]="data"
+ type="submit"
+ [disabled]="!accessForm.valid"
>
<ng-container i18n>Save</ng-container>
</button>