diff --git a/src/app/notifications/notifications-page/notifications-page.component.html b/src/app/notifications/notifications-page/notifications-page.component.html index 7a1fe4e45..50ef8b3de 100644 --- a/src/app/notifications/notifications-page/notifications-page.component.html +++ b/src/app/notifications/notifications-page/notifications-page.component.html @@ -30,7 +30,7 @@ mat-row *matRowDef="let row; columns: displayedColumns" class="select-row" - [routerLink]="[routeMap[row.objectType], row.objectId]" + (click)="navigateToNotification(row)" > You don't have any notifications diff --git a/src/app/notifications/notifications-page/notifications-page.component.scss b/src/app/notifications/notifications-page/notifications-page.component.scss index 996d27b1e..cd15e3d51 100644 --- a/src/app/notifications/notifications-page/notifications-page.component.scss +++ b/src/app/notifications/notifications-page/notifications-page.component.scss @@ -6,6 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -.select-row:hover { +.select-row { cursor: pointer; } diff --git a/src/app/notifications/notifications-page/notifications-page.component.ts b/src/app/notifications/notifications-page/notifications-page.component.ts index 83213853e..58b856673 100644 --- a/src/app/notifications/notifications-page/notifications-page.component.ts +++ b/src/app/notifications/notifications-page/notifications-page.component.ts @@ -24,8 +24,9 @@ import { MatRow, MatNoDataRow } from '@angular/material/table'; -import { ActivatedRoute, RouterLink } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; +import { NotificationsService } from '../notifications.service'; /** * Notifications Page Component @@ -54,6 +55,8 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; }) export class NotificationsPageComponent implements OnInit { private route = inject(ActivatedRoute); + private router = inject(Router); + private notificationsService = inject(NotificationsService); /** Notifications data. */ notificationsData: any; @@ -112,4 +115,88 @@ export class NotificationsPageComponent implements OnInit { this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; } + + /** + * Navigate to notification object with proper entity context + * @param {any} notification Notification object + */ + navigateToNotification(notification: any): void { + 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 + ]); + } + } } diff --git a/src/app/notifications/notifications.service.ts b/src/app/notifications/notifications.service.ts index 15a01480d..b19b1784e 100644 --- a/src/app/notifications/notifications.service.ts +++ b/src/app/notifications/notifications.service.ts @@ -12,6 +12,7 @@ import { HttpClient, HttpParams } from '@angular/common/http'; /** rxjs Imports */ import { Observable, of } from 'rxjs'; +import { map, catchError } from 'rxjs/operators'; /** * Notification service. @@ -37,6 +38,86 @@ export class NotificationsService { return this.http.put('/notifications', {}); } + /** + * Get loan account details to retrieve client/group ID + * @param {string} loanId Loan Account ID + * @returns {Observable} Loan account with clientId or groupId + */ + getLoanAccount(loanId: string): Observable { + return this.http.get(`/loans/${loanId}`).pipe( + map((response: any) => ({ + clientId: response.clientId, + groupId: response.groupId, + accountId: loanId + })), + catchError(() => of(null)) + ); + } + + /** + * Get savings account details to retrieve client/group ID + * @param {string} savingsId Savings Account ID + * @returns {Observable} Savings account with clientId or groupId + */ + getSavingsAccount(savingsId: string): Observable { + return this.http.get(`/savingsaccounts/${savingsId}`).pipe( + map((response: any) => ({ + clientId: response.clientId, + groupId: response.groupId, + accountId: savingsId + })), + catchError(() => of(null)) + ); + } + + /** + * Get fixed deposit account details to retrieve client/group ID + * @param {string} accountId Fixed Deposit Account ID + * @returns {Observable} Fixed deposit account with clientId or groupId + */ + getFixedDepositAccount(accountId: string): Observable { + return this.http.get(`/fixeddepositaccounts/${accountId}`).pipe( + map((response: any) => ({ + clientId: response.clientId, + groupId: response.groupId, + accountId: accountId + })), + catchError(() => of(null)) + ); + } + + /** + * Get recurring deposit account details to retrieve client/group ID + * @param {string} accountId Recurring Deposit Account ID + * @returns {Observable} Recurring deposit account with clientId or groupId + */ + getRecurringDepositAccount(accountId: string): Observable { + return this.http.get(`/recurringdepositaccounts/${accountId}`).pipe( + map((response: any) => ({ + clientId: response.clientId, + groupId: response.groupId, + accountId: accountId + })), + catchError(() => of(null)) + ); + } + + /** + * Get share account details to retrieve client/group ID + * @param {string} accountId Share Account ID + * @returns {Observable} Share account with clientId or groupId + */ + getShareAccount(accountId: string): Observable { + return this.http.get(`/accounts/share/${accountId}`).pipe( + map((response: any) => ({ + clientId: response.clientId, + groupId: response.groupId, + accountId: accountId + })), + catchError(() => of(null)) + ); + } + /** * @returns {Observable} Mock Unread Notifications for Testing. */ diff --git a/src/app/shared/notifications-tray/notifications-tray.component.html b/src/app/shared/notifications-tray/notifications-tray.component.html index 64d46fcce..ef0e6206b 100644 --- a/src/app/shared/notifications-tray/notifications-tray.component.html +++ b/src/app/shared/notifications-tray/notifications-tray.component.html @@ -41,11 +41,7 @@
@for (notification of unreadNotifications; track notification) { -