#1561 Country bei Wechsel mit leerer Adresse nicht aus QueryParams übernehmen, isStringEmpty ausgelagert, Adresszusatz aus Prüfung entfernt

This commit is contained in:
Andreas Schickinger
2021-03-24 17:28:57 +01:00
committed by Lorenz Hilpert
parent e70eea0271
commit eabba753a1
3 changed files with 19 additions and 19 deletions

View File

@@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { ApplicationService } from '@core/application';
import { BreadcrumbService } from '@core/breadcrumb';
import { CrmCustomerService } from '@domain/crm';
import { CustomerDTO } from '@swagger/crm';
import { AddressDTO, CustomerDTO } from '@swagger/crm';
import { UiModalService } from '@ui/modal';
import { AddressSelectionModalService } from '../modals/address-selection-modal/address-selection-modal.service';
import { CustomerCreateComponentBase } from './customer-create.component';
@@ -12,7 +12,7 @@ import { validateEmail } from '../validators/email-validator';
import { Subscription } from 'rxjs';
import { DomainCheckoutService } from '@domain/checkout';
import { UiValidators, setInvalidPropertyErrors } from '@ui/validators';
import { isEmptyString } from 'apps/sales/src/app/core/utils/app.utils';
import { isStringEmpty } from '@utils/common';
@Component({
selector: 'page-customer-create-branch',
@@ -66,24 +66,20 @@ export class CustomerCreateBranchComponent extends CustomerCreateComponentBase i
}
});
this.addressSubscription = this.addressGroup.valueChanges.subscribe(
(value: { street: string; streetNumber: string; zipCode: string; city: string; info: string; country: string }) => {
if (value) {
const country = this.addressGroup.get('country');
if (!country.value) {
country.setValue('DEU');
} else if (
isEmptyString(value.street) &&
isEmptyString(value.streetNumber) &&
isEmptyString(value.zipCode) &&
isEmptyString(value.city) &&
isEmptyString(value.info)
) {
country.setValue('', { onlySelf: true });
}
this.addressSubscription = this.addressGroup.valueChanges.subscribe((value: AddressDTO) => {
if (value) {
const country = this.addressGroup.get('country');
if (!country.value) {
country.setValue('DEU');
} else if (this.isAddressEmpty(value)) {
country.setValue('', { onlySelf: true });
}
}
);
});
}
isAddressEmpty(value: AddressDTO): boolean {
return isStringEmpty(value.street) && isStringEmpty(value.streetNumber) && isStringEmpty(value.zipCode) && isStringEmpty(value.city);
}
ngOnDestroy(): void {
@@ -119,7 +115,7 @@ export class CustomerCreateBranchComponent extends CustomerCreateComponentBase i
streetNumber: fb.control(customer?.address?.streetNumber),
zipCode: fb.control(customer?.address?.zipCode),
city: fb.control(customer?.address?.city),
country: fb.control(customer?.address?.country),
country: fb.control(!this.isAddressEmpty(customer?.address) ? customer?.address?.country : ''),
info: fb.control(customer?.address?.info),
}),
communicationDetails: fb.group({

View File

@@ -4,5 +4,6 @@ export * from './is-boolean';
export * from './is-null-or-undefined';
export * from './is-number';
export * from './is-string';
export * from './is-string-empty';
export * from './memorize.decorator';
// end:ng42.barrel

View File

@@ -0,0 +1,3 @@
export function isStringEmpty(value: string): boolean {
return value === null || value === undefined || value === '';
}