From f6a5002bd867da39aa52a2eab0d89da98b0a9a30 Mon Sep 17 00:00:00 2001 From: Ryam Date: Fri, 1 Dec 2023 15:24:26 +0630 Subject: [PATCH 1/2] refactor: removed unused function --- .../pending-approvals.component.ts | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/packages/admin-ui/src/app/participants/pending-approvals.component.ts b/packages/admin-ui/src/app/participants/pending-approvals.component.ts index 4e7cfaa5..979e49d8 100644 --- a/packages/admin-ui/src/app/participants/pending-approvals.component.ts +++ b/packages/admin-ui/src/app/participants/pending-approvals.component.ts @@ -106,34 +106,6 @@ export class PendingApprovalsComponent implements OnInit { return this.selectedFundAdjustment.some((item) => item.id === id); } - getApprovalData(approved: boolean): IParticipantPendingApproval { - let ndcRequests: IParticipantPendingApproval["ndcChangeRequests"] = - this.selectedNDCRequest; - let fundAdjustments: IParticipantPendingApproval["fundsMovementRequest"] = - this.selectedFundAdjustment; - if (this.isNDCSelectAll) { - ndcRequests = this.ndcRequests.value; - } - if (this.isFundAdjustmentSelectAll) { - fundAdjustments = this.fundAdjustments.value; - } - - ndcRequests.forEach((item) => { - item.approved = approved; - }); - fundAdjustments.forEach((item) => { - item.approved = approved; - }); - return { - ndcChangeRequests: ndcRequests, - fundsMovementRequest: fundAdjustments, - accountsChangeRequest: [], - ipChangeRequests: [], - contactInfoChangeRequests: [], - statusChangeRequests: [], - }; - } - approveFundAdjustmentPendingApprovals() { let fundAdjustments: IParticipantPendingApproval["fundsMovementRequest"] = this.selectedFundAdjustment; From 10ba50fc5dfe4c167e0cd50e05cd19b4cd89eb9a Mon Sep 17 00:00:00 2001 From: Ryam Date: Fri, 5 Jan 2024 15:46:24 +0630 Subject: [PATCH 2/2] feat: pending approval proper error message --- .../_services_and_types/participant_types.ts | 8 +- .../participants.service.ts | 7 +- .../pending-approvals.component.html | 33 ++++ .../pending-approvals.component.ts | 176 ++++++++++++------ 4 files changed, 164 insertions(+), 60 deletions(-) diff --git a/packages/admin-ui/src/app/_services_and_types/participant_types.ts b/packages/admin-ui/src/app/_services_and_types/participant_types.ts index 849fb052..dc3becdc 100644 --- a/packages/admin-ui/src/app/_services_and_types/participant_types.ts +++ b/packages/admin-ui/src/app/_services_and_types/participant_types.ts @@ -88,4 +88,10 @@ export interface FundMovement { updateAmount: string settlementAccountId: string isDuplicate: boolean -} \ No newline at end of file +} + +export declare type BulkApprovalRequestResults = { + reqId: string; + status: "success" | "error"; + message: string; +} diff --git a/packages/admin-ui/src/app/_services_and_types/participants.service.ts b/packages/admin-ui/src/app/_services_and_types/participants.service.ts index c6b05a0e..79b4dd84 100644 --- a/packages/admin-ui/src/app/_services_and_types/participants.service.ts +++ b/packages/admin-ui/src/app/_services_and_types/participants.service.ts @@ -28,6 +28,7 @@ import { IParticipantPendingApprovalSummary, FundMovement, ParticipantsSearchResults, + BulkApprovalRequestResults, } from "./participant_types"; const SVC_BASEURL = "/_participants"; @@ -1067,14 +1068,14 @@ export class ParticipantsService { } submitPendingApprovals(data: IParticipantPendingApproval) { - return new Observable((subscriber) => { + return new Observable((subscriber) => { this._http - .post( + .post( `${SVC_BASEURL}/participants/pendingApprovals`, data ) .subscribe( - (result: IParticipantPendingApproval) => { + (result: BulkApprovalRequestResults[]) => { console.log(`got submitPendingApprovals response: ${result}`); subscriber.next(result); diff --git a/packages/admin-ui/src/app/participants/pending-approvals.component.html b/packages/admin-ui/src/app/participants/pending-approvals.component.html index de593f78..0f3cd3b5 100644 --- a/packages/admin-ui/src/app/participants/pending-approvals.component.html +++ b/packages/admin-ui/src/app/participants/pending-approvals.component.html @@ -40,6 +40,7 @@

Pending Fund Adjustment for all Participants

Pending NDC for all Participants Pending NDC for all Participants
+ + + + + + diff --git a/packages/admin-ui/src/app/participants/pending-approvals.component.ts b/packages/admin-ui/src/app/participants/pending-approvals.component.ts index 979e49d8..7e5da60e 100644 --- a/packages/admin-ui/src/app/participants/pending-approvals.component.ts +++ b/packages/admin-ui/src/app/participants/pending-approvals.component.ts @@ -1,9 +1,13 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, ViewChild } from "@angular/core"; import { ParticipantsService } from "../_services_and_types/participants.service"; import { MessageService } from "../_services_and_types/message.service"; import { BehaviorSubject } from "rxjs"; -import { IParticipantPendingApproval } from "../_services_and_types/participant_types"; +import { + BulkApprovalRequestResults, + IParticipantPendingApproval, +} from "../_services_and_types/participant_types"; import { UnauthorizedError } from "@mojaloop/security-bc-public-types-lib"; +import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap"; @Component({ selector: "app-participants", @@ -28,10 +32,17 @@ export class PendingApprovalsComponent implements OnInit { fundAdjustmentCount: number = 0; ndcRequestCount: number = 0; + approvalResult: BulkApprovalRequestResults[] = []; + + @ViewChild("pendingApprovalsModal") // Get a reference to the depositModal + pendingApprovalsModal!: NgbModal; + pendingApprovalsModalRef?: NgbModalRef; + constructor( private _participantsSvc: ParticipantsService, - private _messageService: MessageService - ) { } + private _messageService: MessageService, + private _modalService: NgbModal + ) {} async ngOnInit(): Promise { console.log("PendingApprovalsComponent ngOnInit"); @@ -69,6 +80,13 @@ export class PendingApprovalsComponent implements OnInit { const isChecked = e.target.checked; if (isChecked) { this.selectedFundAdjustment.push(fundAdjustment); + + // Check if all Fund Adjustment requests are selected + if ( + this.fundAdjustments.value.length === this.selectedFundAdjustment.length + ) { + this.isFundAdjustmentSelectAll = true; + } } else { // find by id from fund adjustment and remove item from selectedFundAdjustment const index = this.selectedFundAdjustment.findIndex( @@ -77,6 +95,8 @@ export class PendingApprovalsComponent implements OnInit { if (index !== -1) { this.selectedFundAdjustment.splice(index, 1); } + + this.isFundAdjustmentSelectAll = false; } } @@ -85,8 +105,14 @@ export class PendingApprovalsComponent implements OnInit { ndcRequest: IParticipantPendingApproval["ndcChangeRequests"][number] ) { const isChecked = e.target.checked; + if (isChecked) { this.selectedNDCRequest.push(ndcRequest); + + // Check if all NDC requests are selected + if (this.ndcRequests.value.length === this.selectedNDCRequest.length) { + this.isNDCSelectAll = true; + } } else { // find by id from fund adjustment and remove item from selectedFundAdjustment const index = this.selectedNDCRequest.findIndex( @@ -95,6 +121,8 @@ export class PendingApprovalsComponent implements OnInit { if (index !== -1) { this.selectedNDCRequest.splice(index, 1); } + + this.isNDCSelectAll = false; } } @@ -115,30 +143,39 @@ export class PendingApprovalsComponent implements OnInit { fundAdjustments.forEach((item) => { item.approved = true; }); - this._participantsSvc.submitPendingApprovals({ - fundsMovementRequest: fundAdjustments, - ndcChangeRequests: [], - accountsChangeRequest: [], - ipChangeRequests: [], - contactInfoChangeRequests: [], - statusChangeRequests: [], - }).subscribe( - async () => { - this._messageService.addSuccess("Approved!"); - await this.getPendingApprovalsSummary(); - await this.getPendingApprovals(); - }, - (error) => { - if (error && error instanceof UnauthorizedError) { - this._messageService.addError(error.message); + this._participantsSvc + .submitPendingApprovals({ + fundsMovementRequest: fundAdjustments, + ndcChangeRequests: [], + accountsChangeRequest: [], + ipChangeRequests: [], + contactInfoChangeRequests: [], + statusChangeRequests: [], + }) + .subscribe( + async (result) => { + if (result.length > 0) { + this.approvalResult = result; + this.pendingApprovalsModalRef = this._modalService.open( + this.pendingApprovalsModal, + { centered: true } + ); + } + + await this.getPendingApprovalsSummary(); + await this.getPendingApprovals(); + }, + (error) => { + if (error && error instanceof UnauthorizedError) { + this._messageService.addError(error.message); + } + }, + () => { + // reset all selected options + this.selectedFundAdjustment = []; + this.isFundAdjustmentSelectAll = false; } - }, - () => { - // reset all selected options - this.selectedFundAdjustment = []; - this.isFundAdjustmentSelectAll = false; - } - ); + ); } rejectFundAdjustmentPendingApprovals() { @@ -150,30 +187,39 @@ export class PendingApprovalsComponent implements OnInit { fundAdjustments.forEach((item) => { item.approved = false; }); - this._participantsSvc.submitPendingApprovals({ - fundsMovementRequest: fundAdjustments, - ndcChangeRequests: [], - accountsChangeRequest: [], - ipChangeRequests: [], - contactInfoChangeRequests: [], - statusChangeRequests: [], - }).subscribe( - async () => { - this._messageService.addSuccess("Rejected!"); - await this.getPendingApprovalsSummary(); - await this.getPendingApprovals(); - }, - (error) => { - if (error && error instanceof UnauthorizedError) { - this._messageService.addError(error.message); + this._participantsSvc + .submitPendingApprovals({ + fundsMovementRequest: fundAdjustments, + ndcChangeRequests: [], + accountsChangeRequest: [], + ipChangeRequests: [], + contactInfoChangeRequests: [], + statusChangeRequests: [], + }) + .subscribe( + async (result) => { + if (result.length > 0) { + this.approvalResult = result; + this.pendingApprovalsModalRef = this._modalService.open( + this.pendingApprovalsModal, + { centered: true } + ); + } + + await this.getPendingApprovalsSummary(); + await this.getPendingApprovals(); + }, + (error) => { + if (error && error instanceof UnauthorizedError) { + this._messageService.addError(error.message); + } + }, + () => { + // reset all selected options + this.selectedFundAdjustment = []; + this.isFundAdjustmentSelectAll = false; } - }, - () => { - // reset all selected options - this.selectedFundAdjustment = []; - this.isFundAdjustmentSelectAll = false; - } - ); + ); } approveNDCRequestPendingApprovals() { @@ -195,8 +241,15 @@ export class PendingApprovalsComponent implements OnInit { statusChangeRequests: [], }) .subscribe( - async () => { - this._messageService.addSuccess("Approved!"); + async (result) => { + if (result.length > 0) { + this.approvalResult = result; + this.pendingApprovalsModalRef = this._modalService.open( + this.pendingApprovalsModal, + { centered: true } + ); + } + await this.getPendingApprovalsSummary(); await this.getPendingApprovals(); }, @@ -232,8 +285,15 @@ export class PendingApprovalsComponent implements OnInit { statusChangeRequests: [], }) .subscribe( - async () => { - this._messageService.addSuccess("Rejected!"); + async (result) => { + if (result.length > 0) { + this.approvalResult = result; + this.pendingApprovalsModalRef = this._modalService.open( + this.pendingApprovalsModal, + { centered: true } + ); + } + await this.getPendingApprovalsSummary(); await this.getPendingApprovals(); }, @@ -250,7 +310,6 @@ export class PendingApprovalsComponent implements OnInit { ); } - async getPendingApprovals(): Promise { return new Promise((resolve, reject) => { this._participantsSvc.getPendingApprovals().subscribe( @@ -287,9 +346,14 @@ export class PendingApprovalsComponent implements OnInit { if (error && error instanceof UnauthorizedError) { this._messageService.addError(error.message); } - reject() + reject(); } ); }); } + + closePendingApprovalsModal() { + this.pendingApprovalsModalRef?.close(); + this.approvalResult = []; + } }