handle all pages dashboard & register api

This commit is contained in:
Ehsan
2025-05-24 22:17:55 +03:30
parent 7dfad1847a
commit 5fa740ad1b
19 changed files with 549 additions and 182 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
"use client";
import RegisterPage from "@/components/register";
import SetCodePage from "@/components/register/SetCodePage";
import VerificationPage from "@/components/register/verificationPage";
import LogInPage from "@/components/register/LogInPage";
import { useState } from "react";
@@ -11,7 +11,7 @@ function ContentVerify() {
return (
<RegisterPage>
{isSendMsg ? (
<SetCodePage
<VerificationPage
setIsSendMsg={setIsSendMsg}
link={`/account/${localStorage.getItem("doctor-id")}`}
/>
+30 -31
View File
@@ -25,38 +25,37 @@ function LogInPage({ setIsSendMsg, num, setNum, matchedCity }) {
// }
};
const handleReq = async () => {
try {
const res = await axios.post(
"https://back-dev.clinic-pro.ir/api/v1/user/auth?_format=json",
{ mobile_number: changeNumToDefault(num) },
{
withCredentials: true,
headers: {
"Content-Type": "application/json",
},
}
);
console.log(res);
if (res.data) {
setIsSendMsg(true);
}
} catch (err) {
console.error("Request failed:", err);
}
// setLoading(true);
// request
// .sendCode(changeNumToDefault(num))
// .then((response) => {
// setLoading(false);
// if (response) {
// // setNum("");
// setIsSendMsg(true);
// try {
// const res = await axios.post(
// "https://back-dev.clinic-pro.ir/api/v1/user/auth?_format=json",
// { mobile_number: changeNumToDefault(num) },
// {
// withCredentials: true,
// headers: {
// "Content-Type": "application/json",
// },
// }
// })
// .catch(() => {
// setLoading(false);
// });
// );
// console.log(res);
// if (res.data) {
// setIsSendMsg(true);
// }
// } catch (err) {
// console.error("Request failed:", err);
// }
setLoading(true);
request
.sendCode(changeNumToDefault(num))
.then((response) => {
setLoading(false);
if (response) {
// setNum("");
setIsSendMsg(true);
}
})
.catch(() => {
setLoading(false);
});
};
return (
+2 -2
View File
@@ -1,6 +1,6 @@
"use client";
import SetCodePage from "@/components/register/SetCodePage";
import VerificationPage from "@/components/register/verificationPage";
import LogInPage from "@/components/register/LogInPage";
import { useState } from "react";
import LayoutRegister from "./LayoutRegister";
@@ -12,7 +12,7 @@ function RegisterPage({ matchedCity }) {
return (
<LayoutRegister matchedCity={matchedCity}>
{isSendMsg ? (
<SetCodePage
<VerificationPage
num={num}
setIsSendMsg={setIsSendMsg}
setStep={false}
@@ -0,0 +1,53 @@
import RetryLogin from "@/components/icons/RetryLogin";
import { Button } from "@mui/material";
const time_resend_code = 120;
function Recode({ retryIcon, timer, setTimer }) {
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);
};
return (
<Button
className="flex !p-1 items-center justify-start gap-1 hover-rotate-90 cursor-pointer"
disabled={typeof timer === "number" && timer !== 0}
onClick={() => {
if (!timer && timer !== "loading") {
handleTimer();
retryIcon.current.classList.add("retry-icon");
setTimeout(() => {
retryIcon.current &&
retryIcon.current.classList.remove("retry-icon");
}, 1000);
}
}}
>
{timer && timer !== "loading" ? (
<p className="text-[#F17732] text-[14px] font-normal select-none">
{timer} ثانیه
</p>
) : (
<>
<div ref={retryIcon}>
<RetryLogin />
</div>
<p className="text-[#F17732] text-[14px] font-normal select-none">
دریافت مجدد کد
</p>
</>
)}
</Button>
);
}
export default Recode;
@@ -1,17 +1,14 @@
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 OTPForm from "../element/OTPForm";
import EditLogin from "../../icons/EditLogin";
import ArrowRightS from "../../icons/ArrowRightS";
import { request } from "@/services/response";
import { changeNumToDefault } from "@/helper";
import axios from "axios";
import Recode from "./Recode";
const time_resend_code = 120;
function SetCodePage({ setIsSendMsg, link, num, setStep }) {
function VerificationPage({ setIsSendMsg, link, num, setStep }) {
const retryIcon = useRef();
const [timer, setTimer] = useState(0);
@@ -48,58 +45,45 @@ function SetCodePage({ setIsSendMsg, link, num, setStep }) {
}
};
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);
};
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(""));
// 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);
// });
// 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 (
@@ -120,7 +104,7 @@ function SetCodePage({ setIsSendMsg, link, num, setStep }) {
کد تایید را وارد نمایید
</p>
<p className="text-[#616161] mt-[16px] sm:mt-[19px] md:mt-[22px] lg:mt-[24px] text-[14px] font-normal text-right">
کد تایید برای شماره 09013261200 ارسال شد.
کد تایید برای شماره <span dir="ltr">09{num}</span> ارسال شد.
</p>
<div className="mt-[26px] sm:mt-[28px] md:mt-[30px] lg:mt-[32px] mb-[56px] sm:mb-[47px] md:mb-[38px] lg:mb-[30px]">
<div className="mb-[27px]" dir="ltr">
@@ -163,35 +147,7 @@ function SetCodePage({ setIsSendMsg, link, num, setStep }) {
</p>
</Button>
<Button
className="flex !p-1 items-center justify-start gap-1 hover-rotate-90 cursor-pointer"
disabled={typeof timer === "number" && timer !== 0}
onClick={() => {
if (!timer && timer !== "loading") {
handleTimer();
retryIcon.current.classList.add("retry-icon");
setTimeout(() => {
retryIcon.current &&
retryIcon.current.classList.remove("retry-icon");
}, 1000);
}
}}
>
{timer && timer !== "loading" ? (
<p className="text-[#F17732] text-[14px] font-normal select-none">
{timer} ثانیه
</p>
) : (
<>
<div ref={retryIcon}>
<RetryLogin />
</div>
<p className="text-[#F17732] text-[14px] font-normal select-none">
دریافت مجدد کد
</p>
</>
)}
</Button>
<Recode retryIcon={retryIcon} timer={timer} setTimer={setTimer} />
</div>
</div>
<Button
@@ -215,4 +171,4 @@ function SetCodePage({ setIsSendMsg, link, num, setStep }) {
);
}
export default SetCodePage;
export default VerificationPage;