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

Fix/27263: Inconsistent validation error for required field in home address #35326

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Changes from 5 commits
Commits
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
19 changes: 17 additions & 2 deletions src/components/CountrySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {forwardRef, useEffect} from 'react';
import {useIsFocused} from '@react-navigation/native';
import React, {forwardRef, useEffect, useRef} from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -23,15 +24,27 @@ type CountrySelectorProps = {
/** inputID used by the Form component */
// eslint-disable-next-line react/no-unused-prop-types
inputID: string;
onBlur: () => void;
onPress: () => void;
};
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved

function CountrySelector({errorText = '', value: countryCode, onInputChange}: CountrySelectorProps, ref: ForwardedRef<View>) {
function CountrySelector({errorText = '', value: countryCode, onInputChange, onBlur = () => {}, onPress = () => {}}: CountrySelectorProps, ref: ForwardedRef<View>) {
const styles = useThemeStyles();
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
const {translate} = useLocalize();

const title = countryCode ? translate(`allCountries.${countryCode}`) : '';
const countryTitleDescStyle = title.length === 0 ? styles.textNormal : null;

const didOpenContrySelector = useRef(false);
const isFocus = useIsFocused();
useEffect(() => {
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
if (!isFocus || !didOpenContrySelector.current) {
return;
}
didOpenContrySelector.current = false;
onBlur();
}, [isFocus, onBlur]);
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
// This will cause the form to revalidate and remove any error related to country name
onInputChange(countryCode);
Expand All @@ -48,6 +61,8 @@ function CountrySelector({errorText = '', value: countryCode, onInputChange}: Co
description={translate('common.country')}
onPress={() => {
const activeRoute = Navigation.getActiveRouteWithoutParams();
onPress();
didOpenContrySelector.current = true;
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
Navigation.navigate(ROUTES.SETTINGS_ADDRESS_COUNTRY.getRoute(countryCode ?? '', activeRoute));
}}
/>
Expand Down
Loading