WEB-509:fix(notifications): resolve account navigation using entity resolution (#3032)

improve
This commit is contained in:
Shubham Kumar
2026-01-21 14:54:17 -06:00
committed by GitHub
parent e9e8876c5d
commit 7bdd7112b0
6 changed files with 263 additions and 13 deletions
@@ -41,11 +41,7 @@
</div>
<div class="notifications-list">
@for (notification of unreadNotifications; track notification) {
<button
mat-menu-item
class="notification-item unread"
[routerLink]="[routeMap[notification.objectType], notification.objectId]"
>
<button mat-menu-item class="notification-item unread" (click)="navigateToNotification(notification, $event)">
<div class="notification-content">
<span class="notification-text">{{ notification.content }}</span>
<span class="unread-indicator">●</span>
@@ -55,11 +51,7 @@
}
@for (notification of displayedReadNotifications; track notification) {
<button
mat-menu-item
class="notification-item read"
[routerLink]="[routeMap[notification.objectType], notification.objectId]"
>
<button mat-menu-item class="notification-item read" (click)="navigateToNotification(notification, $event)">
<div class="notification-content">
<span class="notification-text">{{ notification.content }}</span>
</div>
@@ -8,6 +8,7 @@
/** Angular Imports */
import { Component, OnInit, OnDestroy, ViewEncapsulation, inject } from '@angular/core';
import { Router } from '@angular/router';
/** RxJS Imports */
import { forkJoin } from 'rxjs';
@@ -45,6 +46,7 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
})
export class NotificationsTrayComponent implements OnInit, OnDestroy {
notificationsService = inject(NotificationsService);
private router = inject(Router);
/** Wait time between API status calls 60 seg */
waitTime = environment.waitTimeForNotifications || 60;
@@ -143,4 +145,92 @@ export class NotificationsTrayComponent implements OnInit, OnDestroy {
this.setNotifications();
});
}
/**
* Navigate to notification object with proper entity context
* @param {any} notification Notification object
* @param {Event} event Click event
*/
navigateToNotification(notification: any, event: Event): void {
event.preventDefault();
event.stopPropagation();
const objectType = notification.objectType;
const objectId = notification.objectId;
// For entities that don't require parent context (client, group, center, products)
if ([
'client',
'group',
'center',
'shareProduct',
'loanProduct'
].includes(objectType)) {
this.router.navigate([
this.routeMap[objectType],
objectId
]);
return;
}
// For account types that require parent entity (client/group) ID
switch (objectType) {
case 'loan':
this.notificationsService.getLoanAccount(objectId).subscribe((account) => {
if (account && (account.clientId || account.groupId)) {
const entityType = account.clientId ? 'clients' : 'groups';
const entityId = account.clientId || account.groupId;
this.router.navigate([`/${entityType}/${entityId}/loans-accounts/${account.accountId}`]);
}
});
break;
case 'savingsAccount':
this.notificationsService.getSavingsAccount(objectId).subscribe((account) => {
if (account && (account.clientId || account.groupId)) {
const entityType = account.clientId ? 'clients' : 'groups';
const entityId = account.clientId || account.groupId;
this.router.navigate([`/${entityType}/${entityId}/savings-accounts/${account.accountId}`]);
}
});
break;
case 'fixedDeposit':
this.notificationsService.getFixedDepositAccount(objectId).subscribe((account) => {
if (account && (account.clientId || account.groupId)) {
const entityType = account.clientId ? 'clients' : 'groups';
const entityId = account.clientId || account.groupId;
this.router.navigate([`/${entityType}/${entityId}/fixed-deposits-accounts/${account.accountId}`]);
}
});
break;
case 'recurringDepositAccount':
this.notificationsService.getRecurringDepositAccount(objectId).subscribe((account) => {
if (account && (account.clientId || account.groupId)) {
const entityType = account.clientId ? 'clients' : 'groups';
const entityId = account.clientId || account.groupId;
this.router.navigate([`/${entityType}/${entityId}/recurring-deposits-accounts/${account.accountId}`]);
}
});
break;
case 'shareAccount':
this.notificationsService.getShareAccount(objectId).subscribe((account) => {
if (account && (account.clientId || account.groupId)) {
const entityType = account.clientId ? 'clients' : 'groups';
const entityId = account.clientId || account.groupId;
this.router.navigate([`/${entityType}/${entityId}/shares-accounts/${account.accountId}`]);
}
});
break;
default:
// Fallback to old behavior for unknown types
this.router.navigate([
this.routeMap[objectType],
objectId
]);
}
}
}