Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import React, {useRef, useState} from 'react';
import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {LogBox, ScrollView, View} from 'react-native';
import {GooglePlacesAutocomplete} from 'react-native-google-places-autocomplete';
Expand Down Expand Up @@ -37,12 +37,18 @@ const propTypes = {
/** Error text to display */
errorText: PropTypes.string,

/** Hint text to display */
hint: PropTypes.string,

/** The label to display for the field */
label: PropTypes.string.isRequired,

/** The value to set the field to initially */
value: PropTypes.string,

/** The value to set the field to initially */
defaultValue: PropTypes.string,

/** A callback function when the value of this field has changed */
onInputChange: PropTypes.func.isRequired,

Expand All @@ -58,7 +64,9 @@ const defaultProps = {
shouldSaveDraft: false,
onBlur: () => {},
errorText: '',
hint: '',
value: undefined,
defaultValue: undefined,
containerStyles: [],
};

Expand All @@ -68,11 +76,6 @@ const defaultProps = {
const AddressSearch = (props) => {
const [displayListViewBorder, setDisplayListViewBorder] = useState(false);

// We use `skippedFirstOnChangeTextRef` to work around a feature of the library:
// The library is calling onChangeText with '' at the start and we don't need this
// https://github.com/FaridSafi/react-native-google-places-autocomplete/blob/47d7223dd48f85da97e80a0729a985bbbcee353f/GooglePlacesAutocomplete.js#L148
const skippedFirstOnChangeTextRef = useRef(false);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary anymore since we updated the event handler from onChangeText to onInputChange


const saveLocationDetails = (details) => {
const addressComponents = details.address_components;
if (!addressComponents) {
Expand Down Expand Up @@ -168,17 +171,19 @@ const AddressSearch = (props) => {
label: props.label,
containerStyles: props.containerStyles,
errorText: props.errorText,
hint: props.hint,
value: props.value,
defaultValue: props.defaultValue,
isFormInput: props.isFormInput,
inputID: props.inputID,
shouldSaveDraft: props.shouldSaveDraft,
onBlur: props.onBlur,
autoComplete: 'off',
onChangeText: (text) => {
if (skippedFirstOnChangeTextRef.current) {
props.onInputChange({street: text});
onInputChange: (text) => {
if (props.isFormInput) {
props.onInputChange(text);
} else {
skippedFirstOnChangeTextRef.current = true;
props.onInputChange({street: text});
}

// If the text is empty, we set displayListViewBorder to false to prevent UI flickering
Expand Down
4 changes: 1 addition & 3 deletions src/pages/EnablePayments/AdditionalDetailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,8 @@ class AdditionalDetailsStep extends React.Component {
});
}}
errorText={this.getErrorText('addressStreet')}
hint={this.props.translate('common.noPO')}
/>
<Text style={[styles.mutedTextLabel, styles.mt1]}>
{this.props.translate('common.noPO')}
</Text>
{this.props.walletAdditionalDetailsDraft.addressStreet ? (
<>
{/** Once the user has started entering his address, show the other address fields (city, state, zip) */}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/ReimbursementAccount/AddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styles from '../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import CONST from '../../CONST';
import StatePicker from '../../components/StatePicker';
import Text from '../../components/Text';

const propTypes = {

Expand Down Expand Up @@ -56,8 +55,8 @@ const AddressForm = props => (
value={props.values.street}
onInputChange={props.onFieldChange}
errorText={props.errors.street ? props.translate('bankAccount.error.addressStreet') : ''}
hint={props.translate('common.noPO')}
/>
<Text style={[styles.mutedTextLabel, styles.mt1]}>{props.translate('common.noPO')}</Text>
<View style={[styles.flexRow, styles.mt4]}>
<View style={[styles.flex2, styles.mr2]}>
<TextInput
Expand Down
6 changes: 6 additions & 0 deletions src/stories/Form.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Template = (args) => {
label="Street"
inputID="street"
containerStyles={[styles.mt4]}
hint="No PO box"
isFormInput
/>
<DatePicker
Expand Down Expand Up @@ -175,6 +176,9 @@ const defaultArgs = {
if (!values.accountNumber) {
errors.accountNumber = 'Please enter an account number';
}
if (!values.street) {
errors.street = 'Please enter an address';
}
if (!values.dob) {
errors.dob = 'Please enter your date of birth';
}
Expand Down Expand Up @@ -205,6 +209,7 @@ const defaultArgs = {
draftValues: {
routingNumber: '00001',
accountNumber: '1111222233331111',
street: '123 Happy St, Happyland HP 12345',
dob: '1990-01-01',
pickFruit: 'orange',
pickAnotherFruit: 'apple',
Expand All @@ -221,6 +226,7 @@ InputError.args = {
draftValues: {
routingNumber: '',
accountNumber: '',
street: '',
pickFruit: '',
dob: '',
pickAnotherFruit: '',
Expand Down