-
Notifications
You must be signed in to change notification settings - Fork 3.3k
17548 Personal details push to page #21049
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
Merged
mountiny
merged 37 commits into
Expensify:main
from
gedu:edu/17548_personal_details_push_to_page_patch
Jul 26, 2023
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6c2c140
push to page menu item
gedu c9c320a
Fixed comments
gedu e746928
push to page menu item
gedu 062bc8a
Fixed comments
gedu b603569
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu 56924ba
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu 474125f
Made array containerStyle prop
gedu 74cc95a
handling navigation and state update
gedu f01b1e0
improved navigation animation
gedu f850f23
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu a2cd0b6
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu e48c601
Updated navigation and state changes
gedu 8148f4f
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu c2e715e
Fixed comments
gedu 7ef53f1
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu aee62fa
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu b13ac10
Removed Navigation fro State and Country pages
gedu 8898224
fixed lint errors
gedu fe46e3c
fixed missing dependency
gedu 64b8dbb
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu 761c75a
Fixed comments
gedu d641006
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu e06bc96
Fixed comments
gedu b94e99f
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu 4ee01d6
Removed fallback
gedu 2cead61
Fixed comments
gedu 675a7c3
Fixed comments
gedu 0779f34
fixed comments
gedu d063f55
fix: add missing space
koko57 128597b
fix: update searchValue when current value changes
koko57 94bd35a
fix: include allCountries in the deps array
koko57 f750d18
fix: apply requested changes
koko57 0e416e0
fix: minor change
koko57 5c0ef29
fix: fix prop name problem
koko57 60c9fbb
fix: resolve conflicts
koko57 b34b031
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
koko57 4852ccb
fix: change useOnNetworkReconnect to useNetwork
koko57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import _ from 'underscore'; | ||
import React, {useMemo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import CONST from '../../CONST'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
import HeaderWithBackButton from '../HeaderWithBackButton'; | ||
import SelectionListRadio from '../SelectionListRadio'; | ||
import Modal from '../Modal'; | ||
|
||
const propTypes = { | ||
/** Whether the modal is visible */ | ||
isVisible: PropTypes.bool.isRequired, | ||
|
||
/** Country value selected */ | ||
currentCountry: PropTypes.string, | ||
|
||
/** Function to call when the user selects a Country */ | ||
onCountrySelected: PropTypes.func, | ||
|
||
/** Function to call when the user closes the Country modal */ | ||
onClose: PropTypes.func, | ||
|
||
/** The search value from the selection list */ | ||
searchValue: PropTypes.string.isRequired, | ||
|
||
/** Function to call when the user types in the search input */ | ||
setSearchValue: PropTypes.func.isRequired, | ||
}; | ||
|
||
const defaultProps = { | ||
currentCountry: '', | ||
onClose: () => {}, | ||
onCountrySelected: () => {}, | ||
}; | ||
|
||
function filterOptions(searchValue, data) { | ||
const trimmedSearchValue = searchValue.trim(); | ||
if (trimmedSearchValue.length === 0) { | ||
return []; | ||
} | ||
|
||
return _.filter(data, (country) => country.text.toLowerCase().includes(searchValue.toLowerCase())); | ||
} | ||
|
||
function CountrySelectorModal({currentCountry, isVisible, onClose, onCountrySelected, setSearchValue, searchValue}) { | ||
const {translate} = useLocalize(); | ||
|
||
const countries = useMemo( | ||
() => | ||
_.map(translate('allCountries'), (countryName, countryISO) => ({ | ||
value: countryISO, | ||
keyForList: countryISO, | ||
text: countryName, | ||
isSelected: currentCountry === countryISO, | ||
})), | ||
[translate, currentCountry], | ||
); | ||
|
||
const filteredData = filterOptions(searchValue, countries); | ||
const headerMessage = searchValue.trim() && !filteredData.length ? translate('common.noResultsFound') : ''; | ||
|
||
return ( | ||
<Modal | ||
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
isVisible={isVisible} | ||
onClose={onClose} | ||
onModalHide={onClose} | ||
hideModalContentWhileAnimating | ||
useNativeDriver | ||
> | ||
<HeaderWithBackButton | ||
title={translate('common.country')} | ||
onBackButtonPress={onClose} | ||
/> | ||
<SelectionListRadio | ||
headerMessage={headerMessage} | ||
textInputLabel={translate('common.country')} | ||
textInputPlaceholder={translate('countrySelectorModal.placeholderText')} | ||
textInputValue={searchValue} | ||
sections={[{data: filteredData, indexOffset: 0}]} | ||
onSelectRow={onCountrySelected} | ||
onChangeText={setSearchValue} | ||
shouldFocusOnSelectRow | ||
shouldHaveOptionSeparator | ||
shouldDelayFocus | ||
initiallyFocusedOptionKey={currentCountry} | ||
/> | ||
</Modal> | ||
); | ||
} | ||
|
||
CountrySelectorModal.propTypes = propTypes; | ||
CountrySelectorModal.defaultProps = defaultProps; | ||
CountrySelectorModal.displayName = 'CountrySelectorModal'; | ||
|
||
export default CountrySelectorModal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import lodashGet from 'lodash/get'; | ||
import styles from '../../styles/styles'; | ||
import MenuItemWithTopDescription from '../MenuItemWithTopDescription'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
import CountrySelectorModal from './CountrySelectorModal'; | ||
import FormHelpMessage from '../FormHelpMessage'; | ||
|
||
const propTypes = { | ||
/** Form Error description */ | ||
errorText: PropTypes.string, | ||
|
||
/** Country to display */ | ||
value: PropTypes.string, | ||
|
||
/** Callback to call when the input changes */ | ||
onInputChange: PropTypes.func, | ||
|
||
/** A ref to forward to MenuItemWithTopDescription */ | ||
forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({current: PropTypes.instanceOf(React.Component)})]), | ||
}; | ||
|
||
const defaultProps = { | ||
value: undefined, | ||
forwardedRef: undefined, | ||
errorText: '', | ||
onInputChange: () => {}, | ||
}; | ||
|
||
function CountryPicker({value, errorText, onInputChange, forwardedRef}) { | ||
const {translate} = useLocalize(); | ||
const allCountries = translate('allCountries'); | ||
const [isPickerVisible, setIsPickerVisible] = useState(false); | ||
const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, '')); | ||
|
||
useEffect(() => { | ||
setSearchValue(lodashGet(allCountries, value, '')); | ||
}, [value, allCountries]); | ||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const showPickerModal = () => { | ||
setIsPickerVisible(true); | ||
}; | ||
|
||
const hidePickerModal = () => { | ||
setIsPickerVisible(false); | ||
}; | ||
|
||
const updateCountryInput = (country) => { | ||
onInputChange(country.value); | ||
hidePickerModal(); | ||
}; | ||
|
||
const title = allCountries[value] || ''; | ||
const descStyle = title.length === 0 ? styles.textNormal : null; | ||
|
||
return ( | ||
<View> | ||
<MenuItemWithTopDescription | ||
ref={forwardedRef} | ||
shouldShowRightIcon | ||
title={title} | ||
descriptionTextStyle={descStyle} | ||
description={translate('common.country')} | ||
onPress={showPickerModal} | ||
/> | ||
<View style={styles.ml5}> | ||
<FormHelpMessage message={errorText} /> | ||
</View> | ||
<CountrySelectorModal | ||
isVisible={isPickerVisible} | ||
currentCountry={value} | ||
searchValue={searchValue} | ||
setSearchValue={setSearchValue} | ||
onClose={hidePickerModal} | ||
onCountrySelected={updateCountryInput} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
CountryPicker.propTypes = propTypes; | ||
CountryPicker.defaultProps = defaultProps; | ||
CountryPicker.displayName = 'CountryPicker'; | ||
|
||
export default React.forwardRef((props, ref) => ( | ||
<CountryPicker | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.