From 80c7329916a35d763c4b253d47b6a6a241586a73 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Sat, 17 May 2025 01:46:25 +0330 Subject: [PATCH] get data from url and set in state & change default value & handle delete value of states & handle list and filter category and expertise in doctors page & handle search onchange & filter list clinics on change state --- app/component/modalSearchCity/Content.js | 8 ++++- app/component/modalSearchCity/index.js | 3 +- components/clinics/head/SearchBar.js | 6 ++-- components/clinics/index.js | 8 ++--- components/doctors/index.js | 22 +++++++------ components/doctors/modal/Content.js | 41 +++++++++++++----------- components/doctors/modal/FilterModal.js | 23 ++++++------- components/doctors/search/index.js | 4 +-- components/searchHead/SmSearch.js | 5 ++- components/specialties/index.js | 9 ++---- helper/index.js | 26 +++++++++++++++ 11 files changed, 92 insertions(+), 63 deletions(-) diff --git a/app/component/modalSearchCity/Content.js b/app/component/modalSearchCity/Content.js index 321caa4..c4b5032 100644 --- a/app/component/modalSearchCity/Content.js +++ b/app/component/modalSearchCity/Content.js @@ -12,6 +12,7 @@ function Content({ updateData, handleClose, filteredCities, + handleSearch, }) { const citySelected = selected.city; const listboxProps = { @@ -21,6 +22,11 @@ function Content({ }, }; + const handleFilter = () => { + handleSearch('') + handleClose(); + } + return (
@@ -60,7 +66,7 @@ function Content({
- +
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 ( - +