From 5a58c13a4e77bf4fa13ef072b580b13e0ac666e7 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 17 Nov 2025 15:00:40 +0330 Subject: [PATCH] refactor: implement login state management and navigation flow in appointment components --- app/component/date/dateTime/SendAppo.js | 8 ++- components/appointment/Container.js | 71 +++++++++++++------ components/appointment/index.js | 13 +++- components/register/LogInPage.js | 4 +- .../register/verificationPage/SendReq.js | 9 ++- 5 files changed, 78 insertions(+), 27 deletions(-) diff --git a/app/component/date/dateTime/SendAppo.js b/app/component/date/dateTime/SendAppo.js index 86468b8..7f94e75 100644 --- a/app/component/date/dateTime/SendAppo.js +++ b/app/component/date/dateTime/SendAppo.js @@ -11,9 +11,15 @@ function SendAppo({ hour, setStep }) { const sendReq = () => { const isLogged = Cookies.get("access_token"); + if (isLogged) { - setStep((step) => step + 1); + // اگر لاگین کرده، به مرحله 3 (Detail) می‌رود + setStep(3); + } else { + // اگر لاگین نکرده، به مرحله 1 (Login) می‌رود + setStep(1); } + // setLoading(true); // request // .postAppointment({ diff --git a/components/appointment/Container.js b/components/appointment/Container.js index 6dafc50..008add5 100644 --- a/components/appointment/Container.js +++ b/components/appointment/Container.js @@ -7,6 +7,9 @@ import Paying from "@/components/appointment/paying"; import Detail from "@/components/appointment/detail"; import FailedPay from "@/components/appointment/failedPay"; import SuccessPay from "@/components/appointment/successPay"; +import LogInPage from "@/components/register/LogInPage"; +import VerificationPage from "@/components/register/verificationPage"; +import LayoutRegister from "@/components/register/LayoutRegister"; function Container({ step, @@ -19,11 +22,33 @@ function Container({ isForAnother, setIsForAnother, disabledDates, + // Login states + num, + setNum, + uuid, + setUuid, + isSendMsg, + setIsSendMsg, }) { const elements = [ , - // , - // , + , + , - {/* {step === 1 || step === 2 ? ( - {elements[step]} - ) : ( */} - 2} - matchedCity={matchedCity} - paddingBottom="pb-[80px]" - > - + {step === 1 || step === 2 ? ( + {elements[step]} - - - {/* )} */} + + ) : ( + 4} + matchedCity={matchedCity} + paddingBottom="pb-[80px]" + > + + {elements[step]} + + + )} ); } diff --git a/components/appointment/index.js b/components/appointment/index.js index 1e255c1..1f88f9f 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -19,6 +19,11 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { const [prevData, setPrevData] = useState(defaultData); const [data, setData] = useState(defaultData); + // Login states + const [num, setNum] = useState(""); + const [uuid, setUuid] = useState(""); + const [isSendMsg, setIsSendMsg] = useState(false); + useEffect(() => { const userInfo = Cookies.get("userInfo"); const parsedData = userInfo && JSON.parse(userInfo); @@ -62,7 +67,7 @@ function AppointmentPage({ doctor, disabledDates, matchedCity }) { // }); } - }, []); + }, [step]); // وقتی step تغییر کرد، دوباره چک می‌کنه return ( ); } diff --git a/components/register/LogInPage.js b/components/register/LogInPage.js index 9d384b5..16aefbf 100644 --- a/components/register/LogInPage.js +++ b/components/register/LogInPage.js @@ -5,7 +5,7 @@ import { InputAdornment, Button } from "@mui/material"; import Link from "next/link"; import { useState } from "react"; -function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity }) { +function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity, setStep }) { const [error, setError] = useState({ valid: true, text: "" }); const [loading, setLoading] = useState(false); @@ -23,6 +23,8 @@ function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity }) { if (response.uuid) { setIsSendMsg(true); setUuid(response.uuid); + // به مرحله بعد (VerificationPage) می‌رود + setStep && setStep(2); } }) .catch(() => { diff --git a/components/register/verificationPage/SendReq.js b/components/register/verificationPage/SendReq.js index 47e60fd..b7a3b74 100644 --- a/components/register/verificationPage/SendReq.js +++ b/components/register/verificationPage/SendReq.js @@ -82,7 +82,13 @@ function SendReq({ setLoading(false); if (res && res.uuid) { Cookies.set("userInfo", JSON.stringify(res), cookieOptions); - window.location.pathname = "/"; + + // اگر در صفحه appointment هستیم، به مرحله 3 (Detail) می‌رویم + if (setStep) { + setStep(3); + } else { + window.location.pathname = "/"; + } } }) .catch(() => { @@ -98,7 +104,6 @@ function SendReq({ variant="contained" onClick={() => { setIsSendMsg && setIsSendMsg(true); - setStep && setStep((prev) => prev + 1); if (code.join("").length !== 5) { setIsError(true); } else {