mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merged PR 1200: #3050 Customer Online Email Adress Validation Fix
#3050 Customer Online Email Adress Validation Fix
This commit is contained in:
committed by
Andreas Schickinger
parent
4e9b4064a6
commit
3785ad614f
@@ -135,7 +135,7 @@ export class CustomerCreateOnlineComponent extends CustomerCreateComponentBase i
|
||||
email: fb.control(
|
||||
customer?.communicationDetails?.email,
|
||||
[Validators.required, validateEmail, this.emailDomainErrorValidator],
|
||||
[this.emailExistsValidator]
|
||||
[this.emailExistsValidator()]
|
||||
),
|
||||
phone: fb.control(customer?.communicationDetails?.phone, [UiValidators.phone]),
|
||||
mobile: fb.control(customer?.communicationDetails?.mobile, [UiValidators.phone]),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { AbstractControl, AsyncValidatorFn, FormArray, FormGroup, ValidationErrors, Validators } from '@angular/forms';
|
||||
import { AbstractControl, AsyncValidatorFn, FormArray, FormGroup, Validators } from '@angular/forms';
|
||||
import { ActivatedRoute, Params, Router } from '@angular/router';
|
||||
import { CrmCustomerService } from '@domain/crm';
|
||||
import { CountryDTO, CustomerDTO, InputOptionsDTO, KeyValueDTOOfStringAndString } from '@swagger/crm';
|
||||
import { Observable } from 'rxjs';
|
||||
import { first, map } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { catchError, debounceTime, distinctUntilChanged, first, map, switchMap } from 'rxjs/operators';
|
||||
import { UiModalService } from '@ui/modal';
|
||||
import { BreadcrumbService } from '@core/breadcrumb';
|
||||
import { ApplicationService } from '@core/application';
|
||||
@@ -14,17 +14,32 @@ import { isBoolean } from '@utils/common';
|
||||
import { setInvalidPropertyErrors } from '@ui/validators';
|
||||
import { camelCase } from 'lodash';
|
||||
import { validateEmail } from '../validators/email-validator';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
export abstract class CustomerCreateComponentBase {
|
||||
emailExistsValidator: AsyncValidatorFn = async (control): Promise<ValidationErrors | null> => {
|
||||
if (control.value) {
|
||||
if ((await this.customerService.emailExists(control.value).toPromise())?.result) {
|
||||
return { exists: 'E-Mail existiert bereits' };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
emailExistsValidator(): AsyncValidatorFn {
|
||||
return (control) =>
|
||||
control.valueChanges.pipe(
|
||||
debounceTime(500),
|
||||
distinctUntilChanged(),
|
||||
switchMap((value) => this.customerService.emailExists(value)),
|
||||
map((result) => {
|
||||
if (result?.result) {
|
||||
return { exists: result?.message ? result.message : 'E-Mail existiert bereits' };
|
||||
}
|
||||
}),
|
||||
catchError((error) => {
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
if (error?.error?.invalidProperties?.email) {
|
||||
return of({ invalid: error.error.invalidProperties.email });
|
||||
} else {
|
||||
return of({ invalid: 'E-Mail ist ungültig' });
|
||||
}
|
||||
}
|
||||
}),
|
||||
first()
|
||||
);
|
||||
}
|
||||
|
||||
type: string;
|
||||
control: FormGroup;
|
||||
|
||||
Reference in New Issue
Block a user