diff --git a/src/app/menu/menu.component.html b/src/app/menu/menu.component.html index 145bab1..b154bb5 100644 --- a/src/app/menu/menu.component.html +++ b/src/app/menu/menu.component.html @@ -182,8 +182,10 @@
- + +
@@ -234,6 +236,7 @@
diff --git a/src/app/menu/menu.component.ts b/src/app/menu/menu.component.ts index bb0067f..a6fc206 100644 --- a/src/app/menu/menu.component.ts +++ b/src/app/menu/menu.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, ViewChild } from '@angular/core'; import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; import { PermissionNode } from '../utils/app.interfaces'; import { CredentialService } from '../services/credential.service'; @@ -10,12 +10,14 @@ import { HttpErrorResponse, HttpParams } from '@angular/common/http'; import { CommonModule } from '@angular/common'; import { NgSelectModule } from '@ng-select/ng-select'; import { filter, Observable, take } from 'rxjs'; -import { SuccessMessages } from '../utils/enums'; +import { ErrorMessages, SuccessMessages } from '../utils/enums'; import { URIService } from '../app.uri'; +import { PasswordHideShowComponent } from '../shared/components/password-hide-show/password-hide-show.component'; +import { error } from 'console'; @Component({ selector: 'app-menu', - imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule], + imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule, PasswordHideShowComponent], templateUrl: './menu.component.html', styleUrl: './menu.component.scss' }) @@ -26,8 +28,10 @@ export class MenuComponent { showPermissions = false; permissions: PermissionNode[] = []; saving = false; + passwordType: string = 'password'; menuItems: { endpoint: string; checked: boolean }[] = []; - + @ViewChild('passShowMenu') passwordHideShow?: PasswordHideShowComponent; + constructor( private credentialService: CredentialService, private fb: FormBuilder, @@ -48,6 +52,9 @@ export class MenuComponent { this.loadTransactionEndpoints(); this.createThirdPartyUserForm(); } + toggleSetupPass() { + this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text'; + } createThirdPartyUserForm(): void{ this.thirdPartyForm = this.fb.group({ @@ -61,14 +68,22 @@ export class MenuComponent { Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/) ]], SUS_EMAIL: ["", [Validators.required, Validators.email]], - SUS_USERCELLNO: ["", [Validators.required]], + SUS_USERCELLNO: ["", [ + Validators.required, + Validators.pattern(/^[0-9]+$/) + ]], POR_ORGACODE: [this.credentialService.getPorOrgacode()], SUS_ACTIVE: [true], SUS_THIRDPARTY: [true], }) } - + onlyNumbers(event: KeyboardEvent) { + const charCode = event.which ? event.which : event.keyCode; + if (charCode < 48 || charCode > 57) { + event.preventDefault(); + } +} submitForm() { if (this.thirdPartyForm.invalid) { this.thirdPartyForm.markAllAsTouched(); @@ -102,12 +117,28 @@ export class MenuComponent { if (!(response instanceof HttpErrorResponse)) { this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []); this.createThirdPartyUserForm(); + this.getAllUsers(); + this.permission.reset(); + this.showPermissions = false; } - } + }, - // handle error codes e.g. ERR_TRX_0006 - // Once backend is ready, check response for errorCode field - // e.g. if (response?.errorCode === 'ERR_TRX_0006') { show error } + error: (error: any) => { + const errorCode = error?.error?.errorCode || error?.errorCode; + + switch (errorCode) { + case 'ERR_SEC_0002': + this.i18nService.error(ErrorMessages.USERNAME_ALREADY_EXISTS, []); + break; + + case 'ERR_SEC_0001': + this.i18nService.error(ErrorMessages.EMAIL_ALREADY_EXISTS, []); + break; + + default: + this.i18nService.error('Unexpected error', []); + } + } }); } diff --git a/src/app/utils/enums.ts b/src/app/utils/enums.ts index 7f91996..12f36d4 100644 --- a/src/app/utils/enums.ts +++ b/src/app/utils/enums.ts @@ -12,6 +12,8 @@ export enum ErrorMessages{ USER_FETCH_FAILED = "USER_FETCH_FAILED", RESET_PASSWORD_FAILED = "RESET_PASSWORD_FAILED", CHANGE_PASSWORD_FAILED = "ERR_SEC_0007", + EMAIL_ALREADY_EXISTS = "ERR_SEC_0001", + USERNAME_ALREADY_EXISTS = "ERR_SEC_0002" } diff --git a/src/assets/i18n/English.json b/src/assets/i18n/English.json index 726ede2..f516c8d 100644 --- a/src/assets/i18n/English.json +++ b/src/assets/i18n/English.json @@ -254,7 +254,7 @@ "noThirdPartyRegFound": "No Third Party Registration Details Found", "ERR_SEC_0001": "Email already exists", "ERR_SEC_0007": "New password cannot be same as old password", - "ERR_SEC_0002": "User ID already exists", + "ERR_SEC_0002": "Username already exists", "ERR_SEC_0003": "Old Password is not correct", "ERR_SEC_0004": "Invalid credentials", "ERR_SEC_0005": "User not found",