From d04aa8568d501fabd0614b8bd5ec0925e9044465 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Tue, 9 Sep 2025 19:48:45 +0330 Subject: [PATCH] send filter degree, gender and speciality with en name, handle set url in doctors page with searchbar home for key field or search, set value of province in url with id, change filter stars with ASC and DESC, bg-color of field in spcialties --- app/component/modalSearchCity/Content.js | 53 ++++++++++++++++++++--- app/component/modalSearchCity/index.js | 9 ++-- app/doctors/page.js | 1 + components/doctors/index.js | 12 ++--- components/doctors/modal/ButtonApply.js | 39 +++++++++++++---- components/doctors/search/SendReq.js | 2 +- components/doctors/sortlist/SelectSort.js | 34 +++++++++++++-- components/doctors/sortlist/index.js | 19 +++++++- components/home/search/FilterText.js | 42 +++++++++++++++++- components/home/search/RedirectLink.js | 24 +++++++--- components/searchHead/LgSearch.js | 5 --- helper/index.js | 6 +++ 12 files changed, 203 insertions(+), 43 deletions(-) delete mode 100644 components/searchHead/LgSearch.js diff --git a/app/component/modalSearchCity/Content.js b/app/component/modalSearchCity/Content.js index b94e43f..35f2036 100644 --- a/app/component/modalSearchCity/Content.js +++ b/app/component/modalSearchCity/Content.js @@ -4,17 +4,21 @@ import { Button } from "@mui/material"; import CloseModalD from "@/components/icons/CloseModalD"; import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect"; import ArrowLeftM from "@/components/icons/ArrowLeftM"; +import { useState } from "react"; +import { request } from "@/services/response"; function Content({ state, states, selected, + setDoctors, updateData, handleClose, filteredCities, handleSearch, }) { const citySelected = selected.city; + const [loading, setLoading] = useState(false); const listboxProps = { style: { maxHeight: 200, @@ -22,12 +26,7 @@ function Content({ }, }; - const handleFilter = () => { - const city = - selected && - citySelected && - filteredCities.find((item) => item.name === citySelected); - + const handleFilter = (city) => { const current = new URLSearchParams(window.location.search); current.set("province", city.id); const newUrl = `${window.location.pathname}?${current.toString()}`; @@ -37,6 +36,45 @@ function Content({ handleClose(); }; + const sendReq = () => { + setLoading(true); + const itemCity = + selected && + citySelected && + filteredCities.find((item) => item.name === citySelected); + + const params = new URLSearchParams(window.location.search); + const specialty = params.get("specialty"); + const gender = params.get("gender"); + const degree = params.get("degree"); + const active = params.get("turn"); + + const city = + states.find((item) => item.name === selected.province)?.id || null; + const state = + filteredCities.find((item) => item.name === selected.city)?.id || null; + + const requestData = { + specialty: specialty === "null" ? null : specialty, + gender, + degree, + active, + city, + state, + }; + + request + .getDoctors(requestData) + .then((res) => { + if (res && res.data) setDoctors(res.data); + }) + .catch(() => {}) + .finally(() => { + setLoading(false); + handleFilter(itemCity); + }); + }; + const valState = selected && citySelected && @@ -78,8 +116,9 @@ function Content({
diff --git a/components/doctors/modal/ButtonApply.js b/components/doctors/modal/ButtonApply.js index dc0c126..3837e85 100644 --- a/components/doctors/modal/ButtonApply.js +++ b/components/doctors/modal/ButtonApply.js @@ -3,6 +3,7 @@ import specialties from "@/data/specialties.json"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { request } from "@/services/response"; +import { degreeVal } from "@/helper"; function ButtonApply({ data, @@ -36,21 +37,32 @@ function ButtonApply({ const mappings = [ { key: "field", - getValue: () => { + getValue: (name) => { if (data.category) { const children = specialties.filter( (item) => item.parent === data.category.id ); return children.length > 0 - ? children.find((item) => item.name === data.specialties.name) - ?.name - : data.category.name; + ? children.find((item) => item.name === data.specialties.name)[ + name || "id" + ] + : data.category[name || "id"]; } return null; }, }, - { key: "gender", getValue: () => data.gender || null }, - { key: "degree", getValue: () => data.degree || null }, + { + key: "gender", + getValue: () => (data.gender === "زن" ? "woman" : "man" || null), + }, + { + key: "degree", + getValue: (name) => { + const item = degreeVal.find((item) => item.name === data.degree); + + return (item && item[name || "val"]) || null; + }, + }, { key: "turn", getValue: () => data.turn }, ]; @@ -60,9 +72,20 @@ function ButtonApply({ }; mappings.forEach(({ key, getValue }) => { - const value = getValue(); + let value; + if (key === "field") { + value = getValue("name"); + } else if (key === "gender") { + value = data.gender; + } else if ("degree") { + value = getValue("name"); + } current.set(key, value); - requestData[key] = value; + }); + + mappings.forEach(({ key, getValue }) => { + let value = getValue(); + requestData[key === "field" ? "specialty" : key] = value; }); const queryString = current.toString(); diff --git a/components/doctors/search/SendReq.js b/components/doctors/search/SendReq.js index 7589328..23abb88 100644 --- a/components/doctors/search/SendReq.js +++ b/components/doctors/search/SendReq.js @@ -25,7 +25,7 @@ function SendReq({ fields, setDoctors, matchedCity, matchedState }) { let state = matchedState?.id || null; if (province) { const findCity = cities.find((item) => item.id === province); - const findState = states.find((item) => item.id === findCity.province_id); + const findState = states.find((item) => item.id === findCity?.province_id); if (findCity) city = findCity.id; if (findState) state = findState.id; } diff --git a/components/doctors/sortlist/SelectSort.js b/components/doctors/sortlist/SelectSort.js index 79cd577..72f5fff 100644 --- a/components/doctors/sortlist/SelectSort.js +++ b/components/doctors/sortlist/SelectSort.js @@ -1,8 +1,9 @@ import { MenuItem, Select, SvgIcon } from "@mui/material"; -import { useState } from "react"; import ArrowBottomD from "../../icons/ArrowBottomD"; import SortD from "../../icons/SortD"; import StarDI from "@/components/icons/StarDI"; +import { request } from "@/services/response"; +import { degreeVal } from "@/helper"; const listSort = [ { label: 3, id: 3 }, @@ -10,9 +11,34 @@ const listSort = [ { label: 5, id: 5 }, ]; -function SelectSort({ fields, setFields }) { - const handleChange = (event) => - setFields({ ...fields, stars: Number(event.target.value) }); +function SelectSort({ + data, + fields, + setFields, + setDoctors, + matchedCity, + matchedState, +}) { + const handleChange = (event) => { + const valSort = Number(event.target.value); + setFields({ ...fields, stars: valSort }); + const params = { sort: valSort === 3 ? "ASC" : "DESC", active: data.turn }; + if (data.specialties) params.specialty = data.specialties.id; + else if (data.category) params.specialty = data.category.id; + if (data.gender !== "هر دو") + params.gender = data.gender === "مرد" ? "man" : "woman"; + if (data.degree && data.degree !== "همه موارد") + params.degree = degreeVal.find((item) => item.name === data.degree)?.val; + if (matchedCity) params.city = matchedCity.id; + if (matchedState) params.state = matchedState.id; + + request + .getDoctors(params) + .then((res) => { + if (res && res.data) setDoctors(res.data); + }) + .catch(() => {}); + }; return (