From c873546160ff73f6112f0c3d32954f38ccc35961 Mon Sep 17 00:00:00 2001 From: Lorenz Hilpert Date: Thu, 20 Nov 2025 15:15:32 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=202034:=20=E2=9C=A8=20feat(crm):=20?= =?UTF-8?q?set=20selected=20customer=20when=20navigating=20to=20Pr=C3=A4mi?= =?UTF-8?q?enshop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ feat(crm): set selected customer when navigating to Prämienshop Implements autoTriggerContinueFn pattern to properly set customer context before navigating to reward shop from customer loyalty cards view. Changes: - Add output event to customer-loyalty-cards component (library layer) - Handle navigation at app layer (kundenkarte-main-view) to respect module boundaries - Use existing autoTriggerContinueFn pattern from details-main-view - Inject NavigationStateService and CustomerSearchNavigation services - Preserve context with returnUrl and autoTriggerContinueFn flag This ensures customer selection logic (_setCustomer, _setBuyer, _setSelectedCustomerIdInTab) executes before navigating to the reward shop, matching the behavior of the continue() method in CustomerDetailsViewMainComponent. Refs: #5485 Related work items: #5485 --- .../kundenkarte-main-view.component.html | 1 + .../kundenkarte-main-view.component.ts | 37 ++++++++++++++++++- .../lib/customer-loyalty-cards.component.ts | 18 +++++---- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.html b/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.html index 45a8d9a16..73e9ad0c6 100644 --- a/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.html +++ b/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.html @@ -8,6 +8,7 @@ @let cardCode = firstActiveCardCode(); diff --git a/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.ts b/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.ts index 16bf5ae77..0ddaa56cf 100644 --- a/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.ts +++ b/apps/isa-app/src/page/customer/customer-search/kundenkarte-main-view/kundenkarte-main-view.component.ts @@ -8,8 +8,10 @@ import { OnDestroy, } from '@angular/core'; import { CustomerSearchStore } from '../store'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { map } from 'rxjs/operators'; +import { NavigationStateService } from '@isa/core/navigation'; +import { CustomerSearchNavigation } from '@shared/services/navigation'; import { AsyncPipe } from '@angular/common'; import { CustomerMenuComponent } from '../../components/customer-menu'; import { CustomerLoyaltyCardsComponent } from '@isa/crm/feature/customer-loyalty-cards'; @@ -48,6 +50,9 @@ export class KundenkarteMainViewComponent implements OnDestroy { private _bonusCardsResource = inject(CustomerBonusCardsResource); #cardTransactionsResource = inject(CustomerCardTransactionsResource); elementRef = inject(ElementRef); + #router = inject(Router); + #navigationState = inject(NavigationStateService); + #customerNavigationService = inject(CustomerSearchNavigation); get hostElement() { return this.elementRef.nativeElement; @@ -89,6 +94,36 @@ export class KundenkarteMainViewComponent implements OnDestroy { }, 500); } + /** + * Handle navigation to Prämienshop with proper customer selection. + * Uses autoTriggerContinueFn pattern to auto-select customer via details view. + */ + async onNavigateToPraemienshop(): Promise { + const tabId = this._store.processId; + const customerId = this.customerId(); + + if (!customerId || !tabId) { + return; + } + + // Preserve context for auto-triggering continue() in details view + this.#navigationState.preserveContext( + { + returnUrl: `/${tabId}/reward`, + autoTriggerContinueFn: true, + }, + 'select-customer', + ); + + // Navigate to customer details - will auto-trigger continue() + await this.#router.navigate( + this.#customerNavigationService.detailsRoute({ + processId: tabId, + customerId: Number(customerId), + }).path, + ); + } + ngOnDestroy(): void { if (this.#reloadTimeoutId) { clearTimeout(this.#reloadTimeoutId); diff --git a/libs/crm/feature/customer-loyalty-cards/src/lib/customer-loyalty-cards.component.ts b/libs/crm/feature/customer-loyalty-cards/src/lib/customer-loyalty-cards.component.ts index affa8f205..dca5770d3 100644 --- a/libs/crm/feature/customer-loyalty-cards/src/lib/customer-loyalty-cards.component.ts +++ b/libs/crm/feature/customer-loyalty-cards/src/lib/customer-loyalty-cards.component.ts @@ -1,11 +1,9 @@ -import { Component, effect, inject, input } from '@angular/core'; +import { Component, effect, inject, input, output } from '@angular/core'; import { CustomerBonusCardsResource } from '@isa/crm/data-access'; import { logger } from '@isa/core/logging'; import { CustomerCardPointsSummaryComponent } from './components/customer-card-points-summary'; import { CustomerCardsCarouselComponent } from './components/customer-cards-carousel'; import { coerceNumberProperty, NumberInput } from '@angular/cdk/coercion'; -import { TextButtonComponent } from '@isa/ui/buttons'; -import { Router } from '@angular/router'; import { AddCustomerCardComponent } from './components/add-customer-card/add-customer-card.component'; /** @@ -30,15 +28,12 @@ import { AddCustomerCardComponent } from './components/add-customer-card/add-cus imports: [ CustomerCardPointsSummaryComponent, CustomerCardsCarouselComponent, - TextButtonComponent, AddCustomerCardComponent, ], templateUrl: './customer-loyalty-cards.component.html', styleUrl: './customer-loyalty-cards.component.css', }) export class CustomerLoyaltyCardsComponent { - #router = inject(Router); - #bonusCardsResource = inject(CustomerBonusCardsResource); #logger = logger(() => ({ @@ -61,6 +56,12 @@ export class CustomerLoyaltyCardsComponent { transform: coerceNumberProperty, }); + /** + * Event emitted when user requests navigation to Prämienshop. + * Parent must handle navigation using autoTriggerContinueFn pattern. + */ + readonly navigateToPraemienshop = output(); + /** * All bonus cards for the selected customer. */ @@ -89,9 +90,10 @@ export class CustomerLoyaltyCardsComponent { /** * Handle navigation to Prämienshop. + * Emits event for parent to handle navigation with proper customer selection. */ onNavigateToPraemienshop(): void { - this.#logger.info('Navigate to Prämienshop requested'); - this.#router.navigate([`${this.tabId()}/reward`]); + this.#logger.info('Emit navigate to Prämienshop event'); + this.navigateToPraemienshop.emit(); } }