From a016d3319a71e60b404139440af6e6007119707c Mon Sep 17 00:00:00 2001 From: Ehsan Date: Fri, 16 May 2025 13:52:47 +0330 Subject: [PATCH] save data modal & change list selectors & handle redirect in modal page doctors --- app/component/element/AutoCompleteSelect.js | 6 +- components/doctors/index.js | 5 +- components/doctors/modal/Content.js | 66 ++++++++++++++++----- components/doctors/modal/RadioContent.js | 9 ++- components/doctors/modal/Radios.js | 6 +- data/specialties.json | 2 +- helper/index.js | 13 +++- 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/app/component/element/AutoCompleteSelect.js b/app/component/element/AutoCompleteSelect.js index 11a77ed..ecfb3a4 100644 --- a/app/component/element/AutoCompleteSelect.js +++ b/app/component/element/AutoCompleteSelect.js @@ -17,11 +17,11 @@ function AutoCompleteSelect({ disablePortal options={list} disabled={disabled} - value={value || null} ListboxProps={listboxProps} + value={value || null} className="!w-full !rounded-lg auto-complete-selector" - onChange={(event, newValue) => { - updateData && updateData(newValue ? newValue.label : "", name); + onChange={(e, newValue) => { + updateData && updateData(newValue || "", name); }} sx={{ ...styleTextSelectRight, diff --git a/components/doctors/index.js b/components/doctors/index.js index 252e669..e8d1127 100644 --- a/components/doctors/index.js +++ b/components/doctors/index.js @@ -17,10 +17,11 @@ function DoctorsPage({ params, matchedCity, matchedState }) { }); const [data, setData] = useState({ + category: "", expertise: "", turn: true, - gender: 0, - degree: 0, + gender: "خانم", + degree: "فوق تخصص", }); useEffect(() => { diff --git a/components/doctors/modal/Content.js b/components/doctors/modal/Content.js index 894ea4a..e607ef1 100644 --- a/components/doctors/modal/Content.js +++ b/components/doctors/modal/Content.js @@ -1,58 +1,92 @@ import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect"; import RadioContent from "./RadioContent"; -import { Switch } from "@mui/material"; -import { category, expertise } from "./listSelector"; +import { FormControlLabel, Switch } from "@mui/material"; import specialties from "@/data/specialties.json"; +import { addKeyToList } from "@/helper"; const group1 = ["خانم", "آقا", "هر دو"]; const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"]; -const label = { inputProps: { "aria-label": "Switch demo" } }; 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) => { - 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 (
changeData(+value, "gender")} + changeData={changeData} value={data.gender} text="جنسیت پزشک" group={group1} + name='gender' /> changeData(+value, "degree")} + changeData={changeData} value={data.degree} text="درجه علمی" group={group2} + name='degree' />
-

+ {/*

فقط پزشکان دارای نوبت -

- changeData(event.target.checked, "turn")} +

*/} + {/* + changeData(event.target.checked, "turn") + } + /> */} + changeData(event.target.checked, "turn")} + /> + } + sx={{ + ".MuiFormControlLabel-label": { + color: "#3B3B3B", + fontSize: "16px", + fontWeight: 500, + }, + ".MuiFormControlLabel-root.MuiFormControlLabel-labelPlacementStart": { + marginRight: '0 !important' + } + }} + label="فقط پزشکان دارای نوبت" + labelPlacement="start" // متن را سمت راست یا چپ قرار می‌دهد />
diff --git a/components/doctors/modal/RadioContent.js b/components/doctors/modal/RadioContent.js index 18811f2..c0f8366 100644 --- a/components/doctors/modal/RadioContent.js +++ b/components/doctors/modal/RadioContent.js @@ -1,11 +1,16 @@ import Radios from "./Radios"; -function RadioContent({ group, text, value, changeData }) { +function RadioContent({ group, text, value, changeData, name }) { return (

{text}

- +
); diff --git a/components/doctors/modal/Radios.js b/components/doctors/modal/Radios.js index 976ad47..bec8123 100644 --- a/components/doctors/modal/Radios.js +++ b/components/doctors/modal/Radios.js @@ -1,11 +1,11 @@ import { FormControlLabel, Radio, RadioGroup } from "@mui/material"; -function Radios({ group, value, changeData }) { +function Radios({ group, value, changeData, name }) { return ( changeData(e.target.value)} + onChange={(e) => changeData(e.target.value, name)} sx={{ "& .MuiFormControlLabel-root": { marginRight: "0 !important", @@ -18,7 +18,7 @@ function Radios({ group, value, changeData }) { control={} className="!text-[#525252]" label={item} - value={idx} + value={item} key={idx} /> ))} diff --git a/data/specialties.json b/data/specialties.json index 6720455..86bebd7 100644 --- a/data/specialties.json +++ b/data/specialties.json @@ -344,4 +344,4 @@ "name": "سکته مغزی", "parent": null } -] +] \ No newline at end of file diff --git a/helper/index.js b/helper/index.js index 93be8ec..969f186 100644 --- a/helper/index.js +++ b/helper/index.js @@ -137,4 +137,15 @@ export const searchOnList = (list, value, name) => { item[name].toLowerCase().includes(value) ) return newList; -} \ No newline at end of file +} + +export const addKeyToList = (list, nameKey, nameValue) => { + const newList = list.map(item => { + return { + ...item, + [nameKey]: item[nameValue] + } + }); + + return newList; +} \ No newline at end of file