change component file & set data in url & handle remove all variable
This commit is contained in:
@@ -10,7 +10,8 @@ function AutoCompleteSelect({
|
|||||||
name,
|
name,
|
||||||
label,
|
label,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
listboxProps
|
listboxProps,
|
||||||
|
sendAll
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
@@ -21,7 +22,7 @@ function AutoCompleteSelect({
|
|||||||
value={value || null}
|
value={value || null}
|
||||||
className="!w-full !rounded-lg auto-complete-selector"
|
className="!w-full !rounded-lg auto-complete-selector"
|
||||||
onChange={(e, newValue) => {
|
onChange={(e, newValue) => {
|
||||||
updateData && updateData(newValue || "", name);
|
updateData && updateData((newValue && sendAll) ? newValue : (newValue && !sendAll) && newValue.label || "", name);
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
...styleTextSelectRight,
|
...styleTextSelectRight,
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ import ListDoctors from "./listDoctors";
|
|||||||
import LocationD from "../icons/LocationD";
|
import LocationD from "../icons/LocationD";
|
||||||
import ModalSearchCity from "@/app/component/modalSearchCity";
|
import ModalSearchCity from "@/app/component/modalSearchCity";
|
||||||
|
|
||||||
|
const defaultData = {
|
||||||
|
category: "",
|
||||||
|
expertise: "",
|
||||||
|
turn: true,
|
||||||
|
gender: "هر دو",
|
||||||
|
degree: "متخصص",
|
||||||
|
}
|
||||||
|
|
||||||
function DoctorsPage({ params, matchedCity, matchedState }) {
|
function DoctorsPage({ params, matchedCity, matchedState }) {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -16,13 +24,7 @@ function DoctorsPage({ params, matchedCity, matchedState }) {
|
|||||||
city: matchedCity?.name || params?.city,
|
city: matchedCity?.name || params?.city,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [data, setData] = useState({
|
const [data, setData] = useState(defaultData);
|
||||||
category: "",
|
|
||||||
expertise: "",
|
|
||||||
turn: true,
|
|
||||||
gender: "خانم",
|
|
||||||
degree: "فوق تخصص",
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -53,7 +55,7 @@ function DoctorsPage({ params, matchedCity, matchedState }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</ModalSearchCity>
|
</ModalSearchCity>
|
||||||
<div className="flex flex-col lg:flex-row items-start lg:items-center justify-center gap-[24px] lg:gap-[32px] w-full">
|
<div className="flex flex-col lg:flex-row items-start lg:items-center justify-center gap-[24px] lg:gap-[32px] w-full">
|
||||||
<SearchBar data={data} setData={setData} params={params} />
|
<SearchBar data={data} setData={setData} params={params} defaultData={defaultData} />
|
||||||
<SortList data={data} setData={setData} />
|
<SortList data={data} setData={setData} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ import RadioContent from "./RadioContent";
|
|||||||
import { FormControlLabel, Switch } from "@mui/material";
|
import { FormControlLabel, Switch } from "@mui/material";
|
||||||
import specialties from "@/data/specialties.json";
|
import specialties from "@/data/specialties.json";
|
||||||
import { addKeyToList } from "@/helper";
|
import { addKeyToList } from "@/helper";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
const group1 = ["خانم", "آقا", "هر دو"];
|
const group1 = ["خانم", "آقا", "هر دو"];
|
||||||
const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"];
|
const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"];
|
||||||
|
|
||||||
|
|
||||||
function Content({ data, setData }) {
|
function Content({ data, setData }) {
|
||||||
|
const router = useRouter();
|
||||||
const parentList = specialties.filter(item => !item.parent);
|
const parentList = specialties.filter(item => !item.parent);
|
||||||
const childrenList = specialties.filter(item => item.parent);
|
const childrenList = specialties.filter(item => item.parent);
|
||||||
|
|
||||||
@@ -16,33 +19,36 @@ function Content({ data, setData }) {
|
|||||||
|
|
||||||
const filteredChildrenList = changedChildrenList.filter(item => item.parent === data.category.id);
|
const filteredChildrenList = changedChildrenList.filter(item => item.parent === data.category.id);
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
const changeData = (value, name) => {
|
const changeData = (value, name) => {
|
||||||
console.log(value);
|
const current = new URLSearchParams(window.location.search);
|
||||||
console.log(name);
|
current.set(name, value.id || value);
|
||||||
|
const queryString = current.toString();
|
||||||
setData({ ...data, [name]: value })
|
router.push(`/doctors?${queryString}`)
|
||||||
};
|
setData({ ...data, [name]: value });
|
||||||
|
}
|
||||||
|
|
||||||
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}
|
list={changedParentList}
|
||||||
updateData={changeData}
|
updateData={changeData}
|
||||||
|
sendAll={true}
|
||||||
value={data.category.name}
|
value={data.category.name}
|
||||||
label="دسته بندی"
|
label="دسته بندی"
|
||||||
name="category"
|
name="category"
|
||||||
/>
|
/>
|
||||||
|
{!!filteredChildrenList.length && (
|
||||||
<div className="mt-[24px]">
|
<div className="mt-[24px]">
|
||||||
<AutoCompleteSelect
|
<AutoCompleteSelect
|
||||||
list={filteredChildrenList}
|
list={filteredChildrenList}
|
||||||
disabled={!data.category}
|
|
||||||
updateData={changeData}
|
updateData={changeData}
|
||||||
|
sendAll={true}
|
||||||
value={data.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={changeData}
|
changeData={changeData}
|
||||||
@@ -61,17 +67,11 @@ function Content({ data, setData }) {
|
|||||||
/>
|
/>
|
||||||
<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> */}
|
|
||||||
{/* <Switch
|
|
||||||
onChange={(event) =>
|
|
||||||
changeData(event.target.checked, "turn")
|
|
||||||
}
|
|
||||||
/> */}
|
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
<Switch
|
<Switch
|
||||||
|
// value={data.turn}
|
||||||
|
checked={data.turn}
|
||||||
onChange={(event) => changeData(event.target.checked, "turn")}
|
onChange={(event) => changeData(event.target.checked, "turn")}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -81,12 +81,10 @@ function Content({ data, setData }) {
|
|||||||
fontSize: "16px",
|
fontSize: "16px",
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
},
|
},
|
||||||
".MuiFormControlLabel-root.MuiFormControlLabel-labelPlacementStart": {
|
marginLeft: '0 !important',
|
||||||
marginRight: '0 !important'
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
label="فقط پزشکان دارای نوبت"
|
label="فقط پزشکان دارای نوبت"
|
||||||
labelPlacement="start" // متن را سمت راست یا چپ قرار میدهد
|
labelPlacement="start"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,12 +5,31 @@ import { styleDefault } from "@/mui";
|
|||||||
import { Button, Modal } from "@mui/material";
|
import { Button, Modal } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
function FilterModal({ data, setData, children }) {
|
function FilterModal({ data, setData, children, defaultData }) {
|
||||||
|
const router = useRouter();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const handleOpen = () => setOpen(true);
|
const handleOpen = () => setOpen(true);
|
||||||
const handleClose = () => setOpen(false);
|
const handleClose = () => setOpen(false);
|
||||||
|
|
||||||
|
function clearFilterParams() {
|
||||||
|
const currentParams = new URLSearchParams(window.location.search);
|
||||||
|
const keysToRemove = ['turn', 'expertise', 'degree', 'category', 'gender'];
|
||||||
|
keysToRemove.forEach((key) => currentParams.delete(key));
|
||||||
|
const queryString = currentParams.toString();
|
||||||
|
const newUrl = queryString ? `/doctors?${queryString}` : '/doctors';
|
||||||
|
|
||||||
|
router.push(newUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteData = () => {
|
||||||
|
setData(defaultData);
|
||||||
|
clearFilterParams()
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Button Modal */}
|
{/* Button Modal */}
|
||||||
@@ -28,7 +47,7 @@ function FilterModal({ data, setData, children }) {
|
|||||||
<p className="text-[#3B3B3B] text-[20px] font-bold">فیلترها</p>
|
<p className="text-[#3B3B3B] text-[20px] font-bold">فیلترها</p>
|
||||||
<Button
|
<Button
|
||||||
className="cursor-pointer !p-0 flex items-center justify-center gap-1"
|
className="cursor-pointer !p-0 flex items-center justify-center gap-1"
|
||||||
onClick={handleClose}
|
onClick={deleteData}
|
||||||
variant="text"
|
variant="text"
|
||||||
>
|
>
|
||||||
<CloseOrangeModal />
|
<CloseOrangeModal />
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import ArrowBottomD from "@/components/icons/ArrowBottomD";
|
|||||||
import SearchD from "@/components/icons/SearchD";
|
import SearchD from "@/components/icons/SearchD";
|
||||||
import FilterModal from "../modal/FilterModal";
|
import FilterModal from "../modal/FilterModal";
|
||||||
|
|
||||||
function SearchBar({ data, setData, params }) {
|
function SearchBar({ data, setData, params, defaultData }) {
|
||||||
return (
|
return (
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -12,7 +12,7 @@ function SearchBar({ data, setData, params }) {
|
|||||||
flex items-center !shadow-[0px_1px_24.8px_0px_rgba(204,_204,_204,_0.18)]
|
flex items-center !shadow-[0px_1px_24.8px_0px_rgba(204,_204,_204,_0.18)]
|
||||||
!h-[44px] sm:!h-[50px] md:!h-[57px] lg:!h-[64px]"
|
!h-[44px] sm:!h-[50px] md:!h-[57px] lg:!h-[64px]"
|
||||||
>
|
>
|
||||||
<FilterModal data={data} setData={setData}>
|
<FilterModal data={data} setData={setData} defaultData={defaultData}>
|
||||||
<Button
|
<Button
|
||||||
className="!border-none !hidden lg:!flex !max-h-full !min-w-fit !h-[64px] !px-2 !bg-[#F8F8FF] !rounded-l-none"
|
className="!border-none !hidden lg:!flex !max-h-full !min-w-fit !h-[64px] !px-2 !bg-[#F8F8FF] !rounded-l-none"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
Reference in New Issue
Block a user