Skip to content

Commit

Permalink
Fix TS issues after merging main
Browse files Browse the repository at this point in the history
  • Loading branch information
VickyStash committed Jan 31, 2024
1 parent dedfe12 commit e7ff217
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/components/DotIndicatorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import useThemeStyles from '@hooks/useThemeStyles';
import fileDownload from '@libs/fileDownload';
import * as Localize from '@libs/Localize';
import CONST from '@src/CONST';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import {PressableWithoutFeedback} from './Pressable';
import Text from './Text';

type ReceiptError = {error?: string; source: string; filename: string};

type DotIndicatorMessageProps = {
/**
* In most cases this should just be errors from onxyData
Expand All @@ -23,7 +22,7 @@ type DotIndicatorMessageProps = {
* timestamp: 'message',
* }
*/
messages: Record<string, Localize.MaybePhraseKey>;
messages: Record<string, Localize.MaybePhraseKey | ReceiptError>;

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
Expand Down
3 changes: 2 additions & 1 deletion src/components/MessagesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 @@ -15,7 +16,7 @@ import Tooltip from './Tooltip';

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

/** The type of message, 'error' shows a red dot, 'success' shows a green dot */
type: 'error' | 'success';
Expand Down
5 changes: 3 additions & 2 deletions src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import mapChildrenFlat from '@libs/mapChildrenFlat';
import shouldRenderOffscreen from '@libs/shouldRenderOffscreen';
import CONST from '@src/CONST';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {ReceiptError, ReceiptErrors} from '@src/types/onyx/Transaction';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import MessagesRow from './MessagesRow';
Expand All @@ -26,7 +27,7 @@ type OfflineWithFeedbackProps = ChildrenProps & {
shouldHideOnDelete?: boolean;

/** The errors to display */
errors?: OnyxCommon.Errors | null;
errors?: OnyxCommon.Errors | ReceiptErrors | null;

/** Whether we should show the error messages */
shouldShowErrorMessages?: boolean;
Expand Down Expand Up @@ -84,7 +85,7 @@ function OfflineWithFeedback({

const hasErrors = !isEmptyObject(errors ?? {});
// Some errors have a null message. This is used to apply opacity only and to avoid showing redundant messages.
const errorMessages = omitBy(errors, (e) => e === null);
const errorMessages = omitBy(errors, (e: string | ReceiptError) => e === null);
const hasErrorMessages = !isEmptyObject(errorMessages);
const isOfflinePendingAction = !!isOffline && !!pendingAction;
const isUpdateOrDeleteError = hasErrors && (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ function MoneyRequestView({
{hasReceipt && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={transaction.errors}
errors={transaction?.errors}
errorRowStyles={[styles.ml4]}
onClose={() => {
if (!transaction?.transactionID) {
return;
}

Transaction.clearError(transaction.transactionID);
}}
>
Expand Down
6 changes: 5 additions & 1 deletion src/libs/Localize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CONST from '@src/CONST';
import translations from '@src/languages/translations';
import type {TranslationFlatObject, TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import LocaleListener from './LocaleListener';
import BaseLocaleListener from './LocaleListener/BaseLocaleListener';

Expand Down Expand Up @@ -102,7 +103,10 @@ type MaybePhraseKey = string | [string, Record<string, unknown> & {isTranslated?
/**
* Return translated string for given error.
*/
function translateIfPhraseKey(message: MaybePhraseKey): string {
function translateIfPhraseKey(message: MaybePhraseKey): string;
function translateIfPhraseKey(message: ReceiptError): ReceiptError;
function translateIfPhraseKey(message: MaybePhraseKey | ReceiptError): string | ReceiptError;
function translateIfPhraseKey(message: MaybePhraseKey | ReceiptError): string | ReceiptError {
if (!message || (Array.isArray(message) && message.length === 0)) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getThumbnailAndImageURIs(transaction: OnyxEntry<Transaction>, receiptPa
}
// URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg
// If there're errors, we need to display them in preview. We can store many files in errors, but we just need to get the last one
const errors = _.findLast(transaction.errors) as ReceiptError | undefined;
const errors = _.findLast(transaction?.errors) as ReceiptError | undefined;
const path = errors?.source ?? transaction?.receipt?.source ?? receiptPath ?? '';
// filename of uploaded image or last part of remote URI
const filename = errors?.filename ?? transaction?.filename ?? receiptFileName ?? '';
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ type Transaction = {
};

export default Transaction;
export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, TransactionPendingFieldsKey};
export type {WaypointCollection, Comment, Receipt, Waypoint, ReceiptError, ReceiptErrors, TransactionPendingFieldsKey};

0 comments on commit e7ff217

Please sign in to comment.