import { Combobox, Transition } from "@headlessui/react"; import React, { Fragment, useContext, useState } from "react"; import usePlacesService from "react-google-autocomplete/lib/usePlacesAutocompleteService"; import { useController } from "react-hook-form"; import LocationIcon from "./frontend/icons/LocationIcon"; import { GlobalContext } from "@/globalContext"; export default function CustomStaticLocationAutoCompleteV2({ type, control, name, setValue, onClear, className, containerClassName, hideIcons, suggestionType, ...restProps }) { const { dispatch: globalDispatch, state: globalState } = useContext(GlobalContext); const [location, setLocation] = useState(globalState.location); const { placePredictions, getPlacePredictions, isPlacePredictionsLoading } = usePlacesService({ apiKey: import.meta.env.VITE_GOOGLE_API_KEY, options: { types: suggestionType ?? ["(region)"] }, debounce: 200, }); return ( {!hideIcons && } { setLocation(evt.target.value) getPlacePredictions({ input: evt.target.value }); }} /> {!hideIcons && globalState.location && ( )} {isPlacePredictionsLoading ? (
) : ( 0 ? "py-2 shadow-lg ring-1" : "" } absolute left-0 right-0 top-full z-50 mt-2 w-full origin-top cursor-pointer divide-y divide-gray-100 rounded-xl bg-white ring-black ring-opacity-5 focus:outline-none`} > {placePredictions.map((place, idx) => ( setValue(place?.structured_formatting.main_text + ', ' + place.structured_formatting?.secondary_text) } > {`${place.structured_formatting.main_text} ${place.structured_formatting?.secondary_text ? "," : ""} ${place.structured_formatting?.secondary_text ? place.structured_formatting?.secondary_text : ""}`} ))} )}
); }