Skip to content

Commit 5650d31

Browse files
committed
chore: Move TranslationKeyError to OnyxCommon
1 parent 2130ed8 commit 5650d31

7 files changed

Lines changed: 25 additions & 16 deletions

File tree

src/components/DotIndicatorMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
1010
import {isReceiptError, isTranslationKeyError} from '@libs/ErrorUtils';
1111
import fileDownload from '@libs/fileDownload';
1212
import handleRetryPress from '@libs/ReceiptUploadRetryHandler';
13-
import type {TranslationKeyError} from '@src/languages/types';
1413
import type {ReceiptError} from '@src/types/onyx/Transaction';
14+
import type {TranslationKeyError} from '@src/types/onyx/OnyxCommon';
1515
import ConfirmModal from './ConfirmModal';
1616
import Icon from './Icon';
1717
import * as Expensicons from './Icon/Expensicons';

src/components/ErrorMessageRow.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import mapValues from 'lodash/mapValues';
22
import React from 'react';
33
import type {StyleProp, ViewStyle} from 'react-native';
4-
import type {TranslationKeyError, TranslationKeyErrors} from '@src/languages/types';
54
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
65
import type {ReceiptError, ReceiptErrors} from '@src/types/onyx/Transaction';
76
import {isEmptyObject} from '@src/types/utils/EmptyObject';
87
import MessagesRow from './MessagesRow';
98

109
type ErrorMessageRowProps = {
1110
/** The errors to display */
12-
errors?: OnyxCommon.Errors | ReceiptErrors | TranslationKeyErrors | null;
11+
errors?: OnyxCommon.Errors | ReceiptErrors | OnyxCommon.TranslationKeyErrors | null;
1312

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

src/components/MessagesRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import useLocalize from '@hooks/useLocalize';
55
import useTheme from '@hooks/useTheme';
66
import useThemeStyles from '@hooks/useThemeStyles';
77
import CONST from '@src/CONST';
8-
import type {TranslationKeyError} from '@src/languages/types';
98
import type {ReceiptError} from '@src/types/onyx/Transaction';
109
import {isEmptyObject} from '@src/types/utils/EmptyObject';
10+
import type { TranslationKeyError } from '@src/types/onyx/OnyxCommon';
1111
import DotIndicatorMessage from './DotIndicatorMessage';
1212
import Icon from './Icon';
1313
import * as Expensicons from './Icon/Expensicons';

src/components/OfflineWithFeedback.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import mapChildrenFlat from '@libs/mapChildrenFlat';
88
import shouldRenderOffscreen from '@libs/shouldRenderOffscreen';
99
import type {AllStyles} from '@styles/utils/types';
1010
import CONST from '@src/CONST';
11-
import type {TranslationKeyErrors} from '@src/languages/types';
1211
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
1312
import type {ReceiptErrors} from '@src/types/onyx/Transaction';
1413
import type ChildrenProps from '@src/types/utils/ChildrenProps';
@@ -31,7 +30,7 @@ type OfflineWithFeedbackProps = ChildrenProps & {
3130
shouldHideOnDelete?: boolean;
3231

3332
/** The errors to display */
34-
errors?: OnyxCommon.Errors | ReceiptErrors | TranslationKeyErrors | null;
33+
errors?: OnyxCommon.Errors | OnyxCommon.TranslationKeyErrors | ReceiptErrors | null;
3534

3635
/** Whether we should show the error messages */
3736
shouldShowErrorMessages?: boolean;

src/languages/types.ts

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

79-
type TranslationKeyError = {
80-
translationKey: TranslationPaths;
81-
};
82-
83-
type TranslationKeyErrors = Record<string, TranslationKeyError>;
8479
/**
8580
* Flattened default translation object with its values
8681
*/
@@ -99,4 +94,4 @@ type TranslationParameters<TKey extends TranslationPaths> = FlatTranslationsObje
9994
: Args
10095
: never[];
10196

102-
export type {TranslationDeepObject, TranslationPaths, PluralForm, FlatTranslationsObject, TranslationParameters, TranslationKeyError, TranslationKeyErrors};
97+
export type {TranslationDeepObject, TranslationPaths, PluralForm, FlatTranslationsObject, TranslationParameters};

src/libs/ErrorUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import mapValues from 'lodash/mapValues';
22
import type {OnyxEntry} from 'react-native-onyx';
33
import CONST from '@src/CONST';
4-
import type {TranslationKeyError, TranslationKeyErrors, TranslationPaths} from '@src/languages/types';
5-
import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon';
4+
import type {TranslationPaths} from '@src/languages/types';
5+
import type {ErrorFields, Errors, TranslationKeyError, TranslationKeyErrors} from '@src/types/onyx/OnyxCommon';
66
import type Response from '@src/types/onyx/Response';
77
import type {ReceiptError} from '@src/types/onyx/Transaction';
88
import DateUtils from './DateUtils';

src/types/onyx/OnyxCommon.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {ValueOf} from 'type-fest';
22
import type {AvatarSource} from '@libs/UserUtils';
33
import type CONST from '@src/CONST';
4+
import type { TranslationPaths } from '@src/languages/types';
45

56
/** Pending onyx actions */
67
type PendingAction = ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION> | null;
@@ -26,6 +27,21 @@ type ErrorFields<TKey extends string = string> = Record<TKey, Errors | null | un
2627
/** Mapping of form fields with error translation keys and variables */
2728
type Errors = Record<string, string | null>;
2829

30+
/**
31+
* Error object for a translation key
32+
*/
33+
type TranslationKeyError = {
34+
/**
35+
* The translation key
36+
*/
37+
translationKey: TranslationPaths;
38+
};
39+
40+
/**
41+
* Mapping of form fields with key and translation key error variables
42+
*/
43+
type TranslationKeyErrors = Record<string, TranslationKeyError>;
44+
2945
/**
3046
* Types of avatars
3147
** avatar - user avatar
@@ -54,4 +70,4 @@ type Icon = {
5470
fill?: string;
5571
};
5672

57-
export type {Icon, PendingAction, PendingFields, ErrorFields, Errors, AvatarType, OnyxValueWithOfflineFeedback};
73+
export type {Icon, PendingAction, PendingFields, ErrorFields, Errors, AvatarType, OnyxValueWithOfflineFeedback, TranslationKeyError, TranslationKeyErrors};

0 commit comments

Comments
 (0)