@@ -60,7 +66,7 @@ function Content({
diff --git a/components/clinics/head/SearchBar.js b/components/clinics/head/SearchBar.js
index c9ba5bc..609dac9 100644
--- a/components/clinics/head/SearchBar.js
+++ b/components/clinics/head/SearchBar.js
@@ -5,7 +5,7 @@ import ModalSearchCity from "@/app/component/modalSearchCity";
import { useState } from "react";
import ButtonFilter from "@/app/component/modalSearchCity/ButtonFilter";
-function SearchBar({ selected, setSelected, state, handleSearch, changeSearch, search }) {
+function SearchBar({ selected, setSelected, state, handleSearch }) {
const [open, setOpen] = useState(false);
return (
@@ -22,13 +22,13 @@ function SearchBar({ selected, setSelected, state, handleSearch, changeSearch, s
setOpen={setOpen}
selected={selected}
setSelected={setSelected}
+ handleSearch={handleSearch}
>
changeSearch(e.target.value)}
+ onChange={e => handleSearch(e.target.value)}
InputProps={{
disableUnderline: true,
}}
diff --git a/components/clinics/index.js b/components/clinics/index.js
index cf8b34c..c699a07 100644
--- a/components/clinics/index.js
+++ b/components/clinics/index.js
@@ -10,7 +10,6 @@ import HeadPageList from "@/app/component/head";
function ClinicsPage({ matchedCity, matchedState }) {
const [loading, setLoading] = useState(true);
- const [search, setSearch] = useState("");
const [filteredClinics, setFilteredClinics] = useState(clinics)
const [selected, setSelected] = useState({
@@ -24,10 +23,9 @@ function ClinicsPage({ matchedCity, matchedState }) {
}, 2000);
}, []);
- const changeSearch = text => setSearch(text);
- const handleSearch = () => {
- const searchOnName = searchOnList(clinics, search, 'title')
+ const handleSearch = (value) => {
+ const searchOnName = searchOnList(clinics, value, 'title')
const searchOnLocation = searchOnList(searchOnName, selected.city, 'city')
setFilteredClinics(searchOnLocation);
};
@@ -39,11 +37,9 @@ function ClinicsPage({ matchedCity, matchedState }) {
detail="در قسمت زیر می توانید کلینیک مورد نظر خود را جستجو نمایید"
>
diff --git a/components/doctors/index.js b/components/doctors/index.js
index 4200226..4c5c903 100644
--- a/components/doctors/index.js
+++ b/components/doctors/index.js
@@ -8,13 +8,8 @@ import ListDoctors from "./listDoctors";
import LocationD from "../icons/LocationD";
import ModalSearchCity from "@/app/component/modalSearchCity";
-const defaultData = {
- category: "",
- expertise: "",
- turn: true,
- gender: "هر دو",
- degree: "متخصص",
-}
+// Data
+import specialties from "@/data/specialties.json";
function DoctorsPage({ params, matchedCity, matchedState }) {
const [loading, setLoading] = useState(true);
@@ -23,8 +18,17 @@ function DoctorsPage({ params, matchedCity, matchedState }) {
province: matchedState?.name || params?.province,
city: matchedCity?.name || params?.city,
});
+ const findItem = (name, value) => specialties.find(item => item[name] === value)
+ const itemCategory = findItem('id', params.category);
+ const itemExpertise = findItem('id', params.expertise);
- const [data, setData] = useState(defaultData);
+ const [data, setData] = useState({
+ category: itemCategory || "",
+ expertise: itemExpertise ? { ...itemExpertise, label: itemExpertise.name } : "",
+ turn: params && params.hasOwnProperty('turn') ? JSON.parse(params.turn) : 1,
+ gender: params.gender || "هر دو",
+ degree: params.degree || "متخصص",
+ });
useEffect(() => {
setTimeout(() => {
@@ -55,7 +59,7 @@ function DoctorsPage({ params, matchedCity, matchedState }) {
-
+
diff --git a/components/doctors/modal/Content.js b/components/doctors/modal/Content.js
index 6a7be6f..905851d 100644
--- a/components/doctors/modal/Content.js
+++ b/components/doctors/modal/Content.js
@@ -1,46 +1,50 @@
import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect";
import RadioContent from "./RadioContent";
import { FormControlLabel, Switch } from "@mui/material";
-import specialties from "@/data/specialties.json";
-import { addKeyToList } from "@/helper";
-import { useEffect } from "react";
import { useRouter } from "next/navigation";
+import { filterList } from "@/helper";
const group1 = ["خانم", "آقا", "هر دو"];
const group2 = ["فوق تخصص", "دکترای تخصصی", "متخصص", "دکتری"];
function Content({ data, setData }) {
const router = useRouter();
- const parentList = specialties.filter(item => !item.parent);
- const childrenList = specialties.filter(item => item.parent);
+ const { parentList, childrenList } = filterList(data);
- const changedParentList = addKeyToList(parentList, 'label', 'name') || [];
- const changedChildrenList = addKeyToList(childrenList, 'label', 'name') || [];
-
- const filteredChildrenList = changedChildrenList.filter(item => item.parent === data.category.id);
-
- const changeData = (value, name) => {
+ const changeUrl = (value, name, removeExpertise) => {
const current = new URLSearchParams(window.location.search);
current.set(name, value.id || value);
+ if (removeExpertise) {
+ current.delete('expertise')
+ };
const queryString = current.toString();
router.push(`/doctors?${queryString}`)
- setData({ ...data, [name]: value });
+ }
+
+ const changeData = (value, name, removeExpertise) => {
+ changeUrl(value, name, removeExpertise);
+ const newData = data;
+ newData[name] = value;
+ if (removeExpertise) {
+ newData.expertise = ''
+ };
+ setData(newData);
}
return (
changeData(value, name, true)}
sendAll={true}
value={data.category.name}
label="دسته بندی"
name="category"
/>
- {!!filteredChildrenList.length && (
+ {!!childrenList.length && (
changeData(event.target.checked, "turn")}
+ onChange={(event) => {
+ changeData(event.target.checked ? 1 : 0, "turn")
+ }}
/>
}
sx={{
diff --git a/components/doctors/modal/FilterModal.js b/components/doctors/modal/FilterModal.js
index a85beb8..2ca74f4 100644
--- a/components/doctors/modal/FilterModal.js
+++ b/components/doctors/modal/FilterModal.js
@@ -6,27 +6,24 @@ import { Button, Modal } from "@mui/material";
import { useState } from "react";
import Content from "./Content";
import { useRouter } from "next/navigation";
+import { clearFilterParams } from "@/helper";
-function FilterModal({ data, setData, children, defaultData }) {
+function FilterModal({ data, setData, children }) {
const router = useRouter();
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
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()
+ clearFilterParams(router, ['turn', 'expertise', 'degree', 'category', 'gender'])
+ setData({
+ category: "",
+ expertise: "",
+ turn: true,
+ gender: "هر دو",
+ degree: "متخصص",
+ });
handleClose();
}
diff --git a/components/doctors/search/index.js b/components/doctors/search/index.js
index 9e20fa1..9302732 100644
--- a/components/doctors/search/index.js
+++ b/components/doctors/search/index.js
@@ -4,7 +4,7 @@ import ArrowBottomD from "@/components/icons/ArrowBottomD";
import SearchD from "@/components/icons/SearchD";
import FilterModal from "../modal/FilterModal";
-function SearchBar({ data, setData, params, defaultData }) {
+function SearchBar({ data, setData, params }) {
return (
-
+