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 fc514f53..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,7 +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; @@ -231,6 +236,7 @@ export default function KYCContent() { body: JSON.stringify({ id, status: newStatus, + ...(reason ? { rejectionReason: reason } : {}), }), }); @@ -246,6 +252,7 @@ export default function KYCContent() { ...record, status: newStatus, reviewed: new Date().toISOString(), + ...(reason ? { rejectionReason: reason } : {}), } : record ) @@ -449,6 +456,7 @@ export default function KYCContent() {