save data modal & change list selectors & handle redirect in modal page doctors

This commit is contained in:
Ehsan
2025-05-16 13:52:47 +03:30
parent 328e11c21c
commit a016d3319a
7 changed files with 79 additions and 28 deletions
+3 -3
View File
@@ -17,11 +17,11 @@ function AutoCompleteSelect({
disablePortal disablePortal
options={list} options={list}
disabled={disabled} disabled={disabled}
value={value || null}
ListboxProps={listboxProps} ListboxProps={listboxProps}
value={value || null}
className="!w-full !rounded-lg auto-complete-selector" className="!w-full !rounded-lg auto-complete-selector"
onChange={(event, newValue) => { onChange={(e, newValue) => {
updateData && updateData(newValue ? newValue.label : "", name); updateData && updateData(newValue || "", name);
}} }}
sx={{ sx={{
...styleTextSelectRight, ...styleTextSelectRight,
+3 -2
View File
@@ -17,10 +17,11 @@ function DoctorsPage({ params, matchedCity, matchedState }) {
}); });
const [data, setData] = useState({ const [data, setData] = useState({
category: "",
expertise: "", expertise: "",
turn: true, turn: true,
gender: 0, gender: "خانم",
degree: 0, degree: "فوق تخصص",
}); });
useEffect(() => { useEffect(() => {
+50 -16
View File
@@ -1,58 +1,92 @@
import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect"; import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect";
import RadioContent from "./RadioContent"; import RadioContent from "./RadioContent";
import { Switch } from "@mui/material"; import { FormControlLabel, Switch } from "@mui/material";
import { category, expertise } from "./listSelector";
import specialties from "@/data/specialties.json"; import specialties from "@/data/specialties.json";
import { addKeyToList } from "@/helper";
const group1 = ["خانم", "آقا", "هر دو"]; const group1 = ["خانم", "آقا", "هر دو"];
const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"]; const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"];
const label = { inputProps: { "aria-label": "Switch demo" } };
function Content({ data, setData }) { function Content({ data, setData }) {
const parentList = specialties.filter(item => !item.parent);
const childrenList = specialties.filter(item => item.parent);
const changedParentList = addKeyToList(parentList, 'label', 'name') || [];
const changedChildrenList = addKeyToList(childrenList, 'label', 'name') || [];
const filteredChildrenList = changedChildrenList.filter(item => item.parent === data.category.id);
console.log(data);
const changeData = (value, name) => { const changeData = (value, name) => {
setData({ ...data, [name]: value }); console.log(value);
console.log(name);
setData({ ...data, [name]: value })
}; };
const parentList = specialties.map(item => !item.parent);
const childrenList = specialties.map(item => item.parent);
return ( return (
<div className="mt-[50px] px-[0px] md:px-[19px] lg:px-[38px] mb-[32px]"> <div className="mt-[50px] px-[0px] md:px-[19px] lg:px-[38px] mb-[32px]">
<AutoCompleteSelect <AutoCompleteSelect
list={changedParentList}
updateData={changeData} updateData={changeData}
list={category} value={data.category.name}
name="expertise"
label="دسته بندی" label="دسته بندی"
name="category"
/> />
<div className="mt-[24px]"> <div className="mt-[24px]">
<AutoCompleteSelect <AutoCompleteSelect
list={filteredChildrenList}
disabled={!data.category}
updateData={changeData} updateData={changeData}
list={expertise} value={data.expertise}
name="expertise" name="expertise"
label="تخصص" label="تخصص"
/> />
</div> </div>
<div className="mt-[40px] mb-[32px]"> <div className="mt-[40px] mb-[32px]">
<RadioContent <RadioContent
changeData={(value) => changeData(+value, "gender")} changeData={changeData}
value={data.gender} value={data.gender}
text="جنسیت پزشک" text="جنسیت پزشک"
group={group1} group={group1}
name='gender'
/> />
<span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span> <span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span>
<RadioContent <RadioContent
changeData={(value) => changeData(+value, "degree")} changeData={changeData}
value={data.degree} value={data.degree}
text="درجه علمی" text="درجه علمی"
group={group2} group={group2}
name='degree'
/> />
<span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span> <span className="block mt-[16px] mb-[24px] w-full h-px bg-[#EFEFEF]"></span>
<div className="flex items-center justify-start gap-[12px]"> <div className="flex items-center justify-start gap-[12px]">
<p className="text-[#3B3B3B] text-[16px] font-medium"> {/* <p className="text-[#3B3B3B] text-[16px] font-medium">
فقط پزشکان دارای نوبت فقط پزشکان دارای نوبت
</p> </p> */}
<Switch {/* <Switch
{...label} onChange={(event) =>
onChange={(event) => changeData(event.target.checked, "turn")} changeData(event.target.checked, "turn")
}
/> */}
<FormControlLabel
control={
<Switch
onChange={(event) => changeData(event.target.checked, "turn")}
/>
}
sx={{
".MuiFormControlLabel-label": {
color: "#3B3B3B",
fontSize: "16px",
fontWeight: 500,
},
".MuiFormControlLabel-root.MuiFormControlLabel-labelPlacementStart": {
marginRight: '0 !important'
}
}}
label="فقط پزشکان دارای نوبت"
labelPlacement="start" // متن را سمت راست یا چپ قرار می‌دهد
/> />
</div> </div>
</div> </div>
+7 -2
View File
@@ -1,11 +1,16 @@
import Radios from "./Radios"; import Radios from "./Radios";
function RadioContent({ group, text, value, changeData }) { function RadioContent({ group, text, value, changeData, name }) {
return ( return (
<div> <div>
<p className="text-[16px] font-medium text-[#3B3B3B]">{text}</p> <p className="text-[16px] font-medium text-[#3B3B3B]">{text}</p>
<div className="mt-[16px]"> <div className="mt-[16px]">
<Radios changeData={changeData} group={group} value={value} /> <Radios
changeData={changeData}
group={group}
value={value}
name={name}
/>
</div> </div>
</div> </div>
); );
+3 -3
View File
@@ -1,11 +1,11 @@
import { FormControlLabel, Radio, RadioGroup } from "@mui/material"; import { FormControlLabel, Radio, RadioGroup } from "@mui/material";
function Radios({ group, value, changeData }) { function Radios({ group, value, changeData, name }) {
return ( return (
<RadioGroup <RadioGroup
value={value} value={value}
className="radio-mui" className="radio-mui"
onChange={(e) => changeData(e.target.value)} onChange={(e) => changeData(e.target.value, name)}
sx={{ sx={{
"& .MuiFormControlLabel-root": { "& .MuiFormControlLabel-root": {
marginRight: "0 !important", marginRight: "0 !important",
@@ -18,7 +18,7 @@ function Radios({ group, value, changeData }) {
control={<Radio className="!ml-2" />} control={<Radio className="!ml-2" />}
className="!text-[#525252]" className="!text-[#525252]"
label={item} label={item}
value={idx} value={item}
key={idx} key={idx}
/> />
))} ))}
+1 -1
View File
@@ -344,4 +344,4 @@
"name": "سکته مغزی", "name": "سکته مغزی",
"parent": null "parent": null
} }
] ]
+12 -1
View File
@@ -137,4 +137,15 @@ export const searchOnList = (list, value, name) => {
item[name].toLowerCase().includes(value) item[name].toLowerCase().includes(value)
) )
return newList; return newList;
} }
export const addKeyToList = (list, nameKey, nameValue) => {
const newList = list.map(item => {
return {
...item,
[nameKey]: item[nameValue]
}
});
return newList;
}