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

Get rid of missing translation #42970

Merged
merged 37 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7dae918
get rid of missing translation FormHelpMessage
nkdengineer Jun 2, 2024
7010adf
Fix translate error for DotIndicatorMessage
nkdengineer Jun 3, 2024
7d39bf5
fix test
nkdengineer Jun 3, 2024
6177f8b
fix error utils test
nkdengineer Jun 3, 2024
0451213
complete fix tes
nkdengineer Jun 3, 2024
7b70d73
fix translation error
nkdengineer Jun 3, 2024
55a9077
remove the use of MaybePhraseKey type
nkdengineer Jun 3, 2024
4320a8c
merge main
nkdengineer Jun 3, 2024
20e829f
fix test
nkdengineer Jun 3, 2024
a7fb548
fix lint
nkdengineer Jun 3, 2024
6d3a233
fix test
nkdengineer Jun 3, 2024
0c4cabc
fix prettier
nkdengineer Jun 3, 2024
f29281c
add missing form helper error translation
nkdengineer Jun 3, 2024
74f3f1d
merge main
nkdengineer Jun 4, 2024
5fb3199
merge main
nkdengineer Jun 4, 2024
ba60fea
clean code
nkdengineer Jun 4, 2024
97910d1
merge main
nkdengineer Jun 6, 2024
6f6b5aa
Update src/components/MoneyRequestConfirmationList.tsx
nkdengineer Jun 6, 2024
c8bb635
Update src/components/AddressForm.tsx
nkdengineer Jun 6, 2024
0416297
remove func translateIfPhraseKey and clean code
nkdengineer Jun 6, 2024
727b30a
fix lint
nkdengineer Jun 6, 2024
1383ae8
resolve conflict
nkdengineer Jun 7, 2024
927288f
fix typecheck
nkdengineer Jun 7, 2024
8190fa3
merge main
nkdengineer Jun 10, 2024
506ac9a
fix ts error
nkdengineer Jun 10, 2024
15e9eba
fix lint
nkdengineer Jun 10, 2024
6968d60
Merge branch 'main' into fix/42539
nkdengineer Jun 11, 2024
4edb5ed
merge main
nkdengineer Jun 12, 2024
d90a9df
fix: add missing translation
nkdengineer Jun 12, 2024
c4dd3da
merge main
nkdengineer Jun 13, 2024
174d975
fix type
nkdengineer Jun 13, 2024
bfb9464
merge main
nkdengineer Jun 13, 2024
b6b85d2
fix lint
nkdengineer Jun 13, 2024
61255a3
merge main
nkdengineer Jun 13, 2024
7603cb4
remove type MaybePhraseKey
nkdengineer Jun 14, 2024
899dc4e
merge main
nkdengineer Jun 17, 2024
1ef917b
Merge branch 'main' into fix/42539
francoisl Jun 17, 2024
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
1 change: 1 addition & 0 deletions src/components/AddPlaidBankAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function AddPlaidBankAccount({
}));
const {icon, iconSize, iconStyles} = getBankIcon({styles});
const plaidErrors = plaidData?.errors;
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
const plaidDataErrorMessage = !isEmptyObject(plaidErrors) ? (Object.values(plaidErrors)[0] as string) : '';
const bankName = plaidData?.bankName;

Expand Down
76 changes: 39 additions & 37 deletions src/components/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import type {MaybePhraseKey} from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -77,7 +76,7 @@ function AddressForm({

const zipSampleFormat = (country && (CONST.COUNTRY_ZIP_REGEX_DATA[country] as CountryZipRegex)?.samples) ?? '';

const zipFormat: MaybePhraseKey = ['common.zipCodeExampleFormat', {zipSampleFormat}];
const zipFormat = translate('common.zipCodeExampleFormat', {zipSampleFormat});

const isUSAForm = country === CONST.COUNTRY.US;

Expand All @@ -88,50 +87,53 @@ function AddressForm({
* @returns - An object containing the errors for each inputID
*/

const validator = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>): Errors => {
const errors: Errors & {
zipPostCode?: string | string[];
} = {};
const requiredFields = ['addressLine1', 'city', 'country', 'state'] as const;

// Check "State" dropdown is a valid state if selected Country is USA
if (values.country === CONST.COUNTRY.US && !values.state) {
errors.state = 'common.error.fieldRequired';
}

// Add "Field required" errors if any required field is empty
requiredFields.forEach((fieldKey) => {
const fieldValue = values[fieldKey] ?? '';
if (ValidationUtils.isRequiredFulfilled(fieldValue)) {
return;
const validator = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>): Errors => {
const errors: Errors & {
zipPostCode?: string | string[];
} = {};
const requiredFields = ['addressLine1', 'city', 'country', 'state'] as const;

// Check "State" dropdown is a valid state if selected Country is USA
if (values.country === CONST.COUNTRY.US && !values.state) {
errors.state = translate('common.error.fieldRequired');
}

errors[fieldKey] = 'common.error.fieldRequired';
});
// Add "Field required" errors if any required field is empty
requiredFields.forEach((fieldKey) => {
const fieldValue = values[fieldKey] ?? '';
if (ValidationUtils.isRequiredFulfilled(fieldValue)) {
return;
}

errors[fieldKey] = translate('common.error.fieldRequired');
});

// If no country is selected, default value is an empty string and there's no related regex data so we default to an empty object
const countryRegexDetails = (values.country ? CONST.COUNTRY_ZIP_REGEX_DATA?.[values.country] : {}) as CountryZipRegex;
// If no country is selected, default value is an empty string and there's no related regex data so we default to an empty object
const countryRegexDetails = (values.country ? CONST.COUNTRY_ZIP_REGEX_DATA?.[values.country] : {}) as CountryZipRegex;

// The postal code system might not exist for a country, so no regex either for them.
const countrySpecificZipRegex = countryRegexDetails?.regex;
const countryZipFormat = countryRegexDetails?.samples ?? '';
// The postal code system might not exist for a country, so no regex either for them.
const countrySpecificZipRegex = countryRegexDetails?.regex;
const countryZipFormat = countryRegexDetails?.samples ?? '';

ErrorUtils.addErrorMessage(errors, 'firstName', 'bankAccount.error.firstName');
ErrorUtils.addErrorMessage(errors, 'firstName', 'bankAccount.error.firstName');
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved

if (countrySpecificZipRegex) {
if (!countrySpecificZipRegex.test(values.zipPostCode?.trim().toUpperCase())) {
if (ValidationUtils.isRequiredFulfilled(values.zipPostCode?.trim())) {
errors.zipPostCode = ['privatePersonalDetails.error.incorrectZipFormat', countryZipFormat];
} else {
errors.zipPostCode = 'common.error.fieldRequired';
if (countrySpecificZipRegex) {
if (!countrySpecificZipRegex.test(values.zipPostCode?.trim().toUpperCase())) {
if (ValidationUtils.isRequiredFulfilled(values.zipPostCode?.trim())) {
errors.zipPostCode = ['privatePersonalDetails.error.incorrectZipFormat', countryZipFormat];
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
} else {
errors.zipPostCode = 'common.error.fieldRequired';
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else if (!CONST.GENERIC_ZIP_CODE_REGEX.test(values?.zipPostCode?.trim()?.toUpperCase() ?? '')) {
errors.zipPostCode = 'privatePersonalDetails.error.incorrectZipFormat';
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (!CONST.GENERIC_ZIP_CODE_REGEX.test(values?.zipPostCode?.trim()?.toUpperCase() ?? '')) {
errors.zipPostCode = 'privatePersonalDetails.error.incorrectZipFormat';
}

return errors;
}, []);
return errors;
},
[translate],
);

return (
<FormProvider
Expand Down
3 changes: 1 addition & 2 deletions src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {RefObject} from 'react';
import type {NativeSyntheticEvent, StyleProp, TextInputFocusEventData, View, ViewStyle} from 'react-native';
import type {Place} from 'react-native-google-places-autocomplete';
import type {MaybePhraseKey} from '@libs/Localize';
import type Locale from '@src/types/onyx/Locale';
import type {Address} from '@src/types/onyx/PrivatePersonalDetails';

Expand Down Expand Up @@ -35,7 +34,7 @@ type AddressSearchProps = {
onBlur?: () => void;

/** Error text to display */
errorText?: MaybePhraseKey;
errorText?: string;

/** Hint text to display */
hint?: string;
Expand Down
3 changes: 1 addition & 2 deletions src/components/AmountPicker/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {AmountFormProps} from '@components/AmountForm';
import type {MenuItemBaseProps} from '@components/MenuItem';
import type {MaybePhraseKey} from '@libs/Localize';
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this type is not used anywhere anymore, we might as well remove it?


type AmountSelectorModalProps = {
/** Whether the modal is visible */
Expand All @@ -24,7 +23,7 @@ type AmountPickerProps = {
title?: string | ((value?: string) => string);

/** Form Error description */
errorText?: MaybePhraseKey;
errorText?: string;

/** Callback to call when the input changes */
onInputChange?: (value: string | undefined) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/components/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import variables from '@styles/variables';
import Checkbox from './Checkbox';
import FormHelpMessage from './FormHelpMessage';
Expand Down Expand Up @@ -41,7 +40,7 @@ type CheckboxWithLabelProps = RequiredLabelProps & {
style?: StyleProp<ViewStyle>;

/** Error text to display */
errorText?: MaybePhraseKey;
errorText?: string;

/** Value for checkbox. This prop is intended to be set by FormProvider only */
value?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions src/components/CountrySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {ForwardedRef} from 'react';
import type {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import type {Country} from '@src/CONST';
Expand All @@ -13,7 +12,7 @@ import MenuItemWithTopDescription from './MenuItemWithTopDescription';

type CountrySelectorProps = {
/** Form error text. e.g when no country is selected */
errorText?: MaybePhraseKey;
errorText?: string;

/** Callback called when the country changes. */
onInputChange?: (value?: string) => void;
Expand Down
11 changes: 5 additions & 6 deletions src/components/DotIndicatorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {isReceiptError} from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import type {MaybePhraseKey} from '@libs/Localize';
import * as Localize from '@libs/Localize';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import Icon from './Icon';
Expand All @@ -23,7 +22,7 @@ type DotIndicatorMessageProps = {
* timestamp: 'message',
* }
*/
messages: Record<string, Localize.MaybePhraseKey | ReceiptError>;
messages: Record<string, string | ReceiptError | null>;

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
Expand All @@ -45,12 +44,12 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles}: DotIndica
}

// Fetch the keys, sort them, and map through each key to get the corresponding message
const sortedMessages: Array<MaybePhraseKey | ReceiptError> = Object.keys(messages)
const sortedMessages: Array<string | ReceiptError> = Object.keys(messages)
.sort()
.map((key) => messages[key]);

.map((key) => messages[key])
.filter((message): message is string | ReceiptError => message !== null);
// Removing duplicates using Set and transforming the result into an array
const uniqueMessages: Array<ReceiptError | string> = [...new Set(sortedMessages)].map((message) => (isReceiptError(message) ? message : Localize.translateIfPhraseKey(message)));
const uniqueMessages: Array<ReceiptError | string> = [...new Set(sortedMessages)].map((message) => message);

const isErrorMessage = type === 'error';

Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ function FormProvider(

const errorFields = formState?.errorFields?.[inputID] ?? {};
const fieldErrorMessage =
(Object.keys(errorFields)
Object.keys(errorFields)
.sort()
.map((key) => errorFields[key])
.at(-1) as string) ?? '';
.at(-1) ?? '';

const inputRef = inputProps.ref;

Expand Down
3 changes: 1 addition & 2 deletions src/components/Form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type StateSelector from '@components/StateSelector';
import type TextInput from '@components/TextInput';
import type TextPicker from '@components/TextPicker';
import type ValuePicker from '@components/ValuePicker';
import type {MaybePhraseKey} from '@libs/Localize';
import type BusinessTypePicker from '@pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/BusinessTypePicker';
import type {Country} from '@src/CONST';
import type {OnyxFormKey, OnyxValues} from '@src/ONYXKEYS';
Expand Down Expand Up @@ -139,7 +138,7 @@ type FormRef<TFormID extends OnyxFormKey = OnyxFormKey> = {

type InputRefs = Record<string, MutableRefObject<InputComponentBaseProps>>;

type FormInputErrors<TFormID extends OnyxFormKey = OnyxFormKey> = Partial<Record<FormOnyxKeys<TFormID>, MaybePhraseKey>>;
type FormInputErrors<TFormID extends OnyxFormKey = OnyxFormKey> = Partial<Record<FormOnyxKeys<TFormID>, string | undefined>>;

export type {
FormProps,
Expand Down
3 changes: 1 addition & 2 deletions src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import Button from './Button';
import FormAlertWrapper from './FormAlertWrapper';

type FormAlertWithSubmitButtonProps = {
/** Error message to display above button */
message?: MaybePhraseKey;
message?: string;

/** Whether the button is disabled */
isDisabled?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions src/components/FormAlertWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import type Network from '@src/types/onyx/Network';
import FormHelpMessage from './FormHelpMessage';
import {withNetwork} from './OnyxProvider';
Expand All @@ -29,7 +28,7 @@ type FormAlertWrapperProps = {
isMessageHtml?: boolean;

/** Error message to display above button */
message?: MaybePhraseKey;
message?: string;

/** Props to detect online status */
network: Network;
Expand Down
7 changes: 2 additions & 5 deletions src/components/FormHelpMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Localize from '@libs/Localize';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';

type FormHelpMessageProps = {
/** Error or hint text. Ignored when children is not empty */
message?: Localize.MaybePhraseKey;
message?: string;

/** Children to render next to dot indicator */
children?: React.ReactNode;
Expand All @@ -33,8 +32,6 @@ function FormHelpMessage({message = '', children, isError = true, style, shouldS
return null;
}

const translatedMessage = Localize.translateIfPhraseKey(message);

return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mt2, styles.mb1, style]}>
{isError && shouldShowRedDotIndicator && (
Expand All @@ -44,7 +41,7 @@ function FormHelpMessage({message = '', children, isError = true, style, shouldS
/>
)}
<View style={[styles.flex1, isError && shouldShowRedDotIndicator ? styles.ml2 : {}]}>
{children ?? <Text style={[isError ? styles.formError : styles.formHelp, styles.mb0]}>{translatedMessage}</Text>}
{children ?? <Text style={[isError ? styles.formError : styles.formHelp, styles.mb0]}>{message}</Text>}
</View>
</View>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/MagicCodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
import type {MaybePhraseKey} from '@libs/Localize';
import * as ValidationUtils from '@libs/ValidationUtils';
import CONST from '@src/CONST';
import FormHelpMessage from './FormHelpMessage';
Expand All @@ -33,7 +32,7 @@ type MagicCodeInputProps = {
shouldDelayFocus?: boolean;

/** Error text to display */
errorText?: MaybePhraseKey;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
errorText?: string;

/** Specifies autocomplete hints for the system, so it can provide autofill */
autoComplete: AutoCompleteVariant;
Expand Down
5 changes: 2 additions & 3 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ControlSelection from '@libs/ControlSelection';
import convertToLTR from '@libs/convertToLTR';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import getButtonState from '@libs/getButtonState';
import type {MaybePhraseKey} from '@libs/Localize';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as Session from '@userActions/Session';
Expand Down Expand Up @@ -151,13 +150,13 @@ type MenuItemBaseProps = {
shouldShowDescriptionOnTop?: boolean;

/** Error to display at the bottom of the component */
errorText?: MaybePhraseKey;
errorText?: string;

/** Any additional styles to pass to error text. */
errorTextStyle?: StyleProp<ViewStyle>;

/** Hint to display at the bottom of the component */
hintText?: MaybePhraseKey;
hintText?: string;

/** Should the error text red dot indicator be shown */
shouldShowRedDotIndicator?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions src/components/MessagesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import type * as Localize from '@libs/Localize';
import CONST from '@src/CONST';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand All @@ -16,7 +15,7 @@ import Tooltip from './Tooltip';

type MessagesRowProps = {
/** The messages to display */
messages: Record<string, Localize.MaybePhraseKey | ReceiptError>;
messages: Record<string, string | ReceiptError>;

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
Expand Down
Loading
Loading