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

@@ -10,36 +10,37 @@ const CarCode = ({ carCode, setCarCode, inputValueDefault = "", error, multiple
const [loading, setLoading] = useState(false);
const requestServer = useRequest();
const fetchCarCodes = (inputValue, controller) => {
const debouncer = debounce((query) => {
if (!query || query?.length < 3) {
setOptions([]);
return;
}
setLoading(true);
requestServer(`${GET_CAR_LIST_SEARCH}?machine_code=${query}`, "get", {
requestOptions: { signal: controller.signal },
})
.then((response) => {
const combinedArray = carCode ? [...carCode, ...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 fetchCarCodes = (inputValue, controller) => {
const debouncer = debounce((query) => {
if (!query || query?.length < 3) {
setOptions([]);
return;
}
setLoading(true);
requestServer(`${GET_CAR_LIST_SEARCH}?machine_code=${query}`, "get", {
requestOptions: { signal: controller.signal },
})
.then((response) => {
const combinedArray = carCode ? [...carCode, ...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();
fetchCarCodes(inputValue, controller);
return () => controller.abort();
}, [inputValue]);
return (
<Autocomplete
multiple={multiple}
@@ -50,7 +51,7 @@ const CarCode = ({ carCode, setCarCode, inputValueDefault = "", error, multiple
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue || ""); // Prevent inputValue from being null or undefined
setInputValue(newInputValue || "");
}}
options={options}
getOptionLabel={(option) => {