Skip to content

Commit

Permalink
Merge pull request #4633 from Expensify/joe-state-picker-update
Browse files Browse the repository at this point in the history
Update state picker component in VBA flow
  • Loading branch information
Luke9389 authored Aug 13, 2021
2 parents 53e30cd + abf2dcd commit 28eabfd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
24 changes: 14 additions & 10 deletions src/components/StatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@ import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {CONST} from 'expensify-common/lib/CONST';
import Picker from './Picker';
import ExpensiPicker from './ExpensiPicker';
import withLocalize, {withLocalizePropTypes} from './withLocalize';

const STATES = _.map(CONST.STATES, ({stateISO}) => ({
value: stateISO,
label: stateISO,
}));


// Add a blank state so users are sure to actively choose a state instead accidentally going with the default choice
STATES.unshift({
value: '',
label: '-',
});

const propTypes = {
/** A callback method that is called when the value changes and it received the selected value as an argument */
onChange: PropTypes.func.isRequired,

/** The value that needs to be selected */
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

...withLocalizePropTypes,
};

const defaultProps = {
value: '',
};

const StatePicker = props => <Picker items={STATES} onChange={props.onChange} value={props.value} />;
const StatePicker = props => (
<ExpensiPicker
placeholder={{value: '', label: '-'}}
items={STATES}
onChange={props.onChange}
value={props.value}
label={props.translate('common.state')}
/>
);

StatePicker.propTypes = propTypes;
StatePicker.defaultProps = defaultProps;
StatePicker.displayName = 'StatePicker';

export default StatePicker;
export default withLocalize(StatePicker);
5 changes: 2 additions & 3 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CompanyStep extends React.Component {
'companyTaxID',
'incorporationDate',
'incorporationState',
'incorporationType',
'industryCode',
'password',
];
Expand Down Expand Up @@ -191,7 +192,6 @@ class CompanyStep extends React.Component {
/>
</View>
<View style={[styles.flex1]}>
<Text style={[styles.formLabel]}>{this.props.translate('common.state')}</Text>
<StatePicker
onChange={addressState => this.setState({addressState})}
value={this.state.addressState}
Expand Down Expand Up @@ -256,7 +256,7 @@ class CompanyStep extends React.Component {
items={_.map(CONST.INCORPORATION_TYPES, (label, value) => ({value, label}))}
onChange={incorporationType => this.setState({incorporationType})}
value={this.state.incorporationType}
placeholder={{value: '', label: 'Type'}}
placeholder={{value: '', label: '-'}}
/>
</View>
<View style={[styles.flexRow, styles.mt4]}>
Expand All @@ -278,7 +278,6 @@ class CompanyStep extends React.Component {
/>
</View>
<View style={[styles.flex1]}>
<Text style={[styles.formLabel]}>{this.props.translate('common.state')}</Text>
<StatePicker
onChange={incorporationState => this.setState({incorporationState})}
value={this.state.incorporationState}
Expand Down
2 changes: 0 additions & 2 deletions src/pages/ReimbursementAccount/IdentityForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import Text from '../../components/Text';
import StatePicker from '../../components/StatePicker';
import ExpensiTextInput from '../../components/ExpensiTextInput';
import styles from '../../styles/styles';
Expand Down Expand Up @@ -134,7 +133,6 @@ const IdentityForm = ({
/>
</View>
<View style={[styles.flex1]}>
<Text style={[styles.formLabel]}>{translate('common.state')}</Text>
<StatePicker
value={state}
onChange={val => onFieldChange('state', val)}
Expand Down

0 comments on commit 28eabfd

Please sign in to comment.