change bg of auto-selector, remove value of search from url when click on x button on autoselector, remove to set data of search field in clinics page, fix remove data and update state filter after click on clearAll text in autoselector of doctors age

This commit is contained in:
ehsan
2025-09-17 20:08:42 +03:30
parent 41ba7aa709
commit a6386e693f
8 changed files with 57 additions and 41 deletions
-16
View File
@@ -37,22 +37,6 @@ function SearchBar({
placeholder="جستجوی تخصص" placeholder="جستجوی تخصص"
handleSearch={handleSearch} handleSearch={handleSearch}
/> />
{/* <TextField
variant="standard"
onChange={(e) => handleSearch(e.target.value)}
InputProps={{
disableUnderline: true,
}}
sx={{
background: "transparent !important",
"& .MuiInputBase-input": { color: "#7E7E7E" },
"& .MuiInput-root": { borderBottom: "none" },
"& .MuiInputBase-root": { height: "100%" },
}}
placeholder="جستجوی تخصص"
dir="rtl"
className={`!shadow-none !w-full !min-w-3 !px-5 !h-full bg-[#FAFAFA] !text-[14px] md:!text-[16px] lg:!min-w-[50%] !rounded-0 !font-normal !text-[#6C757D]`}
/> */}
<Button <Button
onClick={handleSearch} onClick={handleSearch}
className=" className="
+4 -4
View File
@@ -18,10 +18,10 @@ function ClinicsPage({ clinics, matchedCity, matchedState }) {
}); });
const handleSearch = (value) => { const handleSearch = (value) => {
const current = new URLSearchParams(window.location.search); // const current = new URLSearchParams(window.location.search);
current.set("search", value); // current.set("search", value);
const queryString = current.toString(); // const queryString = current.toString();
router.push(`/clinics?${queryString}`); // router.push(`/clinics?${queryString}`);
}; };
return ( return (
+1
View File
@@ -67,6 +67,7 @@ function Head({ matchedCity, matchedState, setDoctors }) {
throw err; throw err;
}); });
}; };
console.log(filter);
return ( return (
<div className="flex justify-center gap-[16px] sm:gap-[19px] md:gap-[22px] lg:gap-[24px] flex-col items-center mt-0 md:mt-[40px] lg:mt-[90px]"> <div className="flex justify-center gap-[16px] sm:gap-[19px] md:gap-[22px] lg:gap-[24px] flex-col items-center mt-0 md:mt-[40px] lg:mt-[90px]">
+19 -1
View File
@@ -1,11 +1,29 @@
import AutoCompleteSearch from "@/components/searchHead/smSearch/AutoCompleteSearch"; import AutoCompleteSearch from "@/components/searchHead/smSearch/AutoCompleteSearch";
import specialties from "@/data/specialties.json"; import specialties from "@/data/specialties.json";
import { clearFilterParams } from "@/helper";
import { useRouter } from "next/navigation";
function SearchField({ filter, updateData }) { function SearchField({ filter, setFilter, updateData, setDataInURL }) {
const router = useRouter();
const clearText = () => {
clearFilterParams(router, ["name", "category", "specialty"]);
const newFilter = {
...filter,
...{
name: "",
category: undefined,
specialty: undefined,
},
};
setFilter(newFilter);
// setDataInURL(newFilter);
};
return ( return (
<div className="!min-w-[50%] !w-[524px]"> <div className="!min-w-[50%] !w-[524px]">
<AutoCompleteSearch <AutoCompleteSearch
data={specialties} data={specialties}
clearText={clearText}
inputValue={filter.name} inputValue={filter.name}
handleSearch={(e) => updateData("name", e)} handleSearch={(e) => updateData("name", e)}
placeholder="جستجوی نام پزشک، تخصص، بیماری ..." placeholder="جستجوی نام پزشک، تخصص، بیماری ..."
+8 -14
View File
@@ -7,10 +7,9 @@ function SendReq({ filter, setFilter, setDataInURL, sendReq }) {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const checkName = () => { const checkName = () => {
let newFilter = filter; let newFilter = filter;
let reqData = filter; const specialtyItem =
const specialtyItem = specialties.find((item) => filter.name &&
item.name.includes(filter.name) specialties.find((item) => item.name.includes(filter.name));
);
if (specialtyItem) { if (specialtyItem) {
if (specialtyItem.parent) { if (specialtyItem.parent) {
@@ -21,23 +20,18 @@ function SendReq({ filter, setFilter, setDataInURL, sendReq }) {
} else { } else {
newFilter.specialty = specialtyItem; newFilter.specialty = specialtyItem;
} }
reqData = newFilter;
reqData.name = "";
} else {
reqData = newFilter;
} }
setFilter(newFilter); return newFilter;
setDataInURL(newFilter);
return reqData;
}; };
const filterData = () => { const filterData = () => {
setLoading(true); setLoading(true);
const reqData = checkName(); const newFilter = checkName();
setFilter(newFilter);
setDataInURL(newFilter);
sendReq(reqData).finally(() => { sendReq(newFilter).finally(() => {
setLoading(false); setLoading(false);
}); });
}; };
+6 -1
View File
@@ -36,7 +36,12 @@ function SearchBar({ filter, sendReq, setFilter, updateData, setDataInURL }) {
</div> </div>
</Button> </Button>
</FilterModal> </FilterModal>
<SearchField filter={filter} updateData={updateData} /> <SearchField
filter={filter}
setFilter={setFilter}
updateData={updateData}
setDataInURL={setDataInURL}
/>
<SendReq <SendReq
filter={filter} filter={filter}
sendReq={sendReq} sendReq={sendReq}
+2 -1
View File
@@ -28,8 +28,9 @@ function Fields({ city, state }) {
<ButtonFilter setOpen={setOpen} selected={data} /> <ButtonFilter setOpen={setOpen} selected={data} />
</ModalSearchCity> </ModalSearchCity>
<span className="black w-px bg-[#EFEFEF]"></span> <span className="black w-px bg-[#EFEFEF]"></span>
<div className=" !w-full lg:!w-[524px]"> <div className="!w-full lg:!w-[524px] flex items-center justify-start">
<AutoCompleteSearch <AutoCompleteSearch
noneBg={true}
data={specialtiesData} data={specialtiesData}
inputValue={data.search} inputValue={data.search}
handleSearch={(e) => setData({ data, search: e })} handleSearch={(e) => setData({ data, search: e })}
@@ -2,12 +2,25 @@ import { Autocomplete, TextField } from "@mui/material";
function AutoCompleteSearch({ function AutoCompleteSearch({
data, data,
noneBg,
clearText,
inputValue, inputValue,
placeholder, placeholder,
handleSearch, handleSearch,
setInputValue, setInputValue,
setSelectedOption, setSelectedOption,
}) { }) {
// ایجاد props شرطی برای clearIndicator
const clearIndicatorProps = clearText
? {
clearIndicator: {
onClick: () => {
clearText();
},
},
}
: {};
return ( return (
<Autocomplete <Autocomplete
freeSolo freeSolo
@@ -15,23 +28,23 @@ function AutoCompleteSearch({
getOptionLabel={(option) => option.name} getOptionLabel={(option) => option.name}
inputValue={inputValue} inputValue={inputValue}
className="!w-full" className="!w-full"
onInputChange={(event, newInputValue) => { onInputChange={(_, newInputValue) => {
setInputValue && setInputValue(newInputValue); setInputValue && setInputValue(newInputValue);
handleSearch(newInputValue); handleSearch(newInputValue);
}} }}
onChange={(event, newValue) => { onChange={(_, newValue) => {
setSelectedOption && setSelectedOption(newValue); setSelectedOption && setSelectedOption(newValue);
handleSearch(newValue ? newValue.name : ""); handleSearch(newValue ? newValue.name : "");
}} }}
componentsProps={clearIndicatorProps}
renderOption={(props, option) => ( renderOption={(props, option) => (
<li {...props} key={option.id}> <li {...props} key={option.id}>
{" "}
{option.name} {option.name}
</li> </li>
)} )}
sx={{ sx={{
"& .MuiAutocomplete-input": { "& .MuiAutocomplete-input": {
background: "#ffffff !important", background: noneBg ? "" : "#ffffff !important",
}, },
}} }}
renderInput={(params) => ( renderInput={(params) => (