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
+6 -12
View File
@@ -5,22 +5,20 @@ function AutoComplete({
data,
noneBg,
clearText,
inputValue, // مقدار کنترل‌شده از والد (اختیاری)
inputValue,
placeholder,
handleSearch, // تابعی که باید با مقدار جستجو صدا زده بشه
setInputValue, // اختیاری: اگه والد دوست داره همون‌وقت مقدار رو بگیره
handleSearch,
setInputValue,
setSelectedOption,
debounce = 500, // قابل تنظیم
debounce = 500,
}) {
const typingTimeoutRef = useRef(null);
const [localInput, setLocalInput] = useState(inputValue || "");
// همگام‌سازی وقتی والد مقدار کنترل‌شده رو تغییر میده (مثلاً بعد از انتخاب گزینه)
useEffect(() => {
setLocalInput(inputValue || "");
}, [inputValue]);
// پاک‌کردن تایمر هنگام unmount
useEffect(() => {
return () => {
if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current);
@@ -28,13 +26,10 @@ function AutoComplete({
}, []);
const onInputChange = (_, newInputValue) => {
// نمایش آنی تایپ کاربر
setLocalInput(newInputValue);
// اختیاری: اگر والد خواست همون‌جا مقدار رو بگیره
if (setInputValue) setInputValue(newInputValue);
// پاک کردن تایمر قبلی و ست کردن تایمر جدید برای debounce
if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current);
typingTimeoutRef.current = setTimeout(() => {
handleSearch(newInputValue);
@@ -42,7 +37,6 @@ function AutoComplete({
};
const onChange = (_, newValue) => {
// انتخاب از لیست — مقدار رو فوراً پردازش کن
if (typingTimeoutRef.current) {
clearTimeout(typingTimeoutRef.current);
typingTimeoutRef.current = null;
@@ -55,7 +49,7 @@ function AutoComplete({
: "";
setLocalInput(val);
setSelectedOption && setSelectedOption(newValue);
handleSearch(val); // اجرای فوری روی انتخاب
handleSearch(val);
if (setInputValue) setInputValue(val);
};
@@ -67,7 +61,7 @@ function AutoComplete({
typeof option === "string" ? option : option.name
}
disableClearable
inputValue={localInput} // ← نمایش آنی از local state
inputValue={localInput}
className="!w-full"
onInputChange={onInputChange}
onChange={onChange}