Skip to content

Commit 909b8e5

Browse files
committed
fix: Error message is not translated to Spanish after trying to move report to a deleted WS
1 parent 99e31a5 commit 909b8e5

7 files changed

Lines changed: 39 additions & 11 deletions

File tree

src/components/DotIndicatorMessage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import useLocalize from '@hooks/useLocalize';
77
import useStyleUtils from '@hooks/useStyleUtils';
88
import useTheme from '@hooks/useTheme';
99
import useThemeStyles from '@hooks/useThemeStyles';
10-
import {isReceiptError} from '@libs/ErrorUtils';
10+
import {isReceiptError, isTranslationPathError} from '@libs/ErrorUtils';
1111
import fileDownload from '@libs/fileDownload';
1212
import handleRetryPress from '@libs/ReceiptUploadRetryHandler';
13+
import type {TranslationPathError} from '@src/languages/types';
1314
import type {ReceiptError} from '@src/types/onyx/Transaction';
1415
import ConfirmModal from './ConfirmModal';
1516
import Icon from './Icon';
@@ -25,7 +26,7 @@ type DotIndicatorMessageProps = {
2526
* timestamp: 'message',
2627
* }
2728
*/
28-
messages: Record<string, string | ReceiptError | ReactElement | null>;
29+
messages: Record<string, string | ReceiptError | TranslationPathError | ReactElement | null>;
2930

3031
/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
3132
type: 'error' | 'success';
@@ -109,7 +110,7 @@ function DotIndicatorMessage({messages = {}, style, type, textStyles, dismissErr
109110
key={index}
110111
style={[StyleUtils.getDotIndicatorTextStyles(isErrorMessage), textStyles]}
111112
>
112-
{message}
113+
{isTranslationPathError(message) ? translate(message.translationPath) : message}
113114
</Text>
114115
);
115116
};

src/components/ErrorMessageRow.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import mapValues from 'lodash/mapValues';
22
import React from 'react';
33
import type {StyleProp, ViewStyle} from 'react-native';
4+
import type {TranslationPathError, TranslationPathErrors} from '@src/languages/types';
45
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
56
import type {ReceiptError, ReceiptErrors} from '@src/types/onyx/Transaction';
67
import {isEmptyObject} from '@src/types/utils/EmptyObject';
78
import MessagesRow from './MessagesRow';
89

910
type ErrorMessageRowProps = {
1011
/** The errors to display */
11-
errors?: OnyxCommon.Errors | ReceiptErrors | null;
12+
errors?: OnyxCommon.Errors | ReceiptErrors | TranslationPathErrors | null;
1213

1314
/** Additional style object for the error row */
1415
errorRowStyles?: StyleProp<ViewStyle>;
@@ -26,7 +27,7 @@ type ErrorMessageRowProps = {
2627
function ErrorMessageRow({errors, errorRowStyles, onClose, canDismissError = true, dismissError}: ErrorMessageRowProps) {
2728
// Some errors have a null message. This is used to apply opacity only and to avoid showing redundant messages.
2829
const errorEntries = Object.entries(errors ?? {});
29-
const filteredErrorEntries = errorEntries.filter((errorEntry): errorEntry is [string, string | ReceiptError] => errorEntry[1] !== null);
30+
const filteredErrorEntries = errorEntries.filter((errorEntry): errorEntry is [string, string | ReceiptError | TranslationPathError] => errorEntry[1] !== null);
3031
const errorMessages = mapValues(Object.fromEntries(filteredErrorEntries), (error) => error);
3132
const hasErrorMessages = !isEmptyObject(errorMessages);
3233

src/components/MessagesRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
77
import CONST from '@src/CONST';
88
import type {ReceiptError} from '@src/types/onyx/Transaction';
99
import {isEmptyObject} from '@src/types/utils/EmptyObject';
10+
import type { TranslationPathError } from '@src/languages/types';
1011
import DotIndicatorMessage from './DotIndicatorMessage';
1112
import Icon from './Icon';
1213
import * as Expensicons from './Icon/Expensicons';
@@ -15,7 +16,7 @@ import Tooltip from './Tooltip';
1516

1617
type MessagesRowProps = {
1718
/** The messages to display */
18-
messages: Record<string, string | ReceiptError>;
19+
messages: Record<string, string | ReceiptError | TranslationPathError>;
1920

2021
/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
2122
type: 'error' | 'success';

src/components/OfflineWithFeedback.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
1212
import type {ReceiptErrors} from '@src/types/onyx/Transaction';
1313
import type ChildrenProps from '@src/types/utils/ChildrenProps';
1414
import {isEmptyObject} from '@src/types/utils/EmptyObject';
15+
import type { TranslationPathErrors } from '@src/languages/types';
1516
import CustomStylesForChildrenProvider from './CustomStylesForChildrenProvider';
1617
import ErrorMessageRow from './ErrorMessageRow';
1718

@@ -29,7 +30,7 @@ type OfflineWithFeedbackProps = ChildrenProps & {
2930
shouldHideOnDelete?: boolean;
3031

3132
/** The errors to display */
32-
errors?: OnyxCommon.Errors | ReceiptErrors | null;
33+
errors?: OnyxCommon.Errors | ReceiptErrors | TranslationPathErrors | null;
3334

3435
/** Whether we should show the error messages */
3536
shouldShowErrorMessages?: boolean;

src/languages/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ type DefaultTranslation = typeof en;
7676
*/
7777
type TranslationPaths = FlattenObject<DefaultTranslation>;
7878

79+
type TranslationPathError = {
80+
translationPath: TranslationPaths
81+
}
82+
83+
type TranslationPathErrors = Record<string, TranslationPathError>;
7984
/**
8085
* Flattened default translation object with its values
8186
*/
@@ -94,4 +99,4 @@ type TranslationParameters<TKey extends TranslationPaths> = FlatTranslationsObje
9499
: Args
95100
: never[];
96101

97-
export type {TranslationDeepObject, TranslationPaths, PluralForm, FlatTranslationsObject, TranslationParameters};
102+
export type {TranslationDeepObject, TranslationPaths, PluralForm, FlatTranslationsObject, TranslationParameters, TranslationPathError, TranslationPathErrors};

src/libs/ErrorUtils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mapValues from 'lodash/mapValues';
22
import type {OnyxEntry} from 'react-native-onyx';
33
import CONST from '@src/CONST';
4-
import type {TranslationPaths} from '@src/languages/types';
4+
import type {TranslationPathError, TranslationPathErrors, TranslationPaths} from '@src/languages/types';
55
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
66
import type Response from '@src/types/onyx/Response';
77
import type {ReceiptError} from '@src/types/onyx/Transaction';
@@ -45,6 +45,10 @@ function getMicroSecondOnyxErrorWithTranslationKey(error: TranslationPaths, erro
4545
return {[errorKey ?? DateUtils.getMicroseconds()]: Localize.translateLocal(error)};
4646
}
4747

48+
function getMicroSecondTranslationErrorWithTranslationKey(error: TranslationPaths, errorKey?: number): TranslationPathErrors {
49+
return {[errorKey ?? DateUtils.getMicroseconds()]: {translationPath: error}};
50+
}
51+
4852
/**
4953
* Creates an error object with a timestamp (in microseconds) as the key and the error message as the value.
5054
* @param error - The error message.
@@ -197,6 +201,19 @@ function isReceiptError(message: unknown): message is ReceiptError {
197201
return ((message as Record<string, unknown>)?.error ?? '') === CONST.IOU.RECEIPT_ERROR;
198202
}
199203

204+
function isTranslationPathError(message: unknown): message is TranslationPathError {
205+
if (typeof message === 'string') {
206+
return false;
207+
}
208+
if (Array.isArray(message)) {
209+
return false;
210+
}
211+
if (Object.keys(message as Record<string, unknown>).length === 0) {
212+
return false;
213+
}
214+
return (message as Record<string, unknown>)?.translationPath !== undefined;
215+
}
216+
200217
export {
201218
addErrorMessage,
202219
getAuthenticateErrorMessage,
@@ -212,6 +229,8 @@ export {
212229
getMicroSecondOnyxErrorWithMessage,
213230
getMicroSecondOnyxErrorObject,
214231
isReceiptError,
232+
isTranslationPathError,
233+
getMicroSecondTranslationErrorWithTranslationKey,
215234
};
216235

217236
export type {OnyxDataWithErrors};

src/libs/actions/Report.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import * as Environment from '@libs/Environment/Environment';
6767
import {getOldDotURLFromEnvironment} from '@libs/Environment/Environment';
6868
import getEnvironment from '@libs/Environment/getEnvironment';
6969
import type EnvironmentType from '@libs/Environment/getEnvironment/types';
70-
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
70+
import {getMicroSecondOnyxErrorWithTranslationKey, getMicroSecondTranslationErrorWithTranslationKey} from '@libs/ErrorUtils';
7171
import fileDownload from '@libs/fileDownload';
7272
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
7373
import HttpUtils from '@libs/HttpUtils';
@@ -5642,7 +5642,7 @@ function buildOptimisticChangePolicyData(report: Report, policyID: string, repor
56425642
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
56435643
value: {
56445644
[optimisticMovedReportAction.reportActionID]: {
5645-
errors: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
5645+
errors: getMicroSecondTranslationErrorWithTranslationKey('common.genericErrorMessage'),
56465646
},
56475647
},
56485648
});

0 commit comments

Comments
 (0)