Rev 3046 | Rev 3694 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect } from 'react'
import { Place } from '@mui/icons-material'
import { useLocationAutocomplete } from '@hooks'
import Input from './Input'
const UbicationInput = ({
onGetAddress = () => {},
settedQuery = '',
placeholder = 'Ubicación',
onChange = () => {},
error = null
}) => {
const { address, error: addressError, ref } = useLocationAutocomplete()
useEffect(() => {
onGetAddress(address)
}, [address])
const handleChangeAddress = (event) => {
if (!event.target.value) {
const values = {}
Object.keys(address).forEach((key) => (values[key] = ''))
onGetAddress(values)
}
onChange(event)
}
return (
<Input
type='text'
inputRef={ref}
onChange={handleChangeAddress}
placeholder={placeholder}
defaultValue={settedQuery}
error={error || addressError}
icon={<Place />}
/>
)
}
export default UbicationInput