mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
#4355 Lieferadresse bearbeiten nicht möglich
This commit is contained in:
@@ -49,7 +49,14 @@
|
||||
<span class="mr-4">
|
||||
{{ shippingAddress | address }}
|
||||
</span>
|
||||
<a *ngIf="canEditAddress$ | async" class="text-brand font-bold" type="button">
|
||||
<a
|
||||
*ngIf="editShippingAddressRoute$(shippingAddress.id) | async; let route"
|
||||
class="text-brand font-bold"
|
||||
type="button"
|
||||
[routerLink]="route?.path"
|
||||
[queryParams]="route?.queryParams"
|
||||
[queryParamsHandling]="'merge'"
|
||||
>
|
||||
Bearbeiten
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -71,6 +71,16 @@ export class DetailsMainViewDeliveryAddressesComponent extends ComponentStore<De
|
||||
)
|
||||
);
|
||||
|
||||
editShippingAddressRoute$ = (shippingAddressId: number) =>
|
||||
combineLatest([this.canEditAddress$, this._store.processId$, this._store.customerId$]).pipe(
|
||||
map(([canEditAddress, processId, customerId]) => {
|
||||
if (canEditAddress) {
|
||||
return this._navigation.editShippingAddressRoute({ processId, customerId, shippingAddressId });
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
);
|
||||
|
||||
canEditAddress$ = combineLatest([this._store.isKundenkarte$, this._store.isBusinessKonto$, this._store.isMitarbeiter$]).pipe(
|
||||
map(([isKundenkarte, isBusinessKonto, isMitarbeiter]) => isKundenkarte || isBusinessKonto || isMitarbeiter)
|
||||
);
|
||||
|
||||
@@ -70,13 +70,13 @@
|
||||
</shared-form-control>
|
||||
|
||||
<div class="text-center col-span-2">
|
||||
<shared-checkbox>Diese Rechnungsadresse als Standard Adresse festlegen</shared-checkbox>
|
||||
<shared-checkbox formControlName="isDefault">Diese Rechnungsadresse als Standard Adresse festlegen</shared-checkbox>
|
||||
</div>
|
||||
<div class="mt-6 text-center col-span-2">
|
||||
<button
|
||||
[disabled]="formGroup.invalid || formGroup.disabled"
|
||||
type="submit"
|
||||
class="px-5 py-3 font-bold text-lg rounded-full bg-brand text-white"
|
||||
class="px-5 py-3 font-bold text-lg rounded-full bg-brand text-white disabled:bg-gray-400 disabled:cursor-not-allowed"
|
||||
>
|
||||
Speichern
|
||||
</button>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy, ChangeDetectorRef, inject } from '@angular/core';
|
||||
import { CheckboxComponent } from '@shared/components/checkbox';
|
||||
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
||||
import { SelectModule } from '@shared/components/select';
|
||||
@@ -36,6 +36,8 @@ export class EditBillingAddressMainViewComponent extends ComponentStore<EditBill
|
||||
map(([processId, customerId]) => this._navigation.detailsRoute({ processId, customerId }))
|
||||
);
|
||||
|
||||
private _cdr = inject(ChangeDetectorRef);
|
||||
|
||||
formGroup = new FormGroup({
|
||||
gender: new FormControl<Gender>(0, [Validators.required, Validators.min(1)]),
|
||||
title: new FormControl<string>(undefined),
|
||||
@@ -103,6 +105,10 @@ export class EditBillingAddressMainViewComponent extends ComponentStore<EditBill
|
||||
country: payer.address.country,
|
||||
info: payer.address.info,
|
||||
});
|
||||
|
||||
this.formGroup.markAllAsTouched();
|
||||
this.formGroup.updateValueAndValidity();
|
||||
this._cdr.markForCheck();
|
||||
}
|
||||
|
||||
async save() {
|
||||
|
||||
@@ -86,13 +86,13 @@
|
||||
</shared-form-control>
|
||||
|
||||
<div class="text-center col-span-2">
|
||||
<shared-checkbox>Diese Lieferadresse als Standard Adresse festlegen</shared-checkbox>
|
||||
<shared-checkbox formControlName="isDefault">Diese Lieferadresse als Standard Adresse festlegen</shared-checkbox>
|
||||
</div>
|
||||
<div class="mt-6 text-center col-span-2">
|
||||
<button
|
||||
[disabled]="formGroup.invalid || formGroup.disabled"
|
||||
type="submit"
|
||||
class="px-5 py-3 font-bold text-lg rounded-full bg-brand text-white"
|
||||
class="px-5 py-3 font-bold text-lg rounded-full bg-brand text-white disabled:bg-gray-400 disabled:cursor-not-allowed"
|
||||
tabindex="15"
|
||||
>
|
||||
Speichern
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy, inject, ChangeDetectorRef } from '@angular/core';
|
||||
import { CheckboxComponent } from '@shared/components/checkbox';
|
||||
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
||||
import { SelectModule } from '@shared/components/select';
|
||||
import { FormControlComponent } from '@shared/components/form-control';
|
||||
import { CrmCustomerService } from '@domain/crm';
|
||||
import { AddressDTO, Gender, ShippingAddressDTO } from '@swagger/crm';
|
||||
import { map, takeUntil } from 'rxjs/operators';
|
||||
import { map, switchMap, takeUntil } from 'rxjs/operators';
|
||||
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
||||
import { AddressSelectionModalService } from '@shared/modals/address-selection-modal';
|
||||
import { CustomerSearchStore } from '../store';
|
||||
import { CustomerSearchNavigation } from '@shared/services';
|
||||
import { Subject, combineLatest } from 'rxjs';
|
||||
import { IconComponent } from '@shared/components/icon';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
import { ComponentStore } from '@ngrx/component-store';
|
||||
|
||||
export interface EditShippingAddressMainViewState {
|
||||
shippingAddress?: ShippingAddressDTO;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'page-edit-shipping-address-main-view',
|
||||
@@ -33,9 +38,13 @@ import { RouterLink } from '@angular/router';
|
||||
CheckboxComponent,
|
||||
],
|
||||
})
|
||||
export class EditShippingAddressMainViewComponent implements OnInit, OnDestroy {
|
||||
export class EditShippingAddressMainViewComponent extends ComponentStore<EditShippingAddressMainViewState> implements OnInit, OnDestroy {
|
||||
private _activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
private _onDestroy = new Subject<void>();
|
||||
|
||||
private _cdr = inject(ChangeDetectorRef);
|
||||
|
||||
detailsRoute$ = combineLatest([this._store.processId$, this._store.customerId$]).pipe(
|
||||
map(([processId, customerId]) => this._navigation.detailsRoute({ processId, customerId }))
|
||||
);
|
||||
@@ -61,14 +70,30 @@ export class EditShippingAddressMainViewComponent implements OnInit, OnDestroy {
|
||||
|
||||
isBusinessKonto$ = this._store.isBusinessKonto$;
|
||||
|
||||
shippingAddressId$ = this._activatedRoute.params.pipe(
|
||||
map((params) => params.shippingAddressId),
|
||||
switchMap((shippingAddressId) => this._customerService.getShippingAddress(shippingAddressId).pipe(map((res) => res.result)))
|
||||
);
|
||||
|
||||
get shippingAddressId() {
|
||||
return this.get((s) => s.shippingAddress?.id);
|
||||
}
|
||||
|
||||
constructor(
|
||||
private _customerService: CrmCustomerService,
|
||||
private _addressSelection: AddressSelectionModalService,
|
||||
private _store: CustomerSearchStore,
|
||||
private _navigation: CustomerSearchNavigation
|
||||
) {}
|
||||
) {
|
||||
super({ shippingAddress: undefined });
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.shippingAddressId$.pipe(takeUntil(this._onDestroy)).subscribe((shippingAddress) => {
|
||||
this.patchState({ shippingAddress });
|
||||
this.patchFormGroup(shippingAddress);
|
||||
});
|
||||
|
||||
this._store.customer$.pipe(takeUntil(this._onDestroy)).subscribe(() => {
|
||||
if (this._store.isBusinessKonto) {
|
||||
this.formGroup.controls.organisation.setValidators([Validators.required]);
|
||||
@@ -78,17 +103,40 @@ export class EditShippingAddressMainViewComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
patchFormGroup(shipping: ShippingAddressDTO) {
|
||||
this.formGroup.patchValue({
|
||||
gender: shipping.gender ?? 0,
|
||||
title: shipping.title,
|
||||
lastName: shipping.lastName,
|
||||
firstName: shipping.firstName,
|
||||
organisation: shipping.organisation?.name,
|
||||
street: shipping.address.street,
|
||||
streetNumber: shipping.address.streetNumber,
|
||||
zipCode: shipping.address.zipCode,
|
||||
city: shipping.address.city,
|
||||
country: shipping.address.country,
|
||||
info: shipping.address.info,
|
||||
});
|
||||
|
||||
this.formGroup.markAllAsTouched();
|
||||
this.formGroup.updateValueAndValidity();
|
||||
this._cdr.markForCheck();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this._onDestroy.next();
|
||||
this._onDestroy.complete();
|
||||
}
|
||||
|
||||
async save() {
|
||||
console.log('save');
|
||||
if (this.formGroup.invalid) {
|
||||
this.formGroup.markAllAsTouched();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('save2');
|
||||
|
||||
try {
|
||||
this.formGroup.disable();
|
||||
|
||||
@@ -127,7 +175,12 @@ export class EditShippingAddressMainViewComponent implements OnInit, OnDestroy {
|
||||
address: addressValidationResult,
|
||||
};
|
||||
|
||||
const result = await this._customerService.createShippingAddress(this._store.customerId, shippingAddress, formData.isDefault);
|
||||
const result = await this._customerService.updateShippingAddress(
|
||||
this._store.customerId,
|
||||
this.shippingAddressId,
|
||||
shippingAddress,
|
||||
formData.isDefault
|
||||
);
|
||||
|
||||
this._navigation.navigateToDetails({ processId: this._store.processId, customerId: this._store.customerId });
|
||||
} catch (error) {
|
||||
|
||||
@@ -141,6 +141,34 @@ export class CustomerSearchNavigation {
|
||||
return this._router.navigate(route.path, { queryParams: route.queryParams });
|
||||
}
|
||||
|
||||
editShippingAddressRoute(params: { processId: NumberInput; customerId: NumberInput; shippingAddressId: NumberInput }): NavigationRoute {
|
||||
const path = [
|
||||
'/kunde',
|
||||
coerceNumberProperty(params.processId),
|
||||
'customer',
|
||||
{
|
||||
outlets: {
|
||||
primary: [
|
||||
'search',
|
||||
coerceNumberProperty(params.customerId),
|
||||
'shippingaddress',
|
||||
coerceNumberProperty(params.shippingAddressId),
|
||||
'edit',
|
||||
],
|
||||
side: 'results',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const urlTree = this._router.createUrlTree(path, { queryParams: {} });
|
||||
|
||||
return {
|
||||
path,
|
||||
urlTree,
|
||||
queryParams: {},
|
||||
};
|
||||
}
|
||||
|
||||
ordersRoute(params: { processId: NumberInput; customerId: NumberInput }): NavigationRoute {
|
||||
const path = [
|
||||
'/kunde',
|
||||
|
||||
Reference in New Issue
Block a user