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

This commit is contained in:
Ehsan
2025-09-02 00:32:04 +03:30
parent 1e70d88a84
commit 6920e4078b
9 changed files with 96 additions and 52 deletions
+2 -2
View File
@@ -20,9 +20,9 @@ function ItemDoctor({ doctor }) {
<Image <Image
width={72} width={72}
height={72} height={72}
src={doctor?.img} src={doctor?.img[0]?.url}
alt="image-doctor" alt="image-doctor"
className="w-[64px] md:w-[68px] lg:w-[72px] h-[64px] md:h-[68px] lg:h-[72px]" className="object-contain w-[64px] md:w-[68px] lg:w-[72px] h-[64px] md:h-[68px] lg:h-[72px]"
/> />
</CircularLoading> </CircularLoading>
<div className="flex flex-col items-start justify-center gap-2"> <div className="flex flex-col items-start justify-center gap-2">
+2
View File
@@ -14,6 +14,7 @@ function Container({
doctor, doctor,
setData, setData,
setStep, setStep,
prevData,
matchedCity, matchedCity,
isForAnother, isForAnother,
setIsForAnother, setIsForAnother,
@@ -26,6 +27,7 @@ function Container({
data={data} data={data}
setStep={setStep} setStep={setStep}
setData={setData} setData={setData}
prevData={prevData}
isForAnother={isForAnother} isForAnother={isForAnother}
setIsForAnother={setIsForAnother} setIsForAnother={setIsForAnother}
/>, />,
+2 -2
View File
@@ -2,7 +2,7 @@ import Content from "./Content";
import EditField from "../../../app/component/fields/EditField"; import EditField from "../../../app/component/fields/EditField";
import DefaultSelect from "@/app/component/selectors/DefaultSelect"; import DefaultSelect from "@/app/component/selectors/DefaultSelect";
function Form({ changeData, insurance, data, updateSelect, isForAnother }) { function Form({ changeData, insurance, data, isForAnother }) {
const findVal = () => { const findVal = () => {
return insurance?.find( return insurance?.find(
(g) => (g) =>
@@ -31,7 +31,7 @@ function Form({ changeData, insurance, data, updateSelect, isForAnother }) {
</Content> </Content>
<Content title="نوع بیمه"> <Content title="نوع بیمه">
<DefaultSelect <DefaultSelect
updateData={(name, val) => updateSelect(val, "value", name)} updateData={(name, val) => changeData(val, "value", name)}
label="نوع بیمه" label="نوع بیمه"
name="basic_insurance" name="basic_insurance"
list={insurance} list={insurance}
@@ -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 (
<ButtonFixed>
<Button
loading={loading}
className={`
!flex !w-full md:!w-fit !mt-0 md:!mt-[32px]
!gap-[4px] md:!mr-auto !px-[12px] !py-[8px] md:!py-[9px] !min-w-[150px]
`}
variant="contained"
onClick={handleSubmit}
>
<p
className={`${loading && "opacity-0"} text-[#EFEFEF] text-[16px] font-medium`}
>
ثبت اطلاعات
</p>
<ArrowLeftB />
</Button>
</ButtonFixed>
);
}
export default SubmitData;
+3 -35
View File
@@ -1,10 +1,9 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import AddCircleBlueA from "@/components/icons/AddCircleBlueA"; import AddCircleBlueA from "@/components/icons/AddCircleBlueA";
import ArrowLeftB from "@/components/icons/ArrowLeftB";
import ButtonFixed from "../paying/ButtonFixed";
import Form from "./Form"; import Form from "./Form";
import { request } from "@/services/response"; import { request } from "@/services/response";
import SubmitData from "./SubmitData";
function Detail({ function Detail({
isForAnother, isForAnother,
@@ -12,15 +11,11 @@ function Detail({
setIsForAnother, setIsForAnother,
data, data,
setData, setData,
prevData,
fadeElement, fadeElement,
setIsPay, setIsPay,
}) { }) {
const [insurance, setInsurance] = useState(); const [insurance, setInsurance] = useState();
const [selected, setSelected] = useState({
first: "",
second: "",
});
const changeData = (value, type, name) => const changeData = (value, type, name) =>
setData({ setData({
...data, ...data,
@@ -30,14 +25,6 @@ function Detail({
}, },
}); });
const updateSelect = (event, name) =>
setSelected({ ...selected, [name]: event });
const newStep = () => {
// if(data)
setStep((prev) => prev + 1);
};
useEffect(() => { useEffect(() => {
request.getInsuranceType().then((res) => { request.getInsuranceType().then((res) => {
if (res && res.data) { if (res && res.data) {
@@ -61,7 +48,6 @@ function Detail({
data={data} data={data}
insurance={insurance} insurance={insurance}
changeData={changeData} changeData={changeData}
updateSelect={updateSelect}
isForAnother={isForAnother} isForAnother={isForAnother}
/> />
{!isForAnother && ( {!isForAnother && (
@@ -82,25 +68,7 @@ function Detail({
</p> </p>
</Button> </Button>
)} )}
<ButtonFixed> <SubmitData setStep={setStep} data={data} prevData={prevData} />
<Button
className={`
!flex !w-full md:!w-fit
!gap-[4px] md:!mr-auto !px-[12px] !py-[8px] md:!py-[9px] !min-w-[150px]
${
isForAnother
? "!mt-0 md:!mt-[40px]"
: "!mt-0 md:!mt-[32px]"
}`}
variant="contained"
onClick={newStep}
>
<p className="text-[#EFEFEF] text-[16px] font-medium">
ثبت اطلاعات
</p>
<ArrowLeftB />
</Button>
</ButtonFixed>
</div> </div>
</div> </div>
); );
+10 -4
View File
@@ -24,7 +24,7 @@ function AppointmentPage({ slug, matchedCity }) {
useEffect(() => { useEffect(() => {
const userInfo = Cookies.get("userInfo"); const userInfo = Cookies.get("userInfo");
const parsedData = JSON.parse(userInfo); const parsedData = userInfo && JSON.parse(userInfo);
if (userInfo && parsedData) { if (userInfo && parsedData) {
request request
@@ -32,8 +32,12 @@ function AppointmentPage({ slug, matchedCity }) {
.then((res) => { .then((res) => {
if (res) { if (res) {
const newData = { const newData = {
uuid: res.uuid,
phone: { value: parsedData.username || "", isEdit: false }, 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 }, name: { value: `${res.name} ${res.family}`, isEdit: true },
basic_insurance: { basic_insurance: {
value: res.basic_insurance, value: res.basic_insurance,
@@ -44,6 +48,7 @@ function AppointmentPage({ slug, matchedCity }) {
setPrevData(newData); setPrevData(newData);
} else { } else {
const emptyData = { const emptyData = {
uuid: res.uuid,
phone: { value: parsedData.username || "", isEdit: false }, phone: { value: parsedData.username || "", isEdit: false },
national_code: { value: "", isEdit: true }, national_code: { value: "", isEdit: true },
name: { value: "", isEdit: true }, name: { value: "", isEdit: true },
@@ -56,8 +61,8 @@ function AppointmentPage({ slug, matchedCity }) {
setPrevData(emptyData); setPrevData(emptyData);
} }
}) })
.catch((err) => { .catch(() => {
console.log(err); //
}); });
} }
}, []); }, []);
@@ -69,6 +74,7 @@ function AppointmentPage({ slug, matchedCity }) {
doctor={doctor} doctor={doctor}
setData={setData} setData={setData}
setStep={setStep} setStep={setStep}
prevData={prevData}
matchedCity={matchedCity} matchedCity={matchedCity}
isForAnother={isForAnother} isForAnother={isForAnother}
setIsForAnother={setIsForAnother} setIsForAnother={setIsForAnother}
+4 -3
View File
@@ -12,9 +12,10 @@ function Title({ doctor }) {
<CircularLoading width={100} height={100}> <CircularLoading width={100} height={100}>
<Image <Image
className=" className="
w-[40px] sm:w-[81px] md:w-[123px] lg:w-[164px] object-contain
h-[40px] sm:h-[81px] md:h-[123px] lg:h-[164px] w-[40px] sm:w-[81px] md:w-[123px] lg:w-[164px]
" h-[40px] sm:h-[81px] md:h-[123px] lg:h-[164px]
"
src={doctor?.img[0]?.url} src={doctor?.img[0]?.url}
alt="img-doctor" alt="img-doctor"
height={164} height={164}
+1 -1
View File
@@ -17,7 +17,7 @@ function FrequentSearches() {
href={{ href={{
pathname: "/doctors", pathname: "/doctors",
query: { query: {
specialties: item.id, field: item.id,
}, },
}} }}
> >
+9 -5
View File
@@ -37,11 +37,15 @@ export const request = {
getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`), getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`),
postUserProfile: (data) => api.post("api/v1/user-profile", data), postUserProfile: (data) => api.post("api/v1/user-profile", data),
patchUserProfile: (data, uuid, token) => patchUserProfile: (data, uuid, token) =>
api.patch(`api/v1/user-profile/${uuid}`, data, { api.patch(
headers: { `api/v1/user-profile/${uuid}`,
Authorization: `Bearer ${token}`, data,
}, token && {
}), headers: {
Authorization: `Bearer ${token}`,
},
}
),
getUserInfo: (headers) => api.get("oauth/userinfo", headers), getUserInfo: (headers) => api.get("oauth/userinfo", headers),
getInsuranceType: () => getInsuranceType: () =>
api.get("api/v1/categorys/insurance_type", removeTokenHead), api.get("api/v1/categorys/insurance_type", removeTokenHead),