Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3694 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3694 Rev 3719
Línea 1... Línea 1...
1
import React, { useEffect } from 'react';
1
import React, { useEffect } from 'react';
2
import Place from '@mui/icons-material/Place';
2
import Place from '@mui/icons-material/Place';
3
 
3
 
4
import { useLocationAutocomplete } from '@hooks';
4
import { useLocationAutocomplete } from '@hooks';
5
import Input from './Input';
5
import Input from './Input';
6
 
6
 
7
const UbicationInput = ({
7
const UbicationInput = ({
8
  onGetAddress = () => {},
8
  onGetAddress = () => {},
9
  settedQuery = '',
9
  settedQuery = '',
10
  placeholder = 'Ubicación',
10
  placeholder = 'Ubicación',
11
  onChange = () => {},
11
  onChange = () => {},
12
  error = null
12
  error = null
13
}) => {
13
}) => {
14
  const { address, error: addressError, ref } = useLocationAutocomplete();
14
  const { address, error: addressError, ref } = useLocationAutocomplete();
15
 
15
 
16
  useEffect(() => {
16
  useEffect(() => {
17
    onGetAddress(address);
17
    onGetAddress(address);
18
  }, [address]);
18
  }, [address]);
19
 
19
 
20
  const handleChangeAddress = (event) => {
20
  const handleChangeAddress = (event) => {
21
    if (!event.target.value) {
21
    if (!event.target.value) {
22
      const values = {};
22
      const values = {};
23
      Object.keys(address).forEach((key) => (values[key] = ''));
23
      Object.keys(address).forEach((key) => (values[key] = ''));
24
      onGetAddress(values);
24
      onGetAddress(values);
25
    }
25
    }
26
 
26
 
27
    onChange(event);
27
    onChange(event);
28
  };
28
  };
29
 
29
 
30
  return (
30
  return (
31
    <Input
31
    <Input
32
      type='text'
32
      type='text'
33
      inputRef={ref}
33
      inputRef={ref}
34
      onChange={handleChangeAddress}
34
      onChange={handleChangeAddress}
35
      placeholder={placeholder}
35
      placeholder={placeholder}
36
      defaultValue={settedQuery}
36
      defaultValue={settedQuery}
37
      error={error || addressError}
37
      error={error || addressError}
38
      icon={<Place />}
38
      icon={<Place />}
39
    />
39
    />
40
  );
40
  );
41
};
41
};
42
 
42
 
43
export default UbicationInput;
43
export default UbicationInput;