-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement dedicated route for CountryPicker in AddressPage #26742
Changes from 31 commits
0479a7e
b5a0ebc
3cbd8d2
53286fd
d88cc41
b8cacd7
f4ae5b2
ae6ebcf
9cfcc96
ff87483
f161188
ce5463c
ba351d1
55253e7
4252fba
178d100
3ec7cd8
c7dfa90
fc551b8
137790c
a49e1aa
19a1e7e
2cca5c0
9104539
e81fe77
cdfe3b8
a96a739
136f90c
a017ee9
9d19973
3af7931
945056d
d2331d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, {useEffect} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {View} from 'react-native'; | ||
import styles from '../styles/styles'; | ||
import Navigation from '../libs/Navigation/Navigation'; | ||
import ROUTES from '../ROUTES'; | ||
import useLocalize from '../hooks/useLocalize'; | ||
import MenuItemWithTopDescription from './MenuItemWithTopDescription'; | ||
import FormHelpMessage from './FormHelpMessage'; | ||
|
||
const propTypes = { | ||
/** Form error text. e.g when no country is selected */ | ||
errorText: PropTypes.string, | ||
|
||
/** Callback called when the country changes. */ | ||
onInputChange: PropTypes.func.isRequired, | ||
|
||
/** Current selected country */ | ||
value: PropTypes.string, | ||
|
||
/** inputID used by the Form component */ | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
inputID: PropTypes.string.isRequired, | ||
|
||
/** React ref being forwarded to the MenuItemWithTopDescription */ | ||
forwardedRef: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
errorText: '', | ||
value: '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting an empty string as default prevents the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated! |
||
forwardedRef: () => {}, | ||
}; | ||
|
||
function CountrySelector({errorText, value: countryCode, onInputChange, forwardedRef}) { | ||
const {translate} = useLocalize(); | ||
|
||
const title = countryCode ? translate(`allCountries.${countryCode}`) : ''; | ||
const countryTitleDescStyle = title.length === 0 ? styles.textNormal : null; | ||
|
||
useEffect(() => { | ||
// This will cause the form to revalidate and remove any error related to country name | ||
onInputChange(countryCode); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [countryCode]); | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<View> | ||
<MenuItemWithTopDescription | ||
shouldShowRightIcon | ||
title={title} | ||
ref={forwardedRef} | ||
descriptionTextStyle={countryTitleDescStyle} | ||
description={translate('common.country')} | ||
onPress={() => { | ||
const activeRoute = Navigation.getActiveRoute().replace(/\?.*/, ''); | ||
Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS_ADDRESS_COUNTRY.getRoute(countryCode, activeRoute)); | ||
}} | ||
/> | ||
<View style={styles.ml5}> | ||
<FormHelpMessage message={errorText} /> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
CountrySelector.propTypes = propTypes; | ||
CountrySelector.defaultProps = defaultProps; | ||
CountrySelector.displayName = 'CountrySelector'; | ||
|
||
export default React.forwardRef((props, ref) => ( | ||
<CountrySelector | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very weird formatting but not a blocker.