diff --git a/src/app/core/admin/user-management/user-edit-dialog/user-edit-dialog.component.ts b/src/app/core/admin/user-management/user-edit-dialog/user-edit-dialog.component.ts index 1ed593e71..723ae247f 100644 --- a/src/app/core/admin/user-management/user-edit-dialog/user-edit-dialog.component.ts +++ b/src/app/core/admin/user-management/user-edit-dialog/user-edit-dialog.component.ts @@ -161,8 +161,17 @@ export class UserEditDialogComponent implements OnInit { }); } + private isValidEmail(email: string): boolean { + if (!email || email.trim() === '') return true; // email is optional + return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim()); + } + saveChanges(): void { - if (this.changePassword && this.newPassword !== '' ) { + if (this.user.user.email && !this.isValidEmail(this.user.user.email)) { + this.isError = true; + this.message = 'Email format is incorrect'; + return; + } else if (this.changePassword && this.newPassword !== '' ) { this.isError = true; this.message = 'Cancel or submit new password to save other changes'; } else if(!this.selectedRole || this.selectedRole===null || this.selectedRole.length ===0){ @@ -225,13 +234,18 @@ export class UserEditDialogComponent implements OnInit { this.message = 'Unable to edit user'; if (error.error) { this.isError = true; - this.message = error; + this.message = error.error.message || error.message || 'Unable to edit user'; } }); } addUser(): void { this.isError = false; + if (this.user.user.email && !this.isValidEmail(this.user.user.email)) { + this.isError = true; + this.message = 'Email format is incorrect'; + return; + } if (this.newPassword === this.newPasswordConfirm) { if(!this.selectedRole || this.selectedRole===null || this.selectedRole.length ===0){ this.message = "Please select a role for this user"; diff --git a/src/app/core/registrars/registrars.component.html b/src/app/core/registrars/registrars.component.html index 326c208d2..5636cf8be 100644 --- a/src/app/core/registrars/registrars.component.html +++ b/src/app/core/registrars/registrars.component.html @@ -297,7 +297,7 @@