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

Revert "fix: show error message for invalid receipt" #35496

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 1 addition & 9 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import iouReportPropTypes from '@pages/iouReportPropTypes';
import reportPropTypes from '@pages/reportPropTypes';
import {policyDefaultProps, policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import * as Transaction from '@userActions/Transaction';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -234,14 +233,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]}>
{hasReceipt && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={transaction.errors}
errorRowStyles={[styles.ml4]}
onClose={() => {
Transaction.clearError(transaction.transactionID);
}}
>
<OfflineWithFeedback pendingAction={pendingAction}>
<View style={styles.moneyRequestViewImage}>
<ReportActionItemImage
thumbnail={receiptURIs.thumbnail}
Expand Down
8 changes: 2 additions & 6 deletions src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Str from 'expensify-common/lib/str';
import _ from 'lodash';
import type {ImageSourcePropType} from 'react-native';
import ReceiptDoc from '@assets/images/receipt-doc.png';
import ReceiptGeneric from '@assets/images/receipt-generic.png';
Expand All @@ -8,7 +7,6 @@ import ReceiptSVG from '@assets/images/receipt-svg.png';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Transaction} from '@src/types/onyx';
import type {ReceiptError} from '@src/types/onyx/Transaction';
import * as FileUtils from './fileDownload/FileUtils';

type ThumbnailAndImageURI = {
Expand Down Expand Up @@ -36,11 +34,9 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
}

// 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 path = errors?.source ?? transaction?.receipt?.source ?? receiptPath ?? '';
const path = transaction?.receipt?.source ?? receiptPath ?? '';
// filename of uploaded image or last part of remote URI
const filename = errors?.filename ?? transaction?.filename ?? receiptFileName ?? '';
const filename = transaction?.filename ?? receiptFileName ?? '';
const isReceiptImage = Str.isImage(filename);
const hasEReceipt = transaction?.hasEReceipt;

Expand Down
13 changes: 6 additions & 7 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -3511,18 +3511,18 @@ function detachReceipt(transactionID) {
* @param {String} source
*/
function replaceReceipt(transactionID, file, source) {
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] || {};
const transaction = lodashGet(allTransactions, 'transactionID', {});
const oldReceipt = lodashGet(transaction, 'receipt', {});
const receiptOptimistic = {
source,
state: CONST.IOU.RECEIPT_STATE.OPEN,
};

const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
receipt: receiptOptimistic,
receipt: {
source,
state: CONST.IOU.RECEIPT_STATE.OPEN,
},
filename: file.name,
},
},
Expand All @@ -3535,7 +3535,6 @@ function replaceReceipt(transactionID, file, source) {
value: {
receipt: oldReceipt,
filename: transaction.filename,
errors: getReceiptError(receiptOptimistic, file.name),
},
},
];
Expand Down
6 changes: 1 addition & 5 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,4 @@ function updateWaypoints(transactionID: string, waypoints: WaypointCollection, i
});
}

function clearError(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null});
}

export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, getRouteForDraft, updateWaypoints, clearError};
export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, getRouteForDraft, updateWaypoints};
8 changes: 2 additions & 6 deletions src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ type Route = {

type Routes = Record<string, Route>;

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

type ReceiptErrors = Record<string, ReceiptError>;

type Transaction = {
amount: number;
billable: boolean;
category: string;
comment: Comment;
created: string;
currency: string;
errors?: OnyxCommon.Errors | ReceiptErrors;
errors?: OnyxCommon.Errors;
errorFields?: OnyxCommon.ErrorFields<'route'>;
// The name of the file used for a receipt (formerly receiptFilename)
filename?: string;
Expand Down Expand Up @@ -101,4 +97,4 @@ type Transaction = {
};

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