mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merge branch 'develop' of ssh.dev.azure.com:v3/hugendubel/ISA/ISA-Frontend into develop
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { Location } from '@angular/common';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { ChangeDetectorRef, Component, inject, OnInit } from '@angular/core';
|
||||
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import {
|
||||
AbstractControl,
|
||||
UntypedFormBuilder,
|
||||
UntypedFormGroup,
|
||||
ValidatorFn,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { CrmCustomerService } from '@domain/crm';
|
||||
import { CountryDTO, CustomerDTO, KeyValueDTOOfStringAndString } from '@generated/swagger/crm-api';
|
||||
@@ -9,17 +15,14 @@ import { UiValidators } from '@ui/validators';
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { first, map, switchMap } from 'rxjs/operators';
|
||||
import { validateEmail } from '../../validators/email-validator';
|
||||
import { genderLastNameValidator } from '../../validators/gender-b2b-validator';
|
||||
import { requiredIfControlIsSet } from '../../validators/gender-b2b-validator';
|
||||
import { camelCase } from 'lodash';
|
||||
import { CustomerSearchStore } from '../store';
|
||||
import { CustomerSearchNavigation, NavigationRoute } from '@shared/services/navigation';
|
||||
import { zipCodeValidator } from '../../validators/zip-code-validator';
|
||||
import { GenderSettingsService } from '@shared/services/gender';
|
||||
|
||||
@Component({
|
||||
template: '',
|
||||
standalone: false,
|
||||
})
|
||||
@Component({ template: '' })
|
||||
export abstract class CustomerDataEditComponent implements OnInit {
|
||||
private customerService = inject(CrmCustomerService);
|
||||
private activatedRoute = inject(ActivatedRoute);
|
||||
@@ -64,7 +67,10 @@ export abstract class CustomerDataEditComponent implements OnInit {
|
||||
const enabledFeatures = Object.values(customer.features).filter((f) => f.enabled);
|
||||
const b2bFeature = customer?.features?.find((f) => f?.key === 'b2b');
|
||||
const isB2B = enabledFeatures?.every(
|
||||
(f) => f?.key === 'd-account' && f?.description?.toLowerCase()?.includes('business') && b2bFeature,
|
||||
(f) =>
|
||||
f?.key === 'd-account' &&
|
||||
f?.description?.toLowerCase()?.includes('business') &&
|
||||
b2bFeature,
|
||||
);
|
||||
return isB2B ? [b2bFeature, ...enabledFeatures] : enabledFeatures;
|
||||
}),
|
||||
@@ -73,18 +79,27 @@ export abstract class CustomerDataEditComponent implements OnInit {
|
||||
this.customerType$ = this.customerFeatures$.pipe(
|
||||
map(
|
||||
(features: KeyValueDTOOfStringAndString[]) =>
|
||||
features.find((f) => f.key === 'store' || f.key === 'webshop' || f.key === 'b2b' || f.key === 'guest')?.key,
|
||||
features.find(
|
||||
(f) => f.key === 'store' || f.key === 'webshop' || f.key === 'b2b' || f.key === 'guest',
|
||||
)?.key,
|
||||
),
|
||||
);
|
||||
this.isOnlineOrCustomerCardUser$ = combineLatest([this.customerType$, this.customerFeatures$]).pipe(
|
||||
this.isOnlineOrCustomerCardUser$ = combineLatest([
|
||||
this.customerType$,
|
||||
this.customerFeatures$,
|
||||
]).pipe(
|
||||
map(
|
||||
([type, features]) =>
|
||||
type === 'webshop' ||
|
||||
!!features?.find((feature) => feature?.key === 'p4muser' || feature?.key === 'd-account'),
|
||||
),
|
||||
);
|
||||
this.isWebshopOrGuest$ = this.customerType$.pipe(map((type) => type === 'webshop' || type === 'guest'));
|
||||
this.customerFeatureB2bOrB2c$ = this.customerType$.pipe(map((type) => (type === 'b2b' ? 'b2b' : 'b2c')));
|
||||
this.isWebshopOrGuest$ = this.customerType$.pipe(
|
||||
map((type) => type === 'webshop' || type === 'guest'),
|
||||
);
|
||||
this.customerFeatureB2bOrB2c$ = this.customerType$.pipe(
|
||||
map((type) => (type === 'b2b' ? 'b2b' : 'b2c')),
|
||||
);
|
||||
this.countries$ = this.isWebshopOrGuest$.pipe(
|
||||
switchMap((webshopOrGuest) => {
|
||||
if (!webshopOrGuest) {
|
||||
@@ -113,11 +128,19 @@ export abstract class CustomerDataEditComponent implements OnInit {
|
||||
const isBranch = customerType === 'store';
|
||||
const isWebshop = customerType === 'webshop';
|
||||
const isCard = customerFeatures.find((feature) => feature.key === 'p4muser');
|
||||
|
||||
const zipCodeValidators =
|
||||
(isWebshop && isCard) || isWebshop || isB2b ? [Validators.required, zipCodeValidator()] : []; // #2573 Validierung nur für Onlinekonto, Onlinekonto+Kundenkarte, Business Konto
|
||||
|
||||
const genderValidators: ValidatorFn[] = [];
|
||||
|
||||
if (!isB2b) {
|
||||
genderValidators.push(Validators.required);
|
||||
}
|
||||
|
||||
this.control = fb.group(
|
||||
{
|
||||
gender: fb.control(customerDTO?.gender, [isBranch ? Validators.required : () => null]),
|
||||
gender: fb.control(customerDTO?.gender, genderValidators),
|
||||
title: fb.control(customerDTO?.title),
|
||||
lastName: fb.control(customerDTO?.lastName, [Validators.required]),
|
||||
firstName: fb.control(customerDTO?.firstName, [Validators.required]),
|
||||
@@ -144,7 +167,10 @@ export abstract class CustomerDataEditComponent implements OnInit {
|
||||
info: fb.control(customerDTO?.address?.info),
|
||||
}),
|
||||
},
|
||||
{ validators: genderLastNameValidator(isB2b) },
|
||||
{
|
||||
// #1461 KKM/ISA: Anrede als Pflichtfeld
|
||||
validators: [requiredIfControlIsSet('gender', 'lastName')],
|
||||
},
|
||||
);
|
||||
|
||||
if (typeof this.afterInitForm === 'function') {
|
||||
@@ -178,7 +204,10 @@ export abstract class CustomerDataEditComponent implements OnInit {
|
||||
const invProps = error.error.invalidProperties;
|
||||
const keys = Object.keys(invProps);
|
||||
for (const key of keys) {
|
||||
this.control.get('address')?.get(camelCase(key))?.setErrors({ validateAddress: invProps[key] });
|
||||
this.control
|
||||
.get('address')
|
||||
?.get(camelCase(key))
|
||||
?.setErrors({ validateAddress: invProps[key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { UntypedFormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
|
||||
|
||||
export function genderLastNameValidator(isB2b: boolean): ValidatorFn | null {
|
||||
if (isB2b) {
|
||||
return (control: UntypedFormGroup): ValidationErrors | null => {
|
||||
const gender = control.get('gender').value;
|
||||
const lastName = control.get('lastName').value;
|
||||
if (lastName) {
|
||||
control.get('gender').setValidators([Validators.required]);
|
||||
return { genderNotSet: true };
|
||||
} else {
|
||||
control.get('gender').setValidators(null);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
export function requiredIfControlIsSet(
|
||||
requiredControlName: string,
|
||||
ifSetControlName: string,
|
||||
): ValidatorFn {
|
||||
return (control: UntypedFormGroup): ValidationErrors | null => {
|
||||
const requiredControl = control.get(requiredControlName);
|
||||
const ifSetControl = control.get(ifSetControlName);
|
||||
|
||||
if (ifSetControl && ifSetControl.value) {
|
||||
return Validators.required(requiredControl);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user