From 6920e4078be62bdc4bee52a48c51963741ea1390 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Tue, 2 Sep 2025 00:32:04 +0330 Subject: [PATCH] redirect filter data to doctors page from home page just with one key && add picture url to doctors page && add conditional to appo page and change data in server --- app/component/ItemDoctor.js | 4 +- components/appointment/Container.js | 2 + components/appointment/detail/Form.js | 4 +- components/appointment/detail/SubmitData.js | 63 +++++++++++++++++++++ components/appointment/detail/index.js | 38 +------------ components/appointment/index.js | 14 +++-- components/doctor/detailDoctor/Title.js | 7 ++- components/home/FrequentSearches.js | 2 +- services/response.js | 14 +++-- 9 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 components/appointment/detail/SubmitData.js diff --git a/app/component/ItemDoctor.js b/app/component/ItemDoctor.js index 4d3ea87..6b6879a 100644 --- a/app/component/ItemDoctor.js +++ b/app/component/ItemDoctor.js @@ -20,9 +20,9 @@ function ItemDoctor({ doctor }) { image-doctor
diff --git a/components/appointment/Container.js b/components/appointment/Container.js index 6f5a9aa..4acb0d1 100644 --- a/components/appointment/Container.js +++ b/components/appointment/Container.js @@ -14,6 +14,7 @@ function Container({ doctor, setData, setStep, + prevData, matchedCity, isForAnother, setIsForAnother, @@ -26,6 +27,7 @@ function Container({ data={data} setStep={setStep} setData={setData} + prevData={prevData} isForAnother={isForAnother} setIsForAnother={setIsForAnother} />, diff --git a/components/appointment/detail/Form.js b/components/appointment/detail/Form.js index 7ba00a9..239206a 100644 --- a/components/appointment/detail/Form.js +++ b/components/appointment/detail/Form.js @@ -2,7 +2,7 @@ import Content from "./Content"; import EditField from "../../../app/component/fields/EditField"; import DefaultSelect from "@/app/component/selectors/DefaultSelect"; -function Form({ changeData, insurance, data, updateSelect, isForAnother }) { +function Form({ changeData, insurance, data, isForAnother }) { const findVal = () => { return insurance?.find( (g) => @@ -31,7 +31,7 @@ function Form({ changeData, insurance, data, updateSelect, isForAnother }) { updateSelect(val, "value", name)} + updateData={(name, val) => changeData(val, "value", name)} label="نوع بیمه" name="basic_insurance" list={insurance} diff --git a/components/appointment/detail/SubmitData.js b/components/appointment/detail/SubmitData.js new file mode 100644 index 0000000..a4346ea --- /dev/null +++ b/components/appointment/detail/SubmitData.js @@ -0,0 +1,63 @@ +import { useState } from "react"; +import ButtonFixed from "../paying/ButtonFixed"; +import { Button } from "@mui/material"; +import ArrowLeftB from "@/components/icons/ArrowLeftB"; +import { request } from "@/services/response"; + +function SubmitData({ setStep, data, prevData }) { + const [loading, setLoading] = useState(false); + const newStep = () => setStep((prev) => prev + 1); + + const handleSubmit = () => { + const isChanged = JSON.stringify(prevData) !== JSON.stringify(data); + + if (isChanged) { + setLoading(true); + let newData = data; + const { basic_insurance, name, national_code, uuid } = newData; + + newData = { + basic_insurance: [basic_insurance.value?.id], + ...(prevData.name?.value === data.name.value ? {} : { name: name }), + ...(prevData.national_code?.value + ? {} + : { national_code: national_code }), + }; + + request + .patchUserProfile(newData, uuid) + .then(() => { + setLoading(false); + newStep(); + }) + .catch(() => { + setLoading(false); + }); + } else { + newStep(); + } + }; + + return ( + + + + ); +} + +export default SubmitData; diff --git a/components/appointment/detail/index.js b/components/appointment/detail/index.js index e384397..a1af68e 100644 --- a/components/appointment/detail/index.js +++ b/components/appointment/detail/index.js @@ -1,10 +1,9 @@ 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"; +import SubmitData from "./SubmitData"; function Detail({ isForAnother, @@ -12,15 +11,11 @@ function Detail({ setIsForAnother, data, setData, + prevData, fadeElement, setIsPay, }) { const [insurance, setInsurance] = useState(); - const [selected, setSelected] = useState({ - first: "", - second: "", - }); - const changeData = (value, type, name) => setData({ ...data, @@ -30,14 +25,6 @@ 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) { @@ -61,7 +48,6 @@ function Detail({ data={data} insurance={insurance} changeData={changeData} - updateSelect={updateSelect} isForAnother={isForAnother} /> {!isForAnother && ( @@ -82,25 +68,7 @@ function Detail({

)} - - - +
); diff --git a/components/appointment/index.js b/components/appointment/index.js index 273c487..76ffa9c 100644 --- a/components/appointment/index.js +++ b/components/appointment/index.js @@ -24,7 +24,7 @@ function AppointmentPage({ slug, matchedCity }) { useEffect(() => { const userInfo = Cookies.get("userInfo"); - const parsedData = JSON.parse(userInfo); + const parsedData = userInfo && JSON.parse(userInfo); if (userInfo && parsedData) { request @@ -32,8 +32,12 @@ function AppointmentPage({ slug, matchedCity }) { .then((res) => { if (res) { const newData = { + uuid: res.uuid, phone: { value: parsedData.username || "", isEdit: false }, - national_code: { value: res.national_code || "", isEdit: true }, + national_code: { + value: res.national_code || "", + isEdit: res.national_code ? false : true, + }, name: { value: `${res.name} ${res.family}`, isEdit: true }, basic_insurance: { value: res.basic_insurance, @@ -44,6 +48,7 @@ function AppointmentPage({ slug, matchedCity }) { setPrevData(newData); } else { const emptyData = { + uuid: res.uuid, phone: { value: parsedData.username || "", isEdit: false }, national_code: { value: "", isEdit: true }, name: { value: "", isEdit: true }, @@ -56,8 +61,8 @@ function AppointmentPage({ slug, matchedCity }) { setPrevData(emptyData); } }) - .catch((err) => { - console.log(err); + .catch(() => { + // }); } }, []); @@ -69,6 +74,7 @@ function AppointmentPage({ slug, matchedCity }) { doctor={doctor} setData={setData} setStep={setStep} + prevData={prevData} matchedCity={matchedCity} isForAnother={isForAnother} setIsForAnother={setIsForAnother} diff --git a/components/doctor/detailDoctor/Title.js b/components/doctor/detailDoctor/Title.js index 71134ec..e76a96d 100644 --- a/components/doctor/detailDoctor/Title.js +++ b/components/doctor/detailDoctor/Title.js @@ -12,9 +12,10 @@ function Title({ doctor }) { img-doctor diff --git a/services/response.js b/services/response.js index 48ef63d..c90ea6d 100644 --- a/services/response.js +++ b/services/response.js @@ -37,11 +37,15 @@ export const request = { getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`), postUserProfile: (data) => api.post("api/v1/user-profile", data), patchUserProfile: (data, uuid, token) => - api.patch(`api/v1/user-profile/${uuid}`, data, { - headers: { - Authorization: `Bearer ${token}`, - }, - }), + api.patch( + `api/v1/user-profile/${uuid}`, + data, + token && { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ), getUserInfo: (headers) => api.get("oauth/userinfo", headers), getInsuranceType: () => api.get("api/v1/categorys/insurance_type", removeTokenHead),