Skip to content

Commit

Permalink
Store filename and source properly on transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Nov 2, 2023
1 parent 0a1fb85 commit 0d4ddde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function setMoneyRequestParticipants_temporaryForRefactor(transactionID, partici
* @param {String} filename
*/
function setMoneyRequestReceipt_temporaryForRefactor(transactionID, source, filename) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {receipt: {path: filename, source}});
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {receipt: {source}, filename});
}

/**
Expand Down
36 changes: 13 additions & 23 deletions src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ function IOURequestStepConfirmation({
params: {iouType, reportID, transactionID},
},
transaction,
transaction: {receipt = {}},
transaction: {
filename: receiptFilename,
receipt: {source: receiptPath},
},
}) {
const {translate} = useLocalize();
const {windowWidth} = useWindowDimensions();
Expand Down Expand Up @@ -100,10 +103,10 @@ function IOURequestStepConfirmation({
}, [participants, transaction.billable, policy, transactionID]);

useEffect(() => {
if (!receipt) {
if (!receiptFilename || !receiptPath) {
return;
}
FileUtils.readFileAsync(receipt.path, receipt.source).then((file) => {
FileUtils.readFileAsync(receiptPath, receiptFilename).then((file) => {
if (!file) {
Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType, reportID));
} else {
Expand All @@ -113,7 +116,7 @@ function IOURequestStepConfirmation({
});
}
});
}, [receipt, requestType, iouType, reportID]);
}, [receiptFilename, receiptPath, requestType, iouType, reportID]);

const navigateBack = () => {
// If there is not a report attached to the IOU with a reportID, then the participants were manually selected and the user needs taken
Expand Down Expand Up @@ -203,11 +206,9 @@ function IOURequestStepConfirmation({
const trimmedComment = lodashGet(transaction, 'comment.comment', '').trim();

// If we have a receipt let's start the split bill by creating only the action, the transaction, and the group DM if needed
if (iouType === CONST.IOU.TYPE.SPLIT && receipt.path) {
if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) {
const existingSplitChatReportID = CONST.REGEX.NUMBER.test(reportID) ? reportID : '';
FileUtils.readFileAsync(receipt.path, receipt.source).then((file) => {
IOU.startSplitBill(selectedParticipants, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, trimmedComment, file, existingSplitChatReportID);
});
IOU.startSplitBill(selectedParticipants, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, trimmedComment, receiptFile, existingSplitChatReportID);
return;
}

Expand Down Expand Up @@ -241,6 +242,7 @@ function IOURequestStepConfirmation({
return;
}

console.log('[tim', receiptFile);

Check failure on line 245 in src/pages/iou/request/step/IOURequestStepConfirmation.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
if (receiptFile) {
requestMoney(selectedParticipants, trimmedComment, receiptFile);
return;
Expand All @@ -253,19 +255,7 @@ function IOURequestStepConfirmation({

requestMoney(selectedParticipants, trimmedComment);
},
[
iouType,
transaction,
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
receipt,
report,
reportID,
requestType,
createDistanceRequest,
requestMoney,
receiptFile,
],
[iouType, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, report, reportID, requestType, createDistanceRequest, requestMoney, receiptFile],
);

/**
Expand Down Expand Up @@ -344,7 +334,7 @@ function IOURequestStepConfirmation({
onSendMoney={sendMoney}
onSelectParticipant={addNewParticipant}
receiptPath={lodashGet(transaction, 'receipt.source')}
receiptFilename={lodashGet(transaction, 'receipt.path')}
receiptFilename={lodashGet(transaction, 'filename')}
iouType={iouType}
reportID={reportID}
isPolicyExpenseChat={isPolicyExpenseChat}
Expand All @@ -360,7 +350,7 @@ function IOURequestStepConfirmation({
iouCreated={transaction.created}
isScanRequest={requestType === CONST.IOU.REQUEST_TYPE.SCAN}
isDistanceRequest={requestType === CONST.IOU.REQUEST_TYPE.DISTANCE}
shouldShowSmartScanFields={!_.isEmpty(transaction.receipt)}
shouldShowSmartScanFields={_.isEmpty(lodashGet(transaction, 'receipt.source', ''))}
/>
</View>
)}
Expand Down

0 comments on commit 0d4ddde

Please sign in to comment.