From 73136e3bf8dc6b783ddbf4b2e103de9592f13673 Mon Sep 17 00:00:00 2001 From: RENULUCSHMI PRAKASAN Date: Sun, 20 Jul 2025 10:34:18 +0530 Subject: [PATCH 1/2] fix(kyc): prevent duplicate status updates in updateStatus function --- src/components/Admin/dashboardContent/KYCContent.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Admin/dashboardContent/KYCContent.tsx b/src/components/Admin/dashboardContent/KYCContent.tsx index fc514f53..23b28776 100644 --- a/src/components/Admin/dashboardContent/KYCContent.tsx +++ b/src/components/Admin/dashboardContent/KYCContent.tsx @@ -208,6 +208,7 @@ export default function KYCContent() { * @param newStatus The new status to set */ const updateStatus = async (id: string, newStatus: string) => { + // Prevent duplicate status updates if (loadingActions.statusUpdates[id]) return; From 886287a298ca6f8a4eee52ca9bc99591be2feb02 Mon Sep 17 00:00:00 2001 From: RENULUCSHMI PRAKASAN Date: Sun, 20 Jul 2025 10:34:27 +0530 Subject: [PATCH 2/2] feat(kyc): add rejectionReason field to KYC schema and update handling in API and dashboard --- src/app/api/kyc/update/route.ts | 11 ++++-- .../Admin/dashboardContent/KYCContent.tsx | 36 ++++++++++++++++--- src/lib/models/KYCSchema.ts | 12 +++++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/app/api/kyc/update/route.ts b/src/app/api/kyc/update/route.ts index 384355ac..e83bc5f2 100644 --- a/src/app/api/kyc/update/route.ts +++ b/src/app/api/kyc/update/route.ts @@ -24,12 +24,17 @@ export async function PUT(req: NextRequest) { ); } - // Update the KYC record with new status and review timestamp + // Pull rejectionReason if provided + const { id, status, rejectionReason } = body; + + // Update the KYC record with new status, review timestamp, and optional reason const updatedRecord = await KYC.findByIdAndUpdate( - body.id, + id, { - status: body.status, + status, reviewed: new Date(), + // only include the field when rejecting + ...(rejectionReason ? { rejectionReason } : {}), }, { new: true } // Return updated document instead of original ); diff --git a/src/components/Admin/dashboardContent/KYCContent.tsx b/src/components/Admin/dashboardContent/KYCContent.tsx index 23b28776..831bd414 100644 --- a/src/components/Admin/dashboardContent/KYCContent.tsx +++ b/src/components/Admin/dashboardContent/KYCContent.tsx @@ -35,6 +35,7 @@ type KYCRecord = { nicWithPersonUrl?: string; // URL to photo of person with NIC frontPhotoUrl?: string; // URL to front photo of ID backPhotoUrl?: string; // URL to back photo of ID + rejectionReason?: string; // Reason for rejection (if applicable) }; // Color mapping for different statuses to provide visual feedback @@ -207,8 +208,11 @@ export default function KYCContent() { * @param id The KYC record ID to update * @param newStatus The new status to set */ - const updateStatus = async (id: string, newStatus: string) => { - + const updateStatus = async ( + id: string, + newStatus: string, + reason?: string + ) => { // Prevent duplicate status updates if (loadingActions.statusUpdates[id]) return; @@ -232,6 +236,7 @@ export default function KYCContent() { body: JSON.stringify({ id, status: newStatus, + ...(reason ? { rejectionReason: reason } : {}), }), }); @@ -247,6 +252,7 @@ export default function KYCContent() { ...record, status: newStatus, reviewed: new Date().toISOString(), + ...(reason ? { rejectionReason: reason } : {}), } : record ) @@ -450,6 +456,7 @@ export default function KYCContent() { Date Submitted Status Reviewed + Rejection Reason Documents Accept/Reject @@ -477,6 +484,11 @@ export default function KYCContent() { {record.reviewed ? formatDate(record.reviewed) : "-"} + + {record.status === KYC_STATUSES.REJECTED + ? record.rejectionReason || "-" + : "-"} + {/* Document download buttons */}
@@ -554,10 +566,24 @@ export default function KYCContent() { > + +{" "}