import { useRef, useState } from "react"; import { Button } from "@mui/material"; import OTPForm from "./element/OTPForm"; import EditLogin from "../icons/EditLogin"; import RetryLogin from "../icons/RetryLogin"; import ArrowRightS from "../icons/ArrowRightS"; import { request } from "@/services/response"; import { changeNumToDefault } from "@/helper"; const time_resend_code = 120; function SetCodePage({ setIsSendMsg, link, num, setStep }) { const retryIcon = useRef(); const [timer, setTimer] = useState(0); const [loading, setLoading] = useState(false); const [code, setCode] = useState(["", "", "", ""]); const [isError, setIsError] = useState(false); const inputRefs = Array.from({ length: 5 }, () => useRef()); const handleChange = (index, val) => { const newCode = [...code]; if (val === "backspace") { newCode[index] = ""; setCode(newCode); if (index > 0) { inputRefs[index - 1].current?.focus(); } return; } newCode[index] = val; if (newCode.join("").length === 4 && isError) { setIsError(false); } // if (newCode.join("").length === 4) { // handleReq(); // } setCode(newCode); if (val && index < inputRefs.length - 1) { inputRefs[index + 1].current?.focus(); } }; const handleTimer = () => { setTimer("loading"); setTimeout(() => { setTimer(time_resend_code); let timePresent = time_resend_code; const timerInterval = setInterval(() => { timePresent--; setTimer(timePresent); !timePresent && clearInterval(timerInterval); }, 1000); }, 1000); }; console.log(num); const handleReq = () => { setLoading(true); request .getToken( "mobile", process.env.NEXT_PUBLIC_CLIENT_ID, process.env.NEXT_PUBLIC_CLIENT_SECRET, changeNumToDefault(num), code.join("") ) .then((response) => { setLoading(false); }) .catch((err) => { setLoading(false); }); }; return (
کد تایید را وارد نمایید
کد تایید برای شماره 09013261200 ارسال شد.
!کد را وارد کنید