From c7a0c55399a198948c7dc744da4cc95d25da5915 Mon Sep 17 00:00:00 2001 From: RENULUCSHMI PRAKASAN Date: Tue, 22 Jul 2025 16:48:48 +0530 Subject: [PATCH] feat: add back button to KYC form for improved navigation --- src/app/user/kyc/page.tsx | 46 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/app/user/kyc/page.tsx b/src/app/user/kyc/page.tsx index e0bd2b47..14877c06 100644 --- a/src/app/user/kyc/page.tsx +++ b/src/app/user/kyc/page.tsx @@ -5,6 +5,9 @@ import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/lib/context/AuthContext"; +import Link from "next/link"; +import { ArrowLeft} from "lucide-react"; + // API endpoint configuration for file uploads and KYC submission const API_ENDPOINTS = { @@ -31,12 +34,8 @@ const NIC_PATTERNS = { NEW_NIC: /^(19[0-9]{2}|20[0-9]{2}|2100)[0-9]{8}$/, // New format: 12 digits }; - - // User-facing messages for different scenarios const MESSAGES = { - - NIC_FORMAT_ERROR: "Invalid NIC format. Please enter either 9 digits followed by V/X or 12 digits", NIC_FORMAT_INFO: @@ -45,7 +44,7 @@ const MESSAGES = { "Your face and both sides of your NIC should be clearly visible", FORM_INCOMPLETE: "Please fill all fields and upload all required photos", INVALID_NIC: "Please enter a valid NIC number", - + NIC_UPLOAD_FAILED: "NIC file upload failed", PERSON_PHOTO_UPLOAD_FAILED: "Photo with NIC upload failed", KYC_SUBMISSION_FAILED: "KYC submission failed", @@ -117,9 +116,9 @@ const initialFormState: KYCFormState = { export default function KYCForm() { // State management hooks - const { user, isLoading ,token} = useAuth(); + const { user, isLoading, token } = useAuth(); const router = useRouter(); - + const [nicError, setNicError] = useState(null); const [fileError, setFileError] = useState(null); const [uploading, setUploading] = useState(false); @@ -129,9 +128,6 @@ export default function KYCForm() { } | null>(null); const [formState, setFormState] = useState(initialFormState); - - - // 4) Your redirect-if-not-logged-in effect useEffect(() => { @@ -147,7 +143,7 @@ export default function KYCForm() { ); } - const displayName = `${user.firstName} ${user.lastName}`.trim(); + const displayName = `${user.firstName} ${user.lastName}`.trim(); // Helper function to update specific form field const updateField = ( @@ -162,7 +158,6 @@ export default function KYCForm() { setFormState(initialFormState); setFileError(null); setNicError(null); - // Clear file input elements const fileInputs = document.querySelectorAll( @@ -173,8 +168,6 @@ export default function KYCForm() { }); }; - - // Validate file size and type const validateFile = (file: File): string | null => { if (file.size > FILE_CONSTRAINTS.MAX_SIZE_BYTES) { @@ -188,10 +181,6 @@ export default function KYCForm() { return null; }; - - - - // Validate NIC format using regex patterns const validateNIC = (nicNumber: string): boolean => { return ( @@ -308,8 +297,7 @@ export default function KYCForm() { isError: true, }); return; - } - + } // Validate NIC format if (!validateNIC(formState.nic)) { @@ -359,7 +347,7 @@ export default function KYCForm() { method: "POST", headers: { "Content-Type": "application/json", - "Authorization": `Bearer ${token}`, + Authorization: `Bearer ${token}`, }, body: JSON.stringify({ userId: user!._id, @@ -413,6 +401,16 @@ export default function KYCForm() { return (
+ {/* Back button */} +
+ + + + +
{/* Responsive image container - hidden on mobile */}
@@ -434,7 +432,7 @@ export default function KYCForm() { {FORM_LABELS.TITLE} {/* Read-only Name field */} -
+