diff --git a/src/app/menu/menu.component.html b/src/app/menu/menu.component.html index 782a6a4..3a17e7d 100644 --- a/src/app/menu/menu.component.html +++ b/src/app/menu/menu.component.html @@ -1,67 +1,299 @@ -
+
+
- -
-
-
- -
- - - -
- {{ item.userName }} - {{ item.userId }} -
-
- - - {{ item.userName }} ({{ item.userId }}) - -
-
-
-
+
+
+
+
+ +
+
-
+ +
-

{{ "menu" | translate }}

- -
- - - - - - - - - - - +
+
+
+
+
+
+ {{ "userPermission" | translate }} +
+
+ + +
+
+
+ +
+ + +
+ {{ item.userName }} + {{ item.userId }} +
+
+ + {{ item.userName }} ({{ item.userId }}) + +
+
+ +
+
+ + +
+
+

{{ "menu" | translate }}

+
+
#{{ "type" | translate }}{{ "allow" | translate }}
+ + + + + + + + - - - + + + - - -
#{{ "type" | translate }}{{ "allow" | translate }}
{{ i + 1 }}{{ item.endpoint | translate }}{{ i + 1 }}{{ item.endpoint | translate }} + +
+ + +
+
+ +
+
+
+ +
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ {{ "createThirdPartyUser" | translate }} +
+
-
- +
+ +
+ +
+
+ +
+ +
+
+ {{ "fieldRequired" | translate }} +
+
+
+
+
+ + +
+
+ +
+ +
+
+ {{ "fieldRequired" | translate }} +
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+ {{ "fieldRequired" | translate }} +
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+
+ {{ "fieldRequired" | translate }} +
+
+ {{ "passwordPattern" | translate }} +
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+
+ {{ "fieldRequired" | translate }} +
+
+ {{ "invalidEmail" | translate }} +
+
+
+
+
+ + +
+
+ +
+ +
+
+ {{ "fieldRequired" | translate }} +
+
+
+
+
+
+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+ +
+ +
+
+
+
+
+
+
- \ No newline at end of file + + + + + \ No newline at end of file diff --git a/src/app/menu/menu.component.ts b/src/app/menu/menu.component.ts index 8de6097..03a0e01 100644 --- a/src/app/menu/menu.component.ts +++ b/src/app/menu/menu.component.ts @@ -1,5 +1,5 @@ -import { Component } from '@angular/core'; -import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms'; +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'; import { I18NService } from '../services/i18n.service'; @@ -10,23 +10,28 @@ 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, CommonModule, TranslateModule, NgSelectModule, FormsModule], + imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule, PasswordHideShowComponent], templateUrl: './menu.component.html', styleUrl: './menu.component.scss' }) export class MenuComponent { users: any[] = []; + thirdPartyForm!: FormGroup; permission: FormGroup; 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, @@ -38,12 +43,103 @@ export class MenuComponent { this.defaultPermissions().subscribe((data: PermissionNode[]) => { this.permissions = data; }); + + } ngOnInit() { this.getAllUsers(); this.loadTransactionEndpoints(); + this.createThirdPartyUserForm(); + } + toggleSetupPass() { + this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text'; + } + + createThirdPartyUserForm(): void{ + this.thirdPartyForm = this.fb.group({ + SUS_USERCODE: ["", [Validators.required]], + SUS_EMPCODE: ["", [Validators.required]], + SUS_NAME: ["", [Validators.required]], + SUS_PASSWORD: ['', [ + Validators.required, + Validators.minLength(8), + Validators.maxLength(20), + Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/) + ]], + SUS_EMAIL: ["", [Validators.required, Validators.email]], + SUS_USERCELLNO: ["", [ + Validators.required, + ]], + 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(); + return; + } + + const f = this.thirdPartyForm.value; + const payload = { + formId: "SH_SM_US_USER", + postProcessFormId: "SH_SM_US_USER", + workFlowId: null, + operation: "nonwizard", + porOrgacode: this.credentialService.getPorOrgacode(), + usercode: this.credentialService.getUserId(), + uniqueConstraints: [["SUS_USERCODE", "POR_ORGACODE"]], + formCounters: [], + susUsercode: f.SUS_USERCODE, + susName: f.SUS_NAME, + susEmpcode: f.SUS_EMPCODE, + susPassword: f.SUS_PASSWORD, + susEmail: f.SUS_EMAIL, + susUsercellno: f.SUS_USERCELLNO, + susActive: f.SUS_ACTIVE, + susThirdparty: f.SUS_THIRDPARTY, + } + + console.log("payload",payload ) + this.httpService.requestPOST(URIKey.CREATE_THIRD_PARTY_USER, payload) + .subscribe({ + next: (response: any) => { + if (!(response instanceof HttpErrorResponse)) { + this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []); + this.createThirdPartyUserForm(); + this.getAllUsers(); + this.permission.reset(); + this.showPermissions = false; + } + }, + + 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', []); + } + } + }); +} loadTransactionEndpoints() { this.httpService.requestGET(URIKey.TRANSACTION_ENDPOINTS).subscribe((response) => { @@ -127,7 +223,9 @@ savePermissions() { next: (response: any) => { if (!(response instanceof HttpErrorResponse)) { this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []); - this.onUserChange(); // this triggers one GET — expected + this.permission.reset(); + this.showPermissions = false; + this.menuItems.forEach(item => item.checked = false); } }, complete: () => { diff --git a/src/app/user-management/reset-password/reset-password.component.html b/src/app/user-management/reset-password/reset-password.component.html index 4b40e83..0f07890 100644 --- a/src/app/user-management/reset-password/reset-password.component.html +++ b/src/app/user-management/reset-password/reset-password.component.html @@ -73,7 +73,7 @@
-
+