import { useRef, useState } from "react"; import { Button } from "@mui/material"; import OTPForm from "../element/OTPForm"; import EditLogin from "../../icons/EditLogin"; import ArrowRightS from "../../icons/ArrowRightS"; import { request } from "@/services/response"; import { changeNumToDefault } from "@/helper"; import Recode from "./Recode"; function VerificationPage({ 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 handleReq = async () => { // const formData = new URLSearchParams(); // formData.append("grant_type", "mobile"); // formData.append("client_id", process.env.NEXT_PUBLIC_CLIENT_ID); // formData.append("client_secret", process.env.NEXT_PUBLIC_CLIENT_SECRET); // formData.append("mobile_number", changeNumToDefault(num)); // formData.append("code", code.join("")); // try { // const res = await axios.post( // "https://back-dev.clinic-pro.ir/oauth/token", // formData, // { // withCredentials: true, // headers: { // "Content-Type": "application/x-www-form-urlencoded", // }, // } // ); // console.log(res); // } catch (err) { // console.error("Request failed:", err); // } 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 (
{ setStep && setStep((prev) => prev - 1); setIsSendMsg && setIsSendMsg(false); }} >

کد تایید را وارد نمایید

کد تایید برای شماره 09{num} ارسال شد.

{code.map((digit, index) => ( ))}

!کد را وارد کنید

); } export default VerificationPage;