feat: call the OTP Url in "send money","settings"
This commit is contained in:
@@ -14,6 +14,7 @@ import { notifications } from "@mantine/notifications";
|
||||
import { IconLock, IconRefresh } from "@tabler/icons-react";
|
||||
import { generateCaptcha } from "@/app/captcha";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { sendOtp, verifyOtp } from "@/app/_util/otp";
|
||||
|
||||
export default function ChangePassword() {
|
||||
const [newPassword, setNewPassword] = useState("");
|
||||
@@ -29,14 +30,50 @@ export default function ChangePassword() {
|
||||
const router = useRouter();
|
||||
|
||||
const icon = <IconLock size={18} stroke={1.5} />;
|
||||
const [showOtpField, setShowOtpField] = useState(false);
|
||||
|
||||
const handleGenerateOtp = async () => {
|
||||
const value = "123456"; // Or generate a random OTP
|
||||
setGeneratedOtp(value);
|
||||
setCountdown(180);
|
||||
setTimerActive(true);
|
||||
return value;
|
||||
};
|
||||
// const handleGenerateOtp = async () => {
|
||||
// const value = "123456"; // Or generate a random OTP
|
||||
// setGeneratedOtp(value);
|
||||
// setCountdown(180);
|
||||
// setTimerActive(true);
|
||||
// return value;
|
||||
// };
|
||||
|
||||
|
||||
async function handleSendOtp() {
|
||||
const mobileNumber = localStorage.getItem('remitter_mobile_no');
|
||||
if (!mobileNumber) {
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Mobile number not found.Contact to administrator',
|
||||
color: 'red',
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await sendOtp({ type: 'SET_TPWORD' });
|
||||
setShowOtpField(true);
|
||||
setCountdown(180);
|
||||
setTimerActive(true);
|
||||
} catch (err: any) {
|
||||
console.error('Send OTP failed', err);
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: err.message || 'Send OTP failed.Please try again later.',
|
||||
color: 'red',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function handleVerifyOtp() {
|
||||
try {
|
||||
await verifyOtp(otp);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const regenerateCaptcha = async () => {
|
||||
const newCaptcha = await generateCaptcha();
|
||||
@@ -111,7 +148,7 @@ export default function ChangePassword() {
|
||||
return;
|
||||
}
|
||||
// Passed → move to OTP step
|
||||
await handleGenerateOtp();
|
||||
await handleSendOtp();
|
||||
setStep("otp");
|
||||
notifications.show({
|
||||
title: "OTP Sent",
|
||||
@@ -310,7 +347,7 @@ export default function ChangePassword() {
|
||||
<IconRefresh
|
||||
size={22}
|
||||
style={{ cursor: "pointer", color: "blue", marginBottom: "6px" }}
|
||||
onClick={handleGenerateOtp}
|
||||
onClick={handleSendOtp}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user