update field doctors, cities, states and specialties

This commit is contained in:
ehsan
2025-09-25 17:06:57 +03:30
parent 74c6cf7b6b
commit 0db121150d
15 changed files with 336 additions and 200 deletions
+105
View File
@@ -0,0 +1,105 @@
import { Autocomplete, TextField } from "@mui/material";
import { useEffect, useRef, useState } from "react";
function AutoSearch({
data,
noneBg,
inputValue,
placeholder,
handleSearch,
setInputValue,
setSelectedOption,
debounce = 500,
}) {
const typingTimeoutRef = useRef(null);
const [localInput, setLocalInput] = useState(inputValue || "");
useEffect(() => {
setLocalInput(inputValue || "");
}, [inputValue]);
useEffect(() => {
return () => {
if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current);
};
}, []);
const onInputChange = (_, newInputValue) => {
setLocalInput(newInputValue);
if (setInputValue) setInputValue(newInputValue);
if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current);
typingTimeoutRef.current = setTimeout(() => {
handleSearch(newInputValue);
}, debounce);
};
const onChange = (_, newValue) => {
if (typingTimeoutRef.current) {
clearTimeout(typingTimeoutRef.current);
typingTimeoutRef.current = null;
}
const val = newValue
? typeof newValue === "string"
? newValue
: newValue.name
: "";
setLocalInput(val);
setSelectedOption && setSelectedOption(newValue);
handleSearch(val);
if (setInputValue) setInputValue(val);
};
return (
<Autocomplete
freeSolo
options={data}
getOptionLabel={(option) =>
typeof option === "string" ? option : option.name
}
disableClearable
inputValue={localInput}
className="!w-full"
onInputChange={onInputChange}
onChange={onChange}
renderOption={(props, option) => (
<li {...props} key={option.id}>
{option.name}
</li>
)}
sx={{
"& .MuiAutocomplete-input": {
background: noneBg ? "" : "#ffffff !important",
},
}}
renderInput={(params) => (
<TextField
{...params}
variant="standard"
placeholder={placeholder}
dir="rtl"
InputProps={{
...params.InputProps,
disableUnderline: true,
style: { height: "100%" },
}}
sx={{
background: "transparent !important",
"& .MuiInputBase-input": {
background: "#FAFAFA",
color: "#6C757D",
padding: "0 16px",
fontSize: "14px",
fontFamily: "inherit",
},
}}
className="!shadow-none !w-full !px-5 !h-full !text-[14px] md:!text-[16px] !min-w-[50%] !rounded-0 !font-normal"
/>
)}
/>
);
}
export default AutoSearch;
+33
View File
@@ -0,0 +1,33 @@
import SearchD from "@/components/icons/SearchD";
import { Button } from "@mui/material";
import { useState } from "react";
function FilterButton({ setFilteredClinics }) {
const [loading, setLoading] = useState(false);
const filterData = () => {
setLoading(true)
};
return (
<Button
onClick={filterData}
loading={loading}
className="
!rounded-[4px] !gap-2.5 !p-2 md:!p-3 lg:!p-4 !grid !place-items-center
!w-[38px] sm:!w-[44px] md:!w-[50px] lg:!w-[56px]
!h-[38px] sm:!h-[44px] md:!h-[50px] lg:!h-[56px]
!min-w-[38px] sm:!min-w-[44px] md:!min-w-[50px] lg:!min-w-[56px]
!min-h-[38px] sm:!min-h-[44px] md:!min-h-[50px] lg:!min-h-[56px]
!max-w-[38px] sm:!max-w-[44px] md:!max-w-[50px] lg:!max-w-[56px]
!max-h-[38px] sm:!max-h-[44px] md:!max-h-[50px] lg:!max-h-[56px]
"
>
<div className="w-[24px] h-[24px] min-w-[24px] min-h-[24px] grid place-items-center">
{!loading && <SearchD />}
</div>
<SearchD />
</Button>
);
}
export default FilterButton;
+26 -23
View File
@@ -1,18 +1,34 @@
import { Button, ButtonGroup, TextField } from "@mui/material";
import SearchD from "@/components/icons/SearchD";
import { ButtonGroup } from "@mui/material";
import { useState } from "react";
import ButtonFilter from "@/app/component/modalSearchCity/ButtonFilter";
import AutoCompleteSearch from "@/components/searchHead/smSearch/AutoCompleteSearch";
import ModalSearchCity from "@/components/home/search/modal";
import AutoSearch from "./AutoSearch";
import { useRouter } from "next/navigation";
import FilterButton from "./FilterButton";
function SearchBar({
selected,
setSelected,
specialties,
state,
handleSearch,
selected,
specialties,
setSelected,
setFilteredClinics,
}) {
const [open, setOpen] = useState(false);
const router = useRouter();
const handleSearch = (e) => {
const specialty = specialties.find((item) => item.name === e);
const searchParams = new URLSearchParams(window.location.search);
if (specialty) {
searchParams.set("specialty", specialty.name);
setSelected({ ...selected, specialty: specialty.name });
} else {
e ? searchParams.set("specialty", e) : searchParams.delete("specialty");
setSelected({ ...selected, specialty: e });
}
router.push(`?${searchParams.toString()}`);
};
return (
<ButtonGroup
@@ -28,29 +44,16 @@ function SearchBar({
setOpen={setOpen}
selected={selected}
setSelected={setSelected}
// handleSearch={handleSearch}
>
<ButtonFilter setOpen={setOpen} selected={selected} />
</ModalSearchCity>
<AutoCompleteSearch
<AutoSearch
data={specialties}
inputValue={selected.specialty}
placeholder="جستجوی تخصص"
handleSearch={handleSearch}
/>
<Button
onClick={handleSearch}
className="
!rounded-[4px] !gap-2.5 !p-2 md:!p-3 lg:!p-4
!w-[38px] sm:!w-[44px] md:!w-[50px] lg:!w-[56px]
!h-[38px] sm:!h-[44px] md:!h-[50px] lg:!h-[56px]
!min-w-[38px] sm:!min-w-[44px] md:!min-w-[50px] lg:!min-w-[56px]
!min-h-[38px] sm:!min-h-[44px] md:!min-h-[50px] lg:!min-h-[56px]
!max-w-[38px] sm:!max-w-[44px] md:!max-w-[50px] lg:!max-w-[56px]
!max-h-[38px] sm:!max-h-[44px] md:!max-h-[50px] lg:!max-h-[56px]
"
>
<SearchD />
</Button>
<FilterButton setFilteredClinics={setFilteredClinics} />
</ButtonGroup>
);
}
+2 -10
View File
@@ -5,25 +5,17 @@ import { useState } from "react";
import List from "./list";
import SearchBar from "./head/SearchBar";
import HeadPageList from "@/app/component/head";
import { useRouter } from "next/navigation";
import specialtiesData from "@/data/specialties.json";
function ClinicsPage({ clinics, matchedCity, matchedState }) {
const router = useRouter();
const [filteredClinics, setFilteredClinics] = useState(clinics);
const [selected, setSelected] = useState({
province: matchedState?.name || "",
city: matchedCity?.name || "",
specialty: "",
});
const handleSearch = (value) => {
// const current = new URLSearchParams(window.location.search);
// current.set("search", value);
// const queryString = current.toString();
// router.push(`/clinics?${queryString}`);
};
return (
<div>
<HeadPageList
@@ -34,8 +26,8 @@ function ClinicsPage({ clinics, matchedCity, matchedState }) {
selected={selected}
state={matchedState}
setSelected={setSelected}
handleSearch={handleSearch}
specialties={specialtiesData}
setFilteredClinics={setFilteredClinics}
/>
</HeadPageList>
<List selected={selected} clinics={filteredClinics} />