fix bug save and set data just with one key, remove page login from appo page, disable not avalaible data in calendar, change steps for pages in appo, get data user, edit and set in page user-info

This commit is contained in:
Ehsan
2025-08-31 01:21:59 +03:30
parent 09867bf84a
commit 1e70d88a84
20 changed files with 332 additions and 146 deletions
+64
View File
@@ -0,0 +1,64 @@
import Date from "./date";
// Components
import Content from "./Content";
import Layout from "@/components/layout";
import Paying from "@/components/appointment/paying";
import Detail from "@/components/appointment/detail";
import FailedPay from "@/components/appointment/failedPay";
import SuccessPay from "@/components/appointment/successPay";
function Container({
step,
data,
doctor,
setData,
setStep,
matchedCity,
isForAnother,
setIsForAnother,
}) {
const elements = [
<Date doctor={doctor} setStep={setStep} />,
// <LogInPage setIsSendMsg={false} setStep={setStep} />,
// <VerificationPage setIsSendMsg={false} link={false} setStep={setStep} />,
<Detail
data={data}
setStep={setStep}
setData={setData}
isForAnother={isForAnother}
setIsForAnother={setIsForAnother}
/>,
<Paying setStep={setStep} />,
<SuccessPay setStep={setStep} />,
<FailedPay setStep={setStep} />,
];
return (
<>
{/* {step === 1 || step === 2 ? (
<RegisterPage>{elements[step]}</RegisterPage>
) : ( */}
<Layout
title="رزرو"
name="booking"
disableFooter={step > 2}
matchedCity={matchedCity}
paddingBottom="pb-[80px]"
>
<Content
disableSide={step === 5 || step === 6}
isFirst={step === 0}
setStep={setStep}
doctor={doctor}
step={step}
>
{elements[step]}
</Content>
</Layout>
{/* )} */}
</>
);
}
export default Container;
-1
View File
@@ -4,7 +4,6 @@ import Time from "./Time";
function Date({ doctor, setStep }) {
const [locateVisit, setLocateVisit] = useState(true);
const [isError, setIsError] = useState(false);
const [date, setDate] = useState();
return (
+17 -14
View File
@@ -1,14 +1,16 @@
import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect";
import EditField from "../../../app/component/fields/EditField";
import Content from "./Content";
import EditField from "../../../app/component/fields/EditField";
import DefaultSelect from "@/app/component/selectors/DefaultSelect";
const bime = [
{ label: "بیمه 1", id: 10 },
{ label: "بیمه 2", id: 20 },
{ label: "بیمه 3", id: 30 },
];
function Form({ changeData, insurance, data, updateSelect, isForAnother }) {
const findVal = () => {
return insurance?.find(
(g) =>
g.id ===
(data?.basic_insurance?.value ? data?.basic_insurance.value.id : false)
);
};
function Form({ changeData, data, updateSelect, isForAnother }) {
return (
<div
className="grid mt-[12px] sm:mt-[14px] md:mt-[17px] lg:mt-[20px] items-start
@@ -20,19 +22,20 @@ function Form({ changeData, data, updateSelect, isForAnother }) {
<Content title="کد ملی">
<EditField
changeData={changeData}
data={data?.codemeli}
name="codemeli"
data={data?.national_code}
name="national_code"
/>
</Content>
<Content title="نام و نام خانوادگی">
<EditField changeData={changeData} data={data?.name} name="name" />
</Content>
<Content title="نوع بیمه">
<AutoCompleteSelect
updateData={updateSelect}
<DefaultSelect
updateData={(name, val) => updateSelect(val, "value", name)}
label="نوع بیمه"
name="first"
list={bime}
name="basic_insurance"
list={insurance}
value={findVal()}
/>
</Content>
</div>
+21 -5
View File
@@ -1,9 +1,10 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { Button } from "@mui/material";
import AddCircleBlueA from "@/components/icons/AddCircleBlueA";
import ArrowLeftB from "@/components/icons/ArrowLeftB";
import ButtonFixed from "../paying/ButtonFixed";
import Form from "./Form";
import { request } from "@/services/response";
function Detail({
isForAnother,
@@ -14,6 +15,7 @@ function Detail({
fadeElement,
setIsPay,
}) {
const [insurance, setInsurance] = useState();
const [selected, setSelected] = useState({
first: "",
second: "",
@@ -31,6 +33,19 @@ function Detail({
const updateSelect = (event, name) =>
setSelected({ ...selected, [name]: event });
const newStep = () => {
// if(data)
setStep((prev) => prev + 1);
};
useEffect(() => {
request.getInsuranceType().then((res) => {
if (res && res.data) {
setInsurance(res.data);
}
});
}, []);
return (
// ${typePay === 'success' || typePay === 'failed' ? 'bg-transparent border-transparent md:bg-[#FFF] md:border-[#EFEFEF]' : ''}
<div className="w-full lg:w-[59%]">
@@ -43,10 +58,11 @@ function Detail({
{isForAnother ? "اطلاعات کاربر جدید" : "اطلاعات حساب کاربری"}
</p>
<Form
isForAnother={isForAnother}
updateSelect={updateSelect}
changeData={changeData}
data={data}
insurance={insurance}
changeData={changeData}
updateSelect={updateSelect}
isForAnother={isForAnother}
/>
{!isForAnother && (
<Button
@@ -77,7 +93,7 @@ function Detail({
: "!mt-0 md:!mt-[32px]"
}`}
variant="contained"
onClick={() => setStep((prev) => prev + 1)}
onClick={newStep}
>
<p className="text-[#EFEFEF] text-[16px] font-medium">
ثبت اطلاعات
+63 -56
View File
@@ -1,71 +1,78 @@
"use client";
import { useState } from "react";
import Content from "./Content";
import Layout from "@/components/layout";
import { useEffect, useState } from "react";
import doctors from "@/data/doctors.json";
import RegisterPage from "@/components/register";
import Paying from "@/components/appointment/paying";
import Detail from "@/components/appointment/detail";
import FailedPay from "@/components/appointment/failedPay";
import LogInPage from "@/components/register/LogInPage";
import SuccessPay from "@/components/appointment/successPay";
import VerificationPage from "@/components/register/verificationPage";
import Date from "./date";
import { request } from "@/services/response";
import Cookies from "js-cookie";
import Container from "./Container";
const defaultData = {
phone: { value: "", isEdit: false },
national_code: { value: "", isEdit: false },
name: { value: "", isEdit: false },
basic_insurance: { value: "", isEdit: false },
};
function AppointmentPage({ slug, matchedCity }) {
const doctor = doctors.find((item) => item.id === +slug);
const [step, setStep] = useState(0);
const [step, setStep] = useState(1);
const [isForAnother, setIsForAnother] = useState(false);
const [data, setData] = useState({
phone: { value: "09121056987", isEdit: true },
codemeli: { value: "1741025645", isEdit: true },
name: { value: "ساغر صابری نژاد", isEdit: true },
});
const [prevData, setPrevData] = useState(defaultData);
const [data, setData] = useState(defaultData);
const elements = [
<Date doctor={doctor} setStep={setStep} />,
<LogInPage setIsSendMsg={false} setStep={setStep} />,
<VerificationPage setIsSendMsg={false} link={false} setStep={setStep} />,
<Detail
data={data}
setStep={setStep}
setData={setData}
isForAnother={isForAnother}
setIsForAnother={setIsForAnother}
/>,
<Paying setStep={setStep} />,
<SuccessPay setStep={setStep} />,
<FailedPay setStep={setStep} />,
];
useEffect(() => {
const userInfo = Cookies.get("userInfo");
const parsedData = JSON.parse(userInfo);
if (userInfo && parsedData) {
request
.getUserProfile(parsedData.uuid)
.then((res) => {
if (res) {
const newData = {
phone: { value: parsedData.username || "", isEdit: false },
national_code: { value: res.national_code || "", isEdit: true },
name: { value: `${res.name} ${res.family}`, isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
},
};
setData(newData);
setPrevData(newData);
} else {
const emptyData = {
phone: { value: parsedData.username || "", isEdit: false },
national_code: { value: "", isEdit: true },
name: { value: "", isEdit: true },
basic_insurance: {
value: res.basic_insurance,
isEdit: true,
},
};
setData(emptyData);
setPrevData(emptyData);
}
})
.catch((err) => {
console.log(err);
});
}
}, []);
return (
<>
{step === 1 || step === 2 ? (
<RegisterPage>{elements[step]}</RegisterPage>
) : (
<Layout
title="رزرو"
name="booking"
disableFooter={step > 2}
matchedCity={matchedCity}
paddingBottom="pb-[80px]"
>
<Content
disableSide={step === 5 || step === 6}
isFirst={step === 0}
setStep={setStep}
doctor={doctor}
step={step}
>
{elements[step]}
</Content>
</Layout>
)}
</>
<Container
step={step}
data={data}
doctor={doctor}
setData={setData}
setStep={setStep}
matchedCity={matchedCity}
isForAnother={isForAnother}
setIsForAnother={setIsForAnother}
/>
);
}
+1 -1
View File
@@ -14,7 +14,7 @@ function Detail({ doctor, step, setStep }) {
<LocationA />
</div>
<p className="text-[#616161] text-[14px] md:text-[16px] font-normal">
آدرس: {doctor.location}
آدرس: {doctor?.location}
</p>
</li>
<li className="flex items-center justify-between w-full">
+3 -3
View File
@@ -16,16 +16,16 @@ function Head({ doctor }) {
h-[40px] sm:h-[58px] md:h-[77px] lg:h-[95px]
"
alt="profile doctor"
src={doctor.img}
src={doctor?.img}
height={95}
width={95}
/>
<div className="flex flex-col items-start justify-center gap-[8px] sm:gap-[12px] md:gap-[16px] lg:gap-[20px]">
<p className="text-[#3B3B3B] text-[14px] sm:text-[16px] md:text-[18px] lg:text-[20px] font-bold">
{doctor.name}
{doctor?.name}
</p>
<p className="text-[#616161] text-[14px] md:text-[16px] font-medium">
تخصص: {doctor.expertise}
تخصص: {doctor?.expertise}
</p>
</div>
</div>