Skip to content

Commit

Permalink
Merge pull request #1100 from salar-fs/signup-dob-state
Browse files Browse the repository at this point in the history
salar / signup dob state
  • Loading branch information
negar-binary authored May 12, 2020
2 parents 30b1c18 + ade4d64 commit 9cca7b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DatePicker extends React.PureComponent {
date: this.props.value ? toMoment(this.props.value).format(this.props.display_format) : '',
duration: daysFromTodayTo(this.props.value),
is_datepicker_visible: false,
is_placeholder_visible: this.props.placeholder,
is_placeholder_visible: this.props.placeholder && !this.props.value,
};

componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getLocation = (location_list, value, type) => {
class AddressDetails extends Component {
constructor(props) {
super(props);
this.state = { has_fetched_states_list: false };
this.state = { has_fetched_states_list: false, address_state_to_display: '' };
this.form = React.createRef();
// TODO: Find a better solution for handling no-op instead of using is_mounted flags
this.is_mounted = false;
Expand All @@ -55,7 +55,11 @@ class AddressDetails extends Component {
async componentDidMount() {
this.is_mounted = true;
await this.props.fetchStatesList();
if (this.is_mounted) this.setState({ has_fetched_states_list: true });
if (this.is_mounted)
this.setState({
has_fetched_states_list: true,
address_state_to_display: getLocation(this.props.states_list, this.props.value.address_state, 'text'),
});
this.form.current.getFormikActions().validateForm();
}

Expand Down Expand Up @@ -83,7 +87,9 @@ class AddressDetails extends Component {
onSubmit={(values, actions) => {
if (isDesktop() && values.address_state) {
values.address_state = this.props.states_list.length
? getLocation(this.props.states_list, values.address_state, 'value')
? this.state.address_state_to_display
? getLocation(this.props.states_list, this.state.address_state_to_display, 'value')
: getLocation(this.props.states_list, values.address_state, 'value')
: values.address_state;
}
this.props.onSubmit(this.props.index, values, actions.setSubmitting);
Expand Down Expand Up @@ -137,19 +143,27 @@ class AddressDetails extends Component {
<DesktopWrapper>
<Autocomplete
{...field}
{...(this.state
.address_state_to_display && {
value: this.state
.address_state_to_display,
})}
data-lpignore='true'
autoComplete='new-password' // prevent chrome autocomplete
dropdown_offset='3.2rem'
type='text'
label={localize('State/Province')}
list_items={this.props.states_list}
onItemSelection={({ value, text }) =>
onItemSelection={({ value, text }) => {
setFieldValue(
'address_state',
value ? text : '',
true
)
}
);
this.setState({
address_state_to_display: '',
});
}}
/>
</DesktopWrapper>
<MobileWrapper>
Expand Down

1 comment on commit 9cca7b8

@vercel
Copy link

@vercel vercel bot commented on 9cca7b8 May 12, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.