Refactor autocomplete
This commit is contained in:
parent
a3bdcb3982
commit
d106fff245
2 changed files with 13 additions and 8 deletions
|
|
@ -78,6 +78,9 @@ class FireSubscription extends React.Component {
|
||||||
<div>
|
<div>
|
||||||
<SubsAutocomplete
|
<SubsAutocomplete
|
||||||
focusInput={this.props.focusInput}
|
focusInput={this.props.focusInput}
|
||||||
|
label="Indícanos la posición de la zona a vigilar (por ej. tu pueblo, una calle, etc):"
|
||||||
|
placeHolder="Escribe aquí un lugar"
|
||||||
|
helpText="También puedes seleccionar la zona en el mapa arrastrando el puntero naranja."
|
||||||
onChange={value => this.onAutocompleteChange(value)}
|
onChange={value => this.onAutocompleteChange(value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,7 @@ class SubsAutocomplete extends React.Component {
|
||||||
geocodeByAddress(address)
|
geocodeByAddress(address)
|
||||||
.then(results => getLatLng(results[0]))
|
.then(results => getLatLng(results[0]))
|
||||||
.then(({ lat, lng }) => {
|
.then(({ lat, lng }) => {
|
||||||
// console.log('Success Yay', { lat, lng })
|
|
||||||
// const newState = update(this.state, {$merge: {lat: lat, lng: lng}});
|
|
||||||
// console.log(newState);
|
|
||||||
// this.setState(newState);
|
|
||||||
self.props.onChange({ lat, lng });
|
self.props.onChange({ lat, lng });
|
||||||
// console.log(this.state);
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|
@ -56,11 +51,15 @@ class SubsAutocomplete extends React.Component {
|
||||||
<small className="text-muted">{formattedSuggestion.secondaryText}</small>
|
<small className="text-muted">{formattedSuggestion.secondaryText}</small>
|
||||||
</div>);
|
</div>);
|
||||||
|
|
||||||
|
const {
|
||||||
|
t, label, placeHolder, helpText
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<ControlLabel>
|
<ControlLabel>
|
||||||
<Trans parent="span">Indícanos la posición de la zona a vigilar (por ej. tu pueblo, una calle, etc):</Trans>
|
{t(label)}
|
||||||
</ControlLabel>
|
</ControlLabel>
|
||||||
<PlacesAutocomplete
|
<PlacesAutocomplete
|
||||||
styles={myStyles}
|
styles={myStyles}
|
||||||
|
|
@ -84,13 +83,13 @@ class SubsAutocomplete extends React.Component {
|
||||||
{
|
{
|
||||||
value: this.state.address,
|
value: this.state.address,
|
||||||
onChange: address => this.onChange(address),
|
onChange: address => this.onChange(address),
|
||||||
placeholder: this.props.t('Escribe aquí un lugar'),
|
placeholder: t(placeHolder),
|
||||||
onBlur: () => { /* console.log('Blur event!'); */ },
|
onBlur: () => { /* console.log('Blur event!'); */ },
|
||||||
onFocus: () => { /* console.log('Focused!'); */ },
|
onFocus: () => { /* console.log('Focused!'); */ },
|
||||||
autoFocus: this.props.focusInput
|
autoFocus: this.props.focusInput
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<HelpBlock><Trans parent="span">También puedes seleccionar la zona en el mapa arrastrando el puntero naranja.</Trans></HelpBlock>
|
<HelpBlock>{t(helpText)}</HelpBlock>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
@ -100,6 +99,9 @@ class SubsAutocomplete extends React.Component {
|
||||||
SubsAutocomplete.propTypes = {
|
SubsAutocomplete.propTypes = {
|
||||||
focusInput: PropTypes.bool.isRequired,
|
focusInput: PropTypes.bool.isRequired,
|
||||||
t: PropTypes.func.isRequired,
|
t: PropTypes.func.isRequired,
|
||||||
|
label: PropTypes.string.isRequired,
|
||||||
|
placeHolder: PropTypes.string.isRequired,
|
||||||
|
helpText: PropTypes.string.isRequired,
|
||||||
i18n: PropTypes.object.isRequired
|
i18n: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue