Anpassung für Kundenupgrade von Filial zu Onlinekunden

This commit is contained in:
Lorenz Hilpert
2021-01-22 14:45:44 +01:00
parent 5b6e5d05fc
commit 54f0d16767
3 changed files with 27 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ import { CrmCustomerService } from '@domain/crm';
import { CustomerDTO } from '@swagger/crm';
import { UiValidators } from '@ui/common';
import { UiModalService } from '@ui/modal';
import { Observable } from 'rxjs';
import { filter, map, shareReplay, switchMap, take } from 'rxjs/operators';
import { AddressSelectionModalService } from '../modals/address-selection-modal.service';
import { validateEmail } from '../validators/email-validator';
import { CustomerCreateComponentBase } from './customer-create.component';
@@ -18,6 +20,9 @@ import { CustomerCreateComponentBase } from './customer-create.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomerCreateOnlineComponent extends CustomerCreateComponentBase implements OnInit {
upgradeCustomerId: number;
upgradeCustomer: CustomerDTO;
constructor(
public activatedRoute: ActivatedRoute,
public router: Router,
@@ -33,6 +38,20 @@ export class CustomerCreateOnlineComponent extends CustomerCreateComponentBase i
ngOnInit(): void {
this.init();
this.upgradeCustomerId = Number(this.activatedRoute.snapshot.queryParams.upgradeCustomerId);
if (!isNaN(this.upgradeCustomerId)) {
this.customerService
.getCustomer(this.upgradeCustomerId, 2)
.pipe(map((response) => response.result))
.subscribe((custoemr) => {
this.upgradeCustomer = custoemr;
this.control.patchValue(custoemr);
this.control.updateValueAndValidity();
this.control.markAllAsTouched();
});
}
}
createControl(customer?: CustomerDTO): FormGroup {
@@ -75,7 +94,12 @@ export class CustomerCreateOnlineComponent extends CustomerCreateComponentBase i
}
try {
const response = await this.customerService.createOnlineCustomer(this.control.value).toPromise();
let newCustomer: CustomerDTO = this.control.value;
if (this.upgradeCustomer) {
newCustomer = { ...newCustomer, ...this.upgradeCustomer };
}
const response = await this.customerService.createOnlineCustomer(newCustomer).toPromise();
if (response.error) {
throw new Error(response.message);

View File

@@ -6,7 +6,6 @@ import { CustomerCreateGuestComponent } from './customer-create/customer-create-
import { CustomerCreateOnlineComponent } from './customer-create/customer-create-online.component';
import { PayerCreateB2BComponent } from './customer-details/address/payer-create/payer-create-b2b.component';
import { PayerCreateB2CComponent } from './customer-details/address/payer-create/payer-create-b2c.component';
import { PayerCreateComponent } from './customer-details/address/payer-create/payer-create.component';
import { PayerEditB2BComponent } from './customer-details/address/payer-edit/payer-edit-b2b.component';
import { PayerEditB2CComponent } from './customer-details/address/payer-edit/payer-edit-b2c.component';
import { ShippingCreateB2BComponent } from './customer-details/address/shipping-create/shipping-create-b2b.component';
@@ -16,7 +15,6 @@ import { ShippingEditB2CComponent } from './customer-details/address/shipping-ed
import { CustomerCardComponent } from './customer-details/customer-card/customer-card.component';
import { CustomerDataEditB2BComponent } from './customer-details/customer-data-edit/customer-data-edit-b2b.component';
import { CustomerDataEditB2CComponent } from './customer-details/customer-data-edit/customer-data-edit-b2c.component';
import { CustomerDataEditComponent } from './customer-details/customer-data-edit/customer-data-edit.component';
import { CustomerDetailsComponent } from './customer-details/customer-details.component';
import { CustomerSearchComponent } from './customer-search/customer-search.component';
import { CustomerSearchMainComponent } from './customer-search/search-main/search-main.component';

View File

@@ -131,9 +131,9 @@ export class DeliveryCartComponent implements OnInit, OnDestroy {
if (deliveryExist && missingAddress) {
this.store.dispatch(new UpdateCustomerFormState(CustomerFormState.MISSING_DELIVERY));
const currentRoute = `customer/search/missing-data/${processCart.customer.id}`;
const currentRoute = `customer/create/online`;
this.store.dispatch(new ChangeCurrentRoute(currentRoute));
this.router.navigate([currentRoute], { queryParams: { card: 'create' } });
this.router.navigate([currentRoute], { queryParams: { updateCustomerId: processCart.customer.id } });
return false;
}
return true;