refactor: implement login state management and navigation flow in appointment components
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user