This commit is contained in:
2025-11-04 13:05:34 +05:30
5 changed files with 389 additions and 2 deletions

View File

@@ -99,7 +99,7 @@ export default function AddBeneficiaryOthers() {
try { try {
const token = localStorage.getItem("access_token"); const token = localStorage.getItem("access_token");
const response = await fetch( const response = await fetch(
`http://localhost:8080/api/beneficiary/ifsc-details?ifscCode=${ifscTrimmed}`, `/api/beneficiary/ifsc-details?ifscCode=${ifscTrimmed}`,
{ {
method: "GET", method: "GET",
headers: { headers: {

View File

@@ -21,6 +21,8 @@ export default function Layout({ children }: { children: React.ReactNode }) {
{ label: "Change transaction Password", href: "/settings/change_txn_password" }, { label: "Change transaction Password", href: "/settings/change_txn_password" },
{ label: "Set transaction Password", href: "/settings/set_txn_password" }, { label: "Set transaction Password", href: "/settings/set_txn_password" },
{ label: "Preferred Name", href: "/settings/user_name" }, { label: "Preferred Name", href: "/settings/user_name" },
{ label: "Set Transaction Limit ", href: "/settings/set_txn_limit" },
]; ];
useEffect(() => { useEffect(() => {
const token = localStorage.getItem("access_token"); const token = localStorage.getItem("access_token");

View File

@@ -0,0 +1,370 @@
"use client";
import React, { useEffect, useState } from "react";
import {
TextInput,
Button,
Title,
Paper,
Group,
Text,
} from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { IconRefresh, IconCurrencyRupee } from "@tabler/icons-react";
import { generateCaptcha } from "@/app/captcha";
import { useRouter } from "next/navigation";
import { sendOtp, verifyOtp } from "@/app/_util/otp";
import { getDailyLimit } from "@/app/_util/transactionLimit";
export default function SetTransactionLimit() {
const [limit, setLimit] = useState("");
const [captcha, setCaptcha] = useState("");
const [captchaInput, setCaptchaInput] = useState("");
const [otp, setOtp] = useState("");
const [otpValidated, setOtpValidated] = useState(false);
const [countdown, setCountdown] = useState(180);
const [timerActive, setTimerActive] = useState(false);
const [step, setStep] = useState<"form" | "otp" | "final">("form");
const [dailyLimit, setDailyLimit] = useState<number | null>(null);
const router = useRouter();
const icon = <IconCurrencyRupee size={18} stroke={1.5} />;
const FetchDailyLimit = async () => {
try {
const token = localStorage.getItem("access_token");
if (!token) return;
const data = await getDailyLimit(token);
if (data) {
setDailyLimit(data.dailyLimit);
} else {
setDailyLimit(null);
}
} catch {
setDailyLimit(null);
}
};
async function handleSendOtp() {
const mobileNumber = localStorage.getItem("remitter_mobile_no");
if (!mobileNumber) {
notifications.show({
title: "Error",
message: "Mobile number not found. Contact administrator.",
color: "red",
});
return;
}
try {
await sendOtp({ type: "TLIMIT" });
setCountdown(180);
setTimerActive(true);
notifications.show({
title: "OTP Sent",
message: "An OTP has been sent to your registered mobile.",
color: "blue",
});
} catch (err: any) {
console.error("Send OTP failed", err);
notifications.show({
title: "Error",
message: err.message || "Send OTP failed. Try again later.",
color: "red",
});
}
}
async function handleVerifyOtp() {
try {
await verifyOtp(otp);
return true;
} catch {
return false;
}
}
const regenerateCaptcha = async () => {
const newCaptcha = await generateCaptcha();
setCaptcha(newCaptcha);
setCaptchaInput("");
};
useEffect(() => {
let interval: number | undefined;
if (timerActive && countdown > 0) {
interval = window.setInterval(() => {
setCountdown((prev) => prev - 1);
}, 1000);
}
if (countdown === 0) {
if (interval) clearInterval(interval);
setTimerActive(false);
}
return () => {
if (interval) clearInterval(interval);
};
}, [timerActive, countdown]);
useEffect(() => {
regenerateCaptcha();
FetchDailyLimit();
}, []);
const handleSubmit = async () => {
if (step === "form") {
if (!limit || !captchaInput) {
notifications.show({
title: "Missing Field",
message: "Please fill all mandatory fields.",
color: "red",
});
return;
}
if (isNaN(Number(limit)) || Number(limit) <= 0) {
notifications.show({
title: "Invalid Limit",
message: "Please enter a valid positive numeric transaction limit.",
color: "red",
});
return;
}
if (captchaInput !== captcha) {
notifications.show({
title: "Invalid Captcha",
message: "Please enter correct Captcha",
color: "red",
});
regenerateCaptcha();
return;
}
await handleSendOtp();
setStep("otp");
return;
}
if (step === "otp") {
const verified = await handleVerifyOtp();
if (!verified) {
notifications.show({
title: "Invalid OTP",
message: "The OTP entered does not match.",
color: "red",
});
return;
}
setOtpValidated(true);
setStep("final");
notifications.show({
title: "OTP Verified",
message: "OTP has been successfully verified.",
color: "green",
});
return;
}
if (step === "final") {
const token = localStorage.getItem("access_token");
if (!token) {
router.push("/login");
return;
}
try {
const response = await fetch("/api/customer/daily-limit", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Login-Type": "IB",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
amount: Number(limit),
}),
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.message || "Failed to set transaction limit");
}
notifications.show({
title: "Success",
message: `Transaction limit set successfully to ₹${limit}.`,
color: "green",
});
resetForm();
await FetchDailyLimit(); //refresh
const otp_sended = await sendOtp({ type: "TLIMIT_SET", amount: Number(limit) });
} catch (err: any) {
notifications.show({
title: "Error",
message: err.message || "Server error, please try again later",
color: "red",
});
}
}
};
const resetForm = () => {
setLimit("");
setCaptchaInput("");
setOtp("");
setOtpValidated(false);
setStep("form");
regenerateCaptcha();
};
return (
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
<Title order={3} mb="sm">
Set Transaction Limit
</Title>
<div style={{ overflowY: "auto", maxHeight: "280px", paddingRight: 8 }}>
<Group grow>
<TextInput
label="Transaction Limit"
placeholder="Enter your transaction limit"
value={limit}
onChange={(e) => {
const val = e.currentTarget.value;
// Only allow digits
if (/^\d*$/.test(val)) {
setLimit(val);
}
}}
leftSection={icon}
withAsterisk
mb="sm"
readOnly={step !== "form"}
/>
</Group>
{dailyLimit !== null ? (
<Text size="xs" c="green">
Your transaction limit per day is Rs. {dailyLimit.toFixed(2)}
</Text>
) : (
<Text size="xs" c="red">
No daily limit set for this user
</Text>
)}
{/* CAPTCHA */}
<div style={{ marginTop: 5 }}>
<label
style={{ display: "block", marginBottom: 4, fontSize: "14px" }}
>
Enter CAPTCHA <span style={{ color: "red" }}>*</span>
</label>
<div
style={{
display: "flex",
alignItems: "center",
gap: 10,
marginBottom: 5,
}}
>
<div
style={{
fontSize: "18px",
letterSpacing: "3px",
background: "#f3f4f6",
padding: "6px 12px",
borderRadius: "6px",
border: "1px solid #d1d5db",
userSelect: "none",
textDecoration: "line-through",
fontFamily: "cursive",
}}
>
{captcha}
</div>
<Button
size="xs"
variant="outline"
onClick={regenerateCaptcha}
style={{ height: 30, padding: "0 10px", lineHeight: "1" }}
disabled={step !== "form"}
>
Refresh
</Button>
<TextInput
placeholder="Enter above text"
value={captchaInput}
onChange={(e) => setCaptchaInput(e.currentTarget.value)}
withAsterisk
style={{ flexGrow: 1 }}
readOnly={step !== "form"}
/>
</div>
</div>
<Group grow>
{step !== "form" && (
<Group gap="xs" align="flex-end">
<TextInput
label="OTP"
placeholder="Enter OTP"
value={otp}
maxLength={6}
onChange={(e) => setOtp(e.currentTarget.value)}
withAsterisk
disabled={otpValidated}
style={{ flex: 1 }}
/>
{!otpValidated &&
(timerActive ? (
<Text size="xs" c="dimmed" style={{ minWidth: "120px" }}>
Resend OTP will be enabled in{" "}
{String(Math.floor(countdown / 60)).padStart(2, "0")}:
{String(countdown % 60).padStart(2, "0")}
</Text>
) : (
<IconRefresh
size={22}
style={{
cursor: "pointer",
color: "blue",
marginBottom: "6px",
}}
onClick={handleSendOtp}
/>
))}
</Group>
)}
</Group>
</div>
<Group mt="md" gap="sm">
<Button onClick={handleSubmit}>
{step === "form" && "Submit"}
{step === "otp" && "Validate OTP"}
{step === "final" && "Set Limit"}
</Button>
<Button variant="outline" color="gray" onClick={resetForm}>
Reset
</Button>
</Group>
<Text size="sm" style={{ marginTop: "40px" }}>
<Text span c="red" fw={600}>
Note :{" "}
</Text>
<Text span>
Please enter your desired transaction limit. OTP verification is required to
confirm changes.
</Text>
</Text>
</Paper>
);
}

View File

@@ -14,8 +14,13 @@ interface SendOtpPayload {
} }
function getStoredMobileNumber(): string { function getStoredMobileNumber(): string {
<<<<<<< HEAD
// const mobileNumber = localStorage.getItem('remitter_mobile_no'); // const mobileNumber = localStorage.getItem('remitter_mobile_no');
const mobileNumber = "7890544527"; const mobileNumber = "7890544527";
=======
const mobileNumber = localStorage.getItem('remitter_mobile_no');
// const mobileNumber = "6297421727";
>>>>>>> 9850e742fc9e2db185e3a73807bc3c84570153e7
if (!mobileNumber) throw new Error('Mobile number not found.'); if (!mobileNumber) throw new Error('Mobile number not found.');
return mobileNumber; return mobileNumber;
} }

View File

@@ -45,8 +45,13 @@ export default function Login() {
} }
try { try {
<<<<<<< HEAD
// await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: mobile }); // await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: mobile });
await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: "7890544527" }); await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: "7890544527" });
=======
await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: mobile });
// await sendOtp({ type: 'LOGIN_OTP', username: CIF, mobileNumber: "6297421727" });
>>>>>>> 9850e742fc9e2db185e3a73807bc3c84570153e7
notifications.show({ notifications.show({
color: 'orange', color: 'orange',
title: 'OTP Required', title: 'OTP Required',
@@ -67,8 +72,13 @@ export default function Login() {
async function handleVerifyOtp(mobile?: string) { async function handleVerifyOtp(mobile?: string) {
try { try {
if (mobile) { if (mobile) {
<<<<<<< HEAD
// await verifyLoginOtp(otp, mobile); // await verifyLoginOtp(otp, mobile);
await verifyLoginOtp(otp, '7890544527'); await verifyLoginOtp(otp, '7890544527');
=======
await verifyLoginOtp(otp, mobile);
// await verifyLoginOtp(otp, '6297421727');
>>>>>>> 9850e742fc9e2db185e3a73807bc3c84570153e7
return true; return true;
} }
} }
@@ -296,7 +306,7 @@ export default function Login() {
message: "Internal Server Error, Please try again later", message: "Internal Server Error, Please try again later",
autoClose: 5000, autoClose: 5000,
}); });
} }
// finally { // finally {
// // Ensure we always stop loader if still active // // Ensure we always stop loader if still active
// setIsLogging(false); // setIsLogging(false);