mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 2027: #5483 Reset Reward Cart + Customer from Tab
#5483 Reset Reward Cart + Customer from Tab Small Bugfixes to #5480 Customer clearing Logic
This commit is contained in:
committed by
Lorenz Hilpert
parent
212203fb04
commit
83292836a3
@@ -12,7 +12,7 @@
|
||||
type="button"
|
||||
color="subtle"
|
||||
size="small"
|
||||
(click)="resetCustomerAndCart()"
|
||||
(click)="resetCustomerAndRewardCart()"
|
||||
>
|
||||
Zurücksetzen
|
||||
</ui-text-button>
|
||||
|
||||
@@ -16,8 +16,9 @@ import {
|
||||
SelectedRewardShoppingCartResource,
|
||||
} from '@isa/checkout/data-access';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { injectTabId } from '@isa/core/tabs';
|
||||
import { TabService, getNextTabNameHelper } from '@isa/core/tabs';
|
||||
import { formatName } from '@isa/utils/format-name';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
|
||||
@Component({
|
||||
selector: 'reward-customer-card',
|
||||
@@ -34,7 +35,8 @@ import { formatName } from '@isa/utils/format-name';
|
||||
export class RewardCustomerCardComponent {
|
||||
#crmTabMetadataService = inject(CrmTabMetadataService);
|
||||
#checkoutMetadataService = inject(CheckoutMetadataService);
|
||||
tabId = injectTabId();
|
||||
#domainCheckoutService = inject(DomainCheckoutService);
|
||||
#tabService = inject(TabService);
|
||||
#customerResource = inject(SelectedCustomerResource).resource;
|
||||
#shoppingCartResource = inject(SelectedRewardShoppingCartResource).resource;
|
||||
#primaryCustomerCardResource = inject(PrimaryCustomerCardResource);
|
||||
@@ -65,11 +67,71 @@ export class RewardCustomerCardComponent {
|
||||
});
|
||||
});
|
||||
|
||||
resetCustomerAndCart() {
|
||||
this.#crmTabMetadataService.setSelectedCustomerId(this.tabId()!, undefined);
|
||||
this.#checkoutMetadataService.setRewardShoppingCartId(
|
||||
this.tabId()!,
|
||||
undefined,
|
||||
);
|
||||
resetCustomerAndRewardCart() {
|
||||
const tabId = this.#tabService.activatedTabId()!;
|
||||
|
||||
// Clear all customer-related checkout data
|
||||
this.#clearCheckoutData(tabId);
|
||||
|
||||
// Clear all customer-related metadata
|
||||
this.#clearCustomerMetadata(tabId);
|
||||
|
||||
// Clear reward shopping cart ID from metadata
|
||||
this.#checkoutMetadataService.setRewardShoppingCartId(tabId, undefined);
|
||||
|
||||
// Rename tab to "Vorgang X"
|
||||
const tabName = getNextTabNameHelper(this.#tabService.entityMap());
|
||||
this.#tabService.patchTab(tabId, { name: tabName });
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all checkout data set by the continue() flow (customer, buyer, payer, shipping address, notification channels).
|
||||
* This is the reverse operation of what happens in details-main-view.component.ts continue().
|
||||
*/
|
||||
#clearCheckoutData(tabId: number): void {
|
||||
// Reset customer (reverse of _setCustomer)
|
||||
this.#domainCheckoutService.setCustomer({
|
||||
processId: tabId,
|
||||
customerDto: null as any,
|
||||
});
|
||||
|
||||
// Reset buyer (reverse of _setBuyer)
|
||||
this.#domainCheckoutService.setBuyer({
|
||||
processId: tabId,
|
||||
buyer: null as any,
|
||||
});
|
||||
|
||||
// Reset payer (reverse of _setPayer)
|
||||
this.#domainCheckoutService.setPayer({
|
||||
processId: tabId,
|
||||
payer: null as any,
|
||||
});
|
||||
|
||||
// Reset shipping address (reverse of _setShippingAddress)
|
||||
this.#domainCheckoutService.setShippingAddress({
|
||||
processId: tabId,
|
||||
shippingAddress: null as any,
|
||||
});
|
||||
|
||||
// Reset notification channels (reverse of _updateNotifcationChannelsAsync)
|
||||
this.#domainCheckoutService.setNotificationChannels({
|
||||
processId: tabId,
|
||||
notificationChannels: 0,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all customer-related metadata from the tab (customer ID, payer ID, shipping address ID).
|
||||
* This is the reverse operation of what happens in details-main-view.component.ts continue().
|
||||
*/
|
||||
#clearCustomerMetadata(tabId: number): void {
|
||||
// Clear customer ID from metadata (reverse of _setSelectedCustomerIdInTab)
|
||||
this.#crmTabMetadataService.setSelectedCustomerId(tabId, undefined);
|
||||
|
||||
// Clear payer ID from metadata
|
||||
this.#crmTabMetadataService.setSelectedPayerId(tabId, undefined);
|
||||
|
||||
// Clear shipping address ID from metadata
|
||||
this.#crmTabMetadataService.setSelectedShippingAddressId(tabId, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
checkCartHasItemsHelper,
|
||||
} from './helpers';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { CrmTabMetadataService } from '@isa/crm/data-access';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
// TODO: #5484 Move Guard to other location + Use resources for fetching cart data
|
||||
@@ -30,6 +31,7 @@ import { firstValueFrom } from 'rxjs';
|
||||
export const canDeactivateTabCleanup: CanDeactivateFn<unknown> = async () => {
|
||||
const tabService = inject(TabService);
|
||||
const checkoutMetadataService = inject(CheckoutMetadataService);
|
||||
const crmTabMetadataService = inject(CrmTabMetadataService);
|
||||
const shoppingCartService = inject(ShoppingCartService);
|
||||
const domainCheckoutService = inject(DomainCheckoutService);
|
||||
const router = inject(Router);
|
||||
@@ -41,18 +43,22 @@ export const canDeactivateTabCleanup: CanDeactivateFn<unknown> = async () => {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the target URL contains a tab ID
|
||||
// Check if the target URL contains a tab ID and if it matches the current tab
|
||||
// Routes without tab ID (e.g., /filiale/package-inspection, /kunde/dashboard) are global areas
|
||||
// Routes with tab ID (e.g., /537825823/return, /kunde/3296528359/search) are tab-specific
|
||||
// Routes with different tab ID (e.g., creating new process) should not affect current tab
|
||||
const nextUrl = router.getCurrentNavigation()?.finalUrl?.toString() ?? '';
|
||||
const hasTabIdInUrl = /\/\d{10,}\//.test(nextUrl);
|
||||
const tabIdMatch = nextUrl.match(/\/(\d{10,})\//);
|
||||
const targetTabId = tabIdMatch ? parseInt(tabIdMatch[1], 10) : null;
|
||||
|
||||
// If navigating to a route without tab ID (filial/dashboard areas), keep tab unchanged
|
||||
if (!hasTabIdInUrl) {
|
||||
// Skip cleanup if navigating to global area or different tab
|
||||
if (!targetTabId || targetTabId !== tabId) {
|
||||
log.debug(
|
||||
'Navigating to global area (no tab ID), keeping tab unchanged',
|
||||
targetTabId
|
||||
? 'Navigating to different tab, keeping current tab unchanged'
|
||||
: 'Navigating to global area (no tab ID), keeping tab unchanged',
|
||||
() => ({
|
||||
tabId,
|
||||
currentTabId: tabId,
|
||||
targetTabId,
|
||||
nextUrl,
|
||||
}),
|
||||
);
|
||||
@@ -156,6 +162,11 @@ export const canDeactivateTabCleanup: CanDeactivateFn<unknown> = async () => {
|
||||
// Remove checkout state from store (customer, buyer, payer, etc.)
|
||||
domainCheckoutService.removeProcess({ processId: tabId });
|
||||
|
||||
// Clear customer-related metadata (prevents old customer data from being reused)
|
||||
crmTabMetadataService.setSelectedCustomerId(tabId, undefined);
|
||||
crmTabMetadataService.setSelectedPayerId(tabId, undefined);
|
||||
crmTabMetadataService.setSelectedShippingAddressId(tabId, undefined);
|
||||
|
||||
// Create new shopping cart for the cleaned tab
|
||||
const newShoppingCart = await shoppingCartService.createShoppingCart();
|
||||
checkoutMetadataService.setShoppingCartId(tabId, newShoppingCart.id);
|
||||
|
||||
Reference in New Issue
Block a user