From c5434aa438cb26108aee4b22948ba06c052bb202 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Fri, 6 Dec 2024 12:24:53 -0800 Subject: [PATCH] chore: possible fix for the autocomplete --- .../AutocompleteClientLocation/index.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/AutocompleteClientLocation/index.tsx b/frontend/src/components/AutocompleteClientLocation/index.tsx index 143ec9c1..291c5e1f 100644 --- a/frontend/src/components/AutocompleteClientLocation/index.tsx +++ b/frontend/src/components/AutocompleteClientLocation/index.tsx @@ -74,6 +74,7 @@ const AutocompleteClientLocation: React.ForwardRefExoticComponent(null); const [client, setClient] = useState(null); const [valueTyped, setValueTyped] = useState(null); + const [locationName, setLocationName] = useState(null); const clearClient = () => { updateOptions("locations", []); @@ -98,15 +99,9 @@ const AutocompleteClientLocation: React.ForwardRefExoticComponent { - console.log("handleBlur",valueTyped,options["clients"]); - console.log("handleBlur",valueTyped,options["clients"]?.find((item: AutocompleteProps) => item.label === valueTyped)); - } - useEffect(() => { const selectedItem = options["clients"]?.find((item: AutocompleteProps) => item.label === valueTyped); if(valueTyped && selectedItem){ - console.log("handleClientChange",selectedItem); selectClient(selectedItem); } @@ -114,6 +109,14 @@ const AutocompleteClientLocation: React.ForwardRefExoticComponent { + + const selectedItem = options["locations"]?.find((item: AutocompleteProps) => item.label === locationName); + if(locationName && selectedItem){ + setLocation(selectedItem); + } + }, [locationName]); + useImperativeHandle(ref, () => ({ reset: () => setLocation(null) })); @@ -131,7 +134,6 @@ const AutocompleteClientLocation: React.ForwardRefExoticComponent item.label} helperText="Search by client name, number or acronym" items={options["clients"] || []} @@ -141,6 +143,7 @@ const AutocompleteClientLocation: React.ForwardRefExoticComponent setLocation(item.selectedItem)} itemToElement={(item: AutocompleteProps) => item.label} items={options["locations"] || [{ id: "", label: "No results found" }]}