From 41ba7aa7095606ac1a550e46a83e5bb68bc27dd9 Mon Sep 17 00:00:00 2001
From: Ehsan
Date: Mon, 15 Sep 2025 19:45:39 +0330
Subject: [PATCH] add auto-selecotr to home page and handle set in data, search
in specialties and send req for filter && add locations and change text
---
app/component/ItemDoctor.js | 4 +-
app/doctors/page.js | 3 +-
components/doctor/detailDoctor/Title.js | 4 +-
.../doctor/detailDoctor/cards/AboutDcotor.js | 2 +-
.../detailDoctor/cards/locations/Item.js | 15 ++++----
.../detailDoctor/cards/locations/index.js | 6 +--
components/doctor/index.js | 4 +-
components/doctors/search/SearchField.js | 37 +++++--------------
components/doctors/search/SendReq.js | 33 ++++++++++++++++-
components/doctors/search/index.js | 15 ++++----
components/home/search/Fields.js | 13 ++++++-
.../searchHead/smSearch/AutoCompleteSearch.js | 8 +++-
components/searchHead/smSearch/index.js | 2 -
components/specialties/index.js | 4 +-
14 files changed, 88 insertions(+), 62 deletions(-)
diff --git a/app/component/ItemDoctor.js b/app/component/ItemDoctor.js
index f96f9f1..81c3434 100644
--- a/app/component/ItemDoctor.js
+++ b/app/component/ItemDoctor.js
@@ -83,7 +83,9 @@ function ItemDoctor({ doctor }) {
}`}
>
{Number(doctor?.active)
- ? `اولین نوبت آزاد: ${moment(doctor?.free_turn * 1000)?.format("dddd jD jMMMM")}`
+ ? `اولین نوبت آزاد: ${moment(doctor?.free_turn * 1000).format(
+ "dddd jD jMMMM [ساعت] HH:mm"
+ )}`
: "نوبت ندارد"}
diff --git a/app/doctors/page.js b/app/doctors/page.js
index 6c9ee39..f3650b9 100644
--- a/app/doctors/page.js
+++ b/app/doctors/page.js
@@ -11,7 +11,8 @@ async function Doctors({ searchParams }) {
let doctors = null;
try {
let newSearchParams = searchParams;
- if (matchedCity) newSearchParams.city = matchedCity.name;
+ if (matchedCity && matchedCity.id !== "63")
+ newSearchParams.city = matchedCity.name;
if (matchedState) newSearchParams.state = matchedState.name;
const params = buildDoctorParams(searchParams);
diff --git a/components/doctor/detailDoctor/Title.js b/components/doctor/detailDoctor/Title.js
index e76a96d..bdc2840 100644
--- a/components/doctor/detailDoctor/Title.js
+++ b/components/doctor/detailDoctor/Title.js
@@ -31,9 +31,9 @@ function Title({ doctor }) {
تخصص:
- {doctor?.expertise?.map(
+ {doctor?.specialties?.map(
(item, idx) =>
- `${item.name} ${doctor.expertise.length === idx + 1 ? "" : "|"} `
+ `${item.name} ${doctor.specialties.length === idx + 1 ? "" : "|"} `
)}
diff --git a/components/doctor/detailDoctor/cards/AboutDcotor.js b/components/doctor/detailDoctor/cards/AboutDcotor.js
index 848a4ab..3287974 100644
--- a/components/doctor/detailDoctor/cards/AboutDcotor.js
+++ b/components/doctor/detailDoctor/cards/AboutDcotor.js
@@ -44,7 +44,7 @@ function AboutDcotor({ doctor }) {
تخصص ها
- {doctor?.specialties?.map((item, idx) => (
+ {doctor?.expertise?.map((item, idx) => (
-
diff --git a/components/doctor/detailDoctor/cards/locations/Item.js b/components/doctor/detailDoctor/cards/locations/Item.js
index a21cfd9..2951cce 100644
--- a/components/doctor/detailDoctor/cards/locations/Item.js
+++ b/components/doctor/detailDoctor/cards/locations/Item.js
@@ -7,7 +7,7 @@ import ModalOpenLocation from "@/app/component/openLocation";
import RoutingWhiteC from "@/components/icons/RoutingWhiteC";
import RoutingC from "@/components/icons/RoutingC";
-function Item({ data }) {
+function Item({ doctor, data }) {
const [isOpen, setIsOpen] = useState(false);
const [open, setOpen] = useState(false);
@@ -25,7 +25,7 @@ function Item({ data }) {
onClick={() => setIsOpen(!isOpen)}
className="!px-[2px] !py-[4px] !flex !items-center !justify-between !w-full"
>
-
{data.title}
+ {data.name}
- تلفن: {data.phone}
+ تلفن: {data.telephone}
- روزهای کاری: {data.working_days}
+ روزهای کاری: {doctor.hours_of_work}
+
- {doctor?.locations?.map((item, idx) => (
+ {doctor?.address?.map((item, idx) => (
-
-
- {doctor?.locations.length > idx + 1 && (
+
+ {doctor?.address.length > idx + 1 && (
)}
diff --git a/components/doctor/index.js b/components/doctor/index.js
index 2970d68..9915109 100644
--- a/components/doctor/index.js
+++ b/components/doctor/index.js
@@ -12,9 +12,9 @@ function DoctorPage({ doctor, doctors, comments }) {
- {doctor?.expertise?.map(
+ {doctor?.specialties?.map(
(item, idx) =>
- `${item.name} ${doctor.expertise.length === idx + 1 ? ">" : "|"} `
+ `${item.name} ${doctor.specialties.length === idx + 1 ? ">" : "|"} `
)}
{doctor?.name}
diff --git a/components/doctors/search/SearchField.js b/components/doctors/search/SearchField.js
index 6914710..f22e38f 100644
--- a/components/doctors/search/SearchField.js
+++ b/components/doctors/search/SearchField.js
@@ -1,33 +1,16 @@
-import { TextField } from "@mui/material";
-import React from "react";
+import AutoCompleteSearch from "@/components/searchHead/smSearch/AutoCompleteSearch";
+import specialties from "@/data/specialties.json";
function SearchField({ filter, updateData }) {
return (
-
updateData("name", e.target.value)}
- InputProps={{
- disableUnderline: true,
- }}
- sx={{
- display: "flex",
- flexDirection: "column",
- justifyContent: "center",
- width: "100% !important",
- "& .MuiInput-root": {
- padding: "0",
- borderBottom: "none",
- },
- "& .MuiInputBase-input": {
- color: "#6C757D",
- padding: "0px",
- },
- }}
- dir="rtl"
- placeholder="جستجوی نام پزشک، تخصص، بیماری ..."
- className={`!shadow-none !px-5 !h-full !w-[524px] bg-[#FAFAFA] !text-[14px] md:!text-[16px] !min-w-[50%] !rounded-0 !font-normal !text-[#6C757D]`}
- />
+
+
updateData("name", e)}
+ placeholder="جستجوی نام پزشک، تخصص، بیماری ..."
+ />
+
);
}
diff --git a/components/doctors/search/SendReq.js b/components/doctors/search/SendReq.js
index 2520ea9..e4463c9 100644
--- a/components/doctors/search/SendReq.js
+++ b/components/doctors/search/SendReq.js
@@ -1,14 +1,43 @@
import { Button } from "@mui/material";
import SearchD from "@/components/icons/SearchD";
import { useState } from "react";
+import specialties from "@/data/specialties.json";
-function SendReq({ sendReq }) {
+function SendReq({ filter, setFilter, setDataInURL, sendReq }) {
const [loading, setLoading] = useState(false);
+ const checkName = () => {
+ let newFilter = filter;
+ let reqData = filter;
+ const specialtyItem = specialties.find((item) =>
+ item.name.includes(filter.name)
+ );
+
+ if (specialtyItem) {
+ if (specialtyItem.parent) {
+ newFilter.specialty = specialtyItem;
+ newFilter.category = specialties.find(
+ (item) => item.id === specialtyItem.parent
+ );
+ } else {
+ newFilter.specialty = specialtyItem;
+ }
+ reqData = newFilter;
+ reqData.name = "";
+ } else {
+ reqData = newFilter;
+ }
+
+ setFilter(newFilter);
+ setDataInURL(newFilter);
+
+ return reqData;
+ };
const filterData = () => {
setLoading(true);
+ const reqData = checkName();
- sendReq().finally(() => {
+ sendReq(reqData).finally(() => {
setLoading(false);
});
};
diff --git a/components/doctors/search/index.js b/components/doctors/search/index.js
index 7eb5eb9..4e1d6b4 100644
--- a/components/doctors/search/index.js
+++ b/components/doctors/search/index.js
@@ -5,13 +5,7 @@ import FilterModal from "../modal/FilterModal";
import SendReq from "./SendReq";
import SearchField from "./SearchField";
-function SearchBar({
- filter,
- sendReq,
- setFilter,
- updateData,
- setDataInURL,
-}) {
+function SearchBar({ filter, sendReq, setFilter, updateData, setDataInURL }) {
return (
-
+
);
}
diff --git a/components/home/search/Fields.js b/components/home/search/Fields.js
index af05dfa..ef0828c 100644
--- a/components/home/search/Fields.js
+++ b/components/home/search/Fields.js
@@ -2,16 +2,18 @@
import { useState } from "react";
-import FilterText from "./FilterText";
import RedirectLink from "./RedirectLink";
import ModalSearchCity from "./modal";
import ButtonFilter from "./modal/ButtonFilter";
+import specialtiesData from "@/data/specialties.json";
+import AutoCompleteSearch from "@/components/searchHead/smSearch/AutoCompleteSearch";
function Fields({ city, state }) {
const [open, setOpen] = useState(false);
const [data, setData] = useState({
province: state?.name || "",
city: city?.name || "",
+ search: "",
});
return (
@@ -26,7 +28,14 @@ function Fields({ city, state }) {
-
+
+
setData({ data, search: e })}
+ placeholder="جستجوی نام پزشک، تخصص، بیماری ..."
+ />
+
>
);
diff --git a/components/searchHead/smSearch/AutoCompleteSearch.js b/components/searchHead/smSearch/AutoCompleteSearch.js
index a41ff14..1b1c511 100644
--- a/components/searchHead/smSearch/AutoCompleteSearch.js
+++ b/components/searchHead/smSearch/AutoCompleteSearch.js
@@ -20,9 +20,15 @@ function AutoCompleteSearch({
handleSearch(newInputValue);
}}
onChange={(event, newValue) => {
- setSelectedOption(newValue);
+ setSelectedOption && setSelectedOption(newValue);
handleSearch(newValue ? newValue.name : "");
}}
+ renderOption={(props, option) => (
+ -
+ {" "}
+ {option.name}
+
+ )}
sx={{
"& .MuiAutocomplete-input": {
background: "#ffffff !important",
diff --git a/components/searchHead/smSearch/index.js b/components/searchHead/smSearch/index.js
index 50ba3d2..834a732 100644
--- a/components/searchHead/smSearch/index.js
+++ b/components/searchHead/smSearch/index.js
@@ -5,7 +5,6 @@ import AutoCompleteSearch from "./AutoCompleteSearch";
function SmSearch({ placeholder, handleSearch, data }) {
const [inputValue, setInputValue] = useState("");
- const [selectedOption, setSelectedOption] = useState(null);
return (