Skip to content

Commit

Permalink
get rid of missing translation FormHelpMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Jun 2, 2024
1 parent 2eb16f4 commit 7dae918
Show file tree
Hide file tree
Showing 53 changed files with 181 additions and 222 deletions.
6 changes: 3 additions & 3 deletions src/components/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function AddressForm({

// 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';
errors.state = translate('common.error.fieldRequired');
}

// Add "Field required" errors if any required field is empty
Expand All @@ -106,7 +106,7 @@ function AddressForm({
return;
}

errors[fieldKey] = 'common.error.fieldRequired';
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
Expand All @@ -131,7 +131,7 @@ function AddressForm({
}

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

return (
<FormProvider
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';

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
2 changes: 1 addition & 1 deletion src/components/DotIndicatorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DotIndicatorMessageProps = {
* timestamp: 'message',
* }
*/
messages: Record<string, Localize.MaybePhraseKey | ReceiptError>;
messages: Record<string, string>;

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
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;
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
4 changes: 1 addition & 3 deletions src/components/MessagesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ 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';
import DotIndicatorMessage from './DotIndicatorMessage';
import Icon from './Icon';
Expand All @@ -16,7 +14,7 @@ import Tooltip from './Tooltip';

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

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
Expand Down
31 changes: 7 additions & 24 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ function MoneyRequestConfirmationList({

useEffect(() => {
if (shouldDisplayFieldError && hasSmartScanFailed) {
setFormError('iou.receiptScanningFailed');
setFormError(translate('iou.receiptScanningFailed'));
return;
}
if (shouldDisplayFieldError && didConfirmSplit) {
setFormError('iou.error.genericSmartscanFailureMessage');
setFormError(translate('iou.error.genericSmartscanFailureMessage'));
return;
}
// reset the form error whenever the screen gains or loses focus
Expand Down Expand Up @@ -431,7 +431,7 @@ function MoneyRequestConfirmationList({
const shares: number[] = Object.values(splitSharesMap).map((splitShare) => splitShare?.amount ?? 0);
const sumOfShares = shares?.reduce((prev, current): number => prev + current, 0);
if (sumOfShares !== iouAmount) {
setFormError('iou.error.invalidSplit');
setFormError(translate('iou.error.invalidSplit'));
return;
}

Expand All @@ -441,7 +441,7 @@ function MoneyRequestConfirmationList({

// A split must have at least two participants with amounts bigger than 0
if (participantsWithAmount.length === 1) {
setFormError('iou.error.invalidSplitParticipants');
setFormError(translate('iou.error.invalidSplitParticipants'));
return;
}

Expand Down Expand Up @@ -698,11 +698,11 @@ function MoneyRequestConfirmationList({
return;
}
if (!isEditingSplitBill && isMerchantRequired && (isMerchantEmpty || (shouldDisplayFieldError && TransactionUtils.isMerchantMissing(transaction ?? null)))) {
setFormError('iou.error.invalidMerchant');
setFormError(translate('iou.error.invalidMerchant'));
return;
}
if (iouCategory.length > CONST.API_TRANSACTION_CATEGORY_MAX_LENGTH) {
setFormError('iou.error.invalidCategoryLength');
setFormError(translate('iou.error.invalidCategoryLength'));
return;
}

Expand Down Expand Up @@ -738,24 +738,7 @@ function MoneyRequestConfirmationList({
onConfirm?.(selectedParticipants);
}
},
[
selectedParticipants,
isMerchantRequired,
isMerchantEmpty,
shouldDisplayFieldError,
transaction,
iouType,
onSendMoney,
iouCurrencyCode,
isDistanceRequest,
iouCategory,
isDistanceRequestWithPendingRoute,
iouAmount,
isEditingSplitBill,
formError,
setFormError,
onConfirm,
],
[selectedParticipants, isEditingSplitBill, isMerchantRequired, isMerchantEmpty, shouldDisplayFieldError, transaction, iouCategory.length, formError, iouType, setFormError, translate, onSendMoney, iouCurrencyCode, isDistanceRequest, isDistanceRequestWithPendingRoute, iouAmount, onConfirm],
);

const footerContent = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PDFView/PDFPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function PDFPasswordForm({isFocused, isPasswordInvalid = false, shouldShowLoadin

const errorText = useMemo(() => {
if (isPasswordInvalid) {
return 'attachmentView.passwordIncorrect';
return translate('attachmentView.passwordIncorrect');
}
if (validationErrorText) {
return validationErrorText;
Expand Down
3 changes: 1 addition & 2 deletions src/components/Picker/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {ChangeEvent, Component, ReactElement} from 'react';
import type {MeasureLayoutOnSuccessCallback, NativeMethods, StyleProp, ViewStyle} from 'react-native';
import type {MaybePhraseKey} from '@libs/Localize';

type MeasureLayoutOnFailCallback = () => void;

Expand Down Expand Up @@ -59,7 +58,7 @@ type BasePickerProps<TPickerValue> = {
placeholder?: PickerPlaceholder;

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

/** Customize the BasePicker container */
containerStyles?: StyleProp<ViewStyle>;
Expand Down
3 changes: 1 addition & 2 deletions src/components/RadioButtonWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 FormHelpMessage from './FormHelpMessage';
import * as Pressables from './Pressable';
import RadioButton from './RadioButton';
Expand All @@ -29,7 +28,7 @@ type RadioButtonWithLabelProps = {
hasError?: boolean;

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

const PressableWithFeedback = Pressables.PressableWithFeedback;
Expand Down
3 changes: 1 addition & 2 deletions src/components/RadioButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import FormHelpMessage from './FormHelpMessage';
import RadioButtonWithLabel from './RadioButtonWithLabel';

Expand All @@ -24,7 +23,7 @@ type RadioButtonsProps = {
onPress: (value: string) => void;

/** Potential error text provided by a form InputWrapper */
errorText?: MaybePhraseKey;
errorText?: string;

/** Style for radio button */
radioButtonStyle?: StyleProp<ViewStyle>;
Expand Down
3 changes: 1 addition & 2 deletions src/components/SingleChoiceQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import React, {forwardRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {Text as RNText} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import type {Choice} from './RadioButtons';
import RadioButtons from './RadioButtons';
import Text from './Text';

type SingleChoiceQuestionProps = {
prompt: string;
errorText?: MaybePhraseKey;
errorText?: string;
possibleAnswers: Choice[];
currentQuestionIndex: number;
onInputChange: (value: string) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/components/StateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {View} from 'react-native';
import useGeographicalStateFromRoute from '@hooks/useGeographicalStateFromRoute';
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 ROUTES from '@src/ROUTES';
Expand All @@ -17,7 +16,7 @@ type State = keyof typeof COMMON_CONST.STATES;

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

/** Current selected state */
value?: State | '';
Expand Down
Loading

0 comments on commit 7dae918

Please sign in to comment.