get all users on save

-get all users on save
-show correct erros according to errorCode
-add hid-show on password input field
-update constants
mazdak/UI-transcation-form
Mazdak Gibran 1 month ago
parent 139f5e7384
commit 3b0862fd25

@ -182,8 +182,10 @@
</label> </label>
<div class="w-100"> <div class="w-100">
<div class="password-wrapper"> <div class="password-wrapper">
<input type="password" id="SUS_PASSWORD" class="form-control" formControlName="SUS_PASSWORD" <input [type]="passwordType" id="SUS_PASSWORD" class="form-control" formControlName="SUS_PASSWORD"
placeholder="{{ 'SUS_PASSWORD' | translate }}" appNoWhitespaces /> placeholder="{{ 'SUS_PASSWORD' | translate }}" appNoWhitespaces />
<app-password-hide-show #passShowMenu class="password-eye align-items" [showPassword]="true"
(onEyeClick)="toggleSetupPass()"></app-password-hide-show>
</div> </div>
<div class="text-danger" <div class="text-danger"
*ngIf="thirdPartyForm.get('SUS_PASSWORD')?.touched && thirdPartyForm.get('SUS_PASSWORD')?.invalid"> *ngIf="thirdPartyForm.get('SUS_PASSWORD')?.touched && thirdPartyForm.get('SUS_PASSWORD')?.invalid">
@ -234,6 +236,7 @@
<input type="tel" id="SUS_USERCELLNO" class="form-control" <input type="tel" id="SUS_USERCELLNO" class="form-control"
formControlName="SUS_USERCELLNO" formControlName="SUS_USERCELLNO"
placeholder="{{ 'SUS_USERCELLNO' | translate }}" placeholder="{{ 'SUS_USERCELLNO' | translate }}"
(keypress)="onlyNumbers($event)"
appNoWhitespaces /> appNoWhitespaces />
<div class="text-danger" <div class="text-danger"
*ngIf="thirdPartyForm.get('SUS_USERCELLNO')?.touched && thirdPartyForm.get('SUS_USERCELLNO')?.invalid"> *ngIf="thirdPartyForm.get('SUS_USERCELLNO')?.touched && thirdPartyForm.get('SUS_USERCELLNO')?.invalid">

@ -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 { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
import { PermissionNode } from '../utils/app.interfaces'; import { PermissionNode } from '../utils/app.interfaces';
import { CredentialService } from '../services/credential.service'; import { CredentialService } from '../services/credential.service';
@ -10,12 +10,14 @@ import { HttpErrorResponse, HttpParams } from '@angular/common/http';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgSelectModule } from '@ng-select/ng-select'; import { NgSelectModule } from '@ng-select/ng-select';
import { filter, Observable, take } from 'rxjs'; import { filter, Observable, take } from 'rxjs';
import { SuccessMessages } from '../utils/enums'; import { ErrorMessages, SuccessMessages } from '../utils/enums';
import { URIService } from '../app.uri'; import { URIService } from '../app.uri';
import { PasswordHideShowComponent } from '../shared/components/password-hide-show/password-hide-show.component';
import { error } from 'console';
@Component({ @Component({
selector: 'app-menu', selector: 'app-menu',
imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule], imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule, PasswordHideShowComponent],
templateUrl: './menu.component.html', templateUrl: './menu.component.html',
styleUrl: './menu.component.scss' styleUrl: './menu.component.scss'
}) })
@ -26,8 +28,10 @@ export class MenuComponent {
showPermissions = false; showPermissions = false;
permissions: PermissionNode[] = []; permissions: PermissionNode[] = [];
saving = false; saving = false;
passwordType: string = 'password';
menuItems: { endpoint: string; checked: boolean }[] = []; menuItems: { endpoint: string; checked: boolean }[] = [];
@ViewChild('passShowMenu') passwordHideShow?: PasswordHideShowComponent;
constructor( constructor(
private credentialService: CredentialService, private credentialService: CredentialService,
private fb: FormBuilder, private fb: FormBuilder,
@ -48,6 +52,9 @@ export class MenuComponent {
this.loadTransactionEndpoints(); this.loadTransactionEndpoints();
this.createThirdPartyUserForm(); this.createThirdPartyUserForm();
} }
toggleSetupPass() {
this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text';
}
createThirdPartyUserForm(): void{ createThirdPartyUserForm(): void{
this.thirdPartyForm = this.fb.group({ this.thirdPartyForm = this.fb.group({
@ -61,14 +68,22 @@ export class MenuComponent {
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/) Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
]], ]],
SUS_EMAIL: ["", [Validators.required, Validators.email]], SUS_EMAIL: ["", [Validators.required, Validators.email]],
SUS_USERCELLNO: ["", [Validators.required]], SUS_USERCELLNO: ["", [
Validators.required,
Validators.pattern(/^[0-9]+$/)
]],
POR_ORGACODE: [this.credentialService.getPorOrgacode()], POR_ORGACODE: [this.credentialService.getPorOrgacode()],
SUS_ACTIVE: [true], SUS_ACTIVE: [true],
SUS_THIRDPARTY: [true], SUS_THIRDPARTY: [true],
}) })
} }
onlyNumbers(event: KeyboardEvent) {
const charCode = event.which ? event.which : event.keyCode;
if (charCode < 48 || charCode > 57) {
event.preventDefault();
}
}
submitForm() { submitForm() {
if (this.thirdPartyForm.invalid) { if (this.thirdPartyForm.invalid) {
this.thirdPartyForm.markAllAsTouched(); this.thirdPartyForm.markAllAsTouched();
@ -102,12 +117,28 @@ export class MenuComponent {
if (!(response instanceof HttpErrorResponse)) { if (!(response instanceof HttpErrorResponse)) {
this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []); this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []);
this.createThirdPartyUserForm(); this.createThirdPartyUserForm();
this.getAllUsers();
this.permission.reset();
this.showPermissions = false;
} }
} },
// handle error codes e.g. ERR_TRX_0006 error: (error: any) => {
// Once backend is ready, check response for errorCode field const errorCode = error?.error?.errorCode || error?.errorCode;
// e.g. if (response?.errorCode === 'ERR_TRX_0006') { show error }
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', []);
}
}
}); });
} }

@ -12,6 +12,8 @@ export enum ErrorMessages{
USER_FETCH_FAILED = "USER_FETCH_FAILED", USER_FETCH_FAILED = "USER_FETCH_FAILED",
RESET_PASSWORD_FAILED = "RESET_PASSWORD_FAILED", RESET_PASSWORD_FAILED = "RESET_PASSWORD_FAILED",
CHANGE_PASSWORD_FAILED = "ERR_SEC_0007", CHANGE_PASSWORD_FAILED = "ERR_SEC_0007",
EMAIL_ALREADY_EXISTS = "ERR_SEC_0001",
USERNAME_ALREADY_EXISTS = "ERR_SEC_0002"
} }

@ -254,7 +254,7 @@
"noThirdPartyRegFound": "No Third Party Registration Details Found", "noThirdPartyRegFound": "No Third Party Registration Details Found",
"ERR_SEC_0001": "Email already exists", "ERR_SEC_0001": "Email already exists",
"ERR_SEC_0007": "New password cannot be same as old password", "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_0003": "Old Password is not correct",
"ERR_SEC_0004": "Invalid credentials", "ERR_SEC_0004": "Invalid credentials",
"ERR_SEC_0005": "User not found", "ERR_SEC_0005": "User not found",

Loading…
Cancel
Save