Merged PR 2040: fix(crm): prevent duplicate reload of loyalty points

fix(crm): prevent duplicate reload of loyalty points

Refactored reload mechanism to use parent-managed pattern:
- Child components emit events instead of reloading directly
- Parent coordinates reload of both transactions and bonus cards
- Added loading guards to prevent concurrent requests
- Added JSDoc documentation to public methods

Closes #5497

Related work items: #5497
This commit is contained in:
Lorenz Hilpert
2025-11-21 13:40:06 +00:00
committed by Nino Righi
parent 644c33ddc3
commit 5f1d3a2c7b
4 changed files with 186 additions and 169 deletions

View File

@@ -17,10 +17,18 @@
<crm-customer-bon-redemption
[cardCode]="cardCode"
class="mt-4"
(redeemed)="reloadCardTransactions()"
(redeemed)="reloadCardTransactionsAndCards()"
/>
<crm-customer-booking
[cardCode]="cardCode"
class="mt-4"
(booked)="reloadCardTransactionsAndCards()"
/>
<crm-customer-card-transactions
[cardCode]="cardCode"
class="mt-8"
(reload)="reloadCardTransactionsAndCards()"
/>
<crm-customer-booking [cardCode]="cardCode" class="mt-4" />
<crm-customer-card-transactions [cardCode]="cardCode" class="mt-8" />
}
<utils-scroll-top-button

View File

@@ -47,13 +47,16 @@ export class KundenkarteMainViewComponent implements OnDestroy {
private _store = inject(CustomerSearchStore);
private _activatedRoute = inject(ActivatedRoute);
private _bonusCardsResource = inject(CustomerBonusCardsResource);
#bonusCardsResource = inject(CustomerBonusCardsResource);
#cardTransactionsResource = inject(CustomerCardTransactionsResource);
elementRef = inject(ElementRef);
#router = inject(Router);
#navigationState = inject(NavigationStateService);
#customerNavigationService = inject(CustomerSearchNavigation);
/**
* Returns the native DOM element of this component
*/
get hostElement() {
return this.elementRef.nativeElement;
}
@@ -73,7 +76,7 @@ export class KundenkarteMainViewComponent implements OnDestroy {
* Get the first active card code
*/
readonly firstActiveCardCode = computed(() => {
const cards = this._bonusCardsResource.resource.value();
const cards = this.#bonusCardsResource.resource.value();
const firstActiveCard = cards?.find((card) => card.isActive);
return firstActiveCard?.code;
});
@@ -83,14 +86,24 @@ export class KundenkarteMainViewComponent implements OnDestroy {
effect(() => {
const customerId = this.customerId();
if (customerId) {
this._bonusCardsResource.params({ customerId: Number(customerId) });
this.#bonusCardsResource.params({ customerId: Number(customerId) });
}
});
}
reloadCardTransactions() {
/**
* Reloads both card transactions and bonus cards resources after a 500ms delay.
* Only triggers reload if the resource is not currently loading to prevent concurrent requests.
*/
reloadCardTransactionsAndCards() {
this.#reloadTimeoutId = setTimeout(() => {
this.#cardTransactionsResource.resource.reload();
if (!this.#cardTransactionsResource.resource.isLoading()) {
this.#cardTransactionsResource.resource.reload();
}
if (!this.#bonusCardsResource.resource.isLoading()) {
this.#bonusCardsResource.resource.reload();
}
}, 500);
}