From cdb0babb8696c9179257ca65d6445bbe1fea144b Mon Sep 17 00:00:00 2001 From: "tomosa.sarkar" Date: Mon, 22 Sep 2025 15:18:49 +0530 Subject: [PATCH] Feat: For Migration if user not have password --- TODO.md | 2 +- src/app/login/page.tsx | 154 ++++++++++++++++++++++++++--------------- 2 files changed, 98 insertions(+), 58 deletions(-) diff --git a/TODO.md b/TODO.md index 7caf614..e3f34cf 100644 --- a/TODO.md +++ b/TODO.md @@ -21,7 +21,7 @@ - >give rights - >view rights - Forget Password -- For Migration if user not have password +- >For Migration if user not have password diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index a349933..7eee408 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -23,8 +23,7 @@ export default function Login() { const [opened, setOpened] = useState(false); const [otpStep, setOtpStep] = useState(false); const [otp, setOtp] = useState(""); - const [isOtpSending, setIsOtpSending] = useState(false); - const [isOtpVerifying, setIsOtpVerifying] = useState(false); + const [loading, setLoading] = useState(false); useEffect(() => { const loadCaptcha = async () => { @@ -34,6 +33,21 @@ export default function Login() { loadCaptcha(); }, []); + useEffect(() => { + const headerData = [ + "THE KANGRA CENTRAL CO-OPERATIVE BANK LTD.", + "कांगड़ा केन्द्रीय सहकारी बैंक सीमित", + ]; + let index = 0; + const interval = setInterval(() => { + index = (index + 1) % headerData.length; + if (headerRef.current) { + headerRef.current.textContent = headerData[index]; + } + }, 2000); + return () => clearInterval(interval); + }, []); + const regenerateCaptcha = () => { // setCaptcha(generateCaptcha()); const loadCaptcha = async () => { @@ -108,7 +122,6 @@ export default function Login() { return; } if (!response.ok) { - //console.log("hiiiii"); notifications.show({ withBorder: true, color: "red", @@ -158,20 +171,80 @@ export default function Login() { return; } } - useEffect(() => { - const headerData = [ - "THE KANGRA CENTRAL CO-OPERATIVE BANK LTD.", - "कांगड़ा केन्द्रीय सहकारी बैंक सीमित", - ]; - let index = 0; - const interval = setInterval(() => { - index = (index + 1) % headerData.length; - if (headerRef.current) { - headerRef.current.textContent = headerData[index]; + + // For migration User + const sendOtp = async () => { + try { + setLoading(true); + const res = await fetch(`/api/otp/send/set-password?customerNo=${CIF}`, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }); + + if (!res.ok) throw new Error("Failed to send OTP"); + notifications.show({ + color: "green", + title: "OTP Sent", + message: "Please check your registered mobile.", + }); + setOtpStep(true); + } catch (err: any) { + notifications.show({ + color: "red", + title: "Error", + message: err.message || "Could not send OTP", + }); + } finally { + setLoading(false); + } + }; + + // For migration User + const verifyOtp = async () => { + if (!otp) { + notifications.show({ + color: "red", + title: "Invalid Input", + message: "Please enter OTP before verifying", + }); + return; + } + + try { + setLoading(true); + const res = await fetch(`/api/otp/verify/set-password?customerNo=${CIF}&otp=${otp}`, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }); + + const data = await res.json(); + console.log(data) + if (!res.ok) { + notifications.show({ + color: "red", + title: "Error", + message: data.error || "OTP verification failed", + }); + return; } - }, 2000); - return () => clearInterval(interval); - }, []); + localStorage.setItem("access_token", data.token); + notifications.show({ + color: "green", + title: "OTP Verified", + message: "Redirecting to set password page...", + }); + setOpened(false); + router.push("/SetPassword"); + } catch (err: any) { + notifications.show({ + color: "red", + title: "Error", + message: err.message || "OTP verification failed", + }); + } finally { + setLoading(false); + } + }; return ( @@ -200,13 +273,8 @@ export default function Login() { > Cancel - - {/* ✅ Instead of calling API, just open OTP screen */} - @@ -214,61 +282,33 @@ export default function Login() { ) : ( // STEP 2: OTP Verification (Frontend-only) <> - - Enter the OTP (for demo, you can accept any value). - - + Enter the OTP sent to your registered mobile setOtp(e.currentTarget.value)} /> - - - )} - - - {/* */} + {/* Main Screen */}
{/* Header */}