Feature/change any file

This commit is contained in:
AmirHossein Mahmoodi
2025-01-21 12:20:38 +00:00
parent dd4d01d639
commit 87e3281f60
42 changed files with 220 additions and 432 deletions

View File

@@ -11,34 +11,34 @@ const RahdarCode = ({ rahdarsCode, setRahdarsCode, error, multiple = true }) =>
const [loading, setLoading] = useState(false);
const requestServer = useRequest();
const fetchRahdarCodes = (inputValue, controller) => {
const debouncer = debounce((query) => {
if ((query || "").length < 3) {
setOptions([]);
return;
}
setLoading(true);
requestServer(`${GET_RAHDARANS_LIST_SEARCH}?code=${query}`, "get", {
requestOptions: { signal: controller.signal },
})
.then((response) => {
const combinedArray = rahdarsCode
? [...rahdarsCode, ...response.data.data]
: [...response.data.data];
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
setOptions(uniqueArray || []);
})
.catch(() => {
setOptions([]);
})
.finally(() => {
setLoading(false);
});
}, 500);
debouncer(inputValue);
};
useEffect(() => {
const fetchRahdarCodes = (inputValue, controller) => {
const debouncer = debounce((query) => {
if ((query || "").length < 3) {
setOptions([]);
return;
}
setLoading(true);
requestServer(`${GET_RAHDARANS_LIST_SEARCH}?code=${query}`, "get", {
requestOptions: { signal: controller.signal },
})
.then((response) => {
const combinedArray = rahdarsCode
? [...rahdarsCode, ...response.data.data]
: [...response.data.data];
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
setOptions(uniqueArray || []);
})
.catch(() => {
setOptions([]);
})
.finally(() => {
setLoading(false);
});
}, 500);
debouncer(inputValue);
};
const controller = new AbortController();
fetchRahdarCodes(inputValue, controller);
return () => controller.abort();