Skip to content
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

17548 Personal details push to page #21049

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6c2c140
push to page menu item
gedu Jun 9, 2023
c9c320a
Fixed comments
gedu Jun 19, 2023
e746928
push to page menu item
gedu Jun 9, 2023
062bc8a
Fixed comments
gedu Jun 19, 2023
b603569
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jun 22, 2023
56924ba
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jun 23, 2023
474125f
Made array containerStyle prop
gedu Jun 26, 2023
74cc95a
handling navigation and state update
gedu Jun 28, 2023
f01b1e0
improved navigation animation
gedu Jun 28, 2023
f850f23
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 4, 2023
a2cd0b6
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 7, 2023
e48c601
Updated navigation and state changes
gedu Jul 7, 2023
8148f4f
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 10, 2023
c2e715e
Fixed comments
gedu Jul 11, 2023
7ef53f1
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 11, 2023
aee62fa
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 14, 2023
b13ac10
Removed Navigation fro State and Country pages
gedu Jul 14, 2023
8898224
fixed lint errors
gedu Jul 14, 2023
fe46e3c
fixed missing dependency
gedu Jul 14, 2023
64b8dbb
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 17, 2023
761c75a
Fixed comments
gedu Jul 17, 2023
d641006
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 18, 2023
e06bc96
Fixed comments
gedu Jul 19, 2023
b94e99f
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
gedu Jul 19, 2023
4ee01d6
Removed fallback
gedu Jul 19, 2023
2cead61
Fixed comments
gedu Jul 20, 2023
675a7c3
Fixed comments
gedu Jul 24, 2023
0779f34
fixed comments
gedu Jul 24, 2023
d063f55
fix: add missing space
koko57 Jul 25, 2023
128597b
fix: update searchValue when current value changes
koko57 Jul 25, 2023
94bd35a
fix: include allCountries in the deps array
koko57 Jul 25, 2023
f750d18
fix: apply requested changes
koko57 Jul 25, 2023
0e416e0
fix: minor change
koko57 Jul 25, 2023
5c0ef29
fix: fix prop name problem
koko57 Jul 26, 2023
60c9fbb
fix: resolve conflicts
koko57 Jul 26, 2023
b34b031
Merge branch 'main' into edu/17548_personal_details_push_to_page_patch
koko57 Jul 26, 2023
4852ccb
fix: change useOnNetworkReconnect to useNetwork
koko57 Jul 26, 2023
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
67 changes: 0 additions & 67 deletions src/components/CountryPicker.js
mountiny marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

96 changes: 96 additions & 0 deletions src/components/CountryPicker/CountrySelectorModal.js
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') : '';
mountiny marked this conversation as resolved.
Show resolved Hide resolved

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;
94 changes: 94 additions & 0 deletions src/components/CountryPicker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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);
setSearchValue(lodashGet(allCountries, country.value, ''));
mountiny marked this conversation as resolved.
Show resolved Hide resolved
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}
/>
));
2 changes: 1 addition & 1 deletion src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function Form(props) {
}

if (child.props.onValueChange) {
child.props.onValueChange(value);
child.props.onValueChange(value, inputKey);
}
},
});
Expand Down
9 changes: 8 additions & 1 deletion src/components/MenuItemWithTopDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function MenuItemWithTopDescription(props) {
<MenuItem
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={props.forwardRef}
shouldShowBasicTitle
shouldShowDescriptionOnTop
/>
Expand All @@ -20,4 +21,10 @@ function MenuItemWithTopDescription(props) {
MenuItemWithTopDescription.propTypes = propTypes;
MenuItemWithTopDescription.displayName = 'MenuItemWithTopDescription';

export default MenuItemWithTopDescription;
export default React.forwardRef((props, ref) => (
<MenuItemWithTopDescription
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardRef={ref}
mountiny marked this conversation as resolved.
Show resolved Hide resolved
/>
));
67 changes: 0 additions & 67 deletions src/components/StatePicker.js
mountiny marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

Loading
Loading