Skip to content

Commit

Permalink
Merge pull request #26536 from jeet-dhandha/fix-26518
Browse files Browse the repository at this point in the history
Fix - Distance Request Optimistic Data (26518)
  • Loading branch information
Hayata Suenaga authored Sep 2, 2023
2 parents 9701fbe + 3712c95 commit 7e3e760
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ function MoneyRequestConfirmationList(props) {
return [...selectedParticipants, OptionsListUtils.getIOUConfirmationOptionsFromPayeePersonalDetail(payeePersonalDetails)];
}, [selectedParticipants, props.hasMultipleParticipants, payeePersonalDetails]);

const distanceMerchant = useMemo(() => DistanceRequestUtils.getDistanceMerchant(distance, unit, rate, currency, translate), [distance, unit, rate, currency, translate]);

useEffect(() => {
IOU.setMoneyRequestMerchant(distanceMerchant);
}, [distanceMerchant]);

/**
* @param {Object} option
*/
Expand Down Expand Up @@ -457,7 +463,7 @@ function MoneyRequestConfirmationList(props) {
{props.isDistanceRequest ? (
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly && isTypeRequest}
title={DistanceRequestUtils.getDistanceMerchant(distance, unit, rate, currency, translate)}
title={distanceMerchant}
description={translate('common.distance')}
style={[styles.moneyRequestMenuItem, styles.mb2]}
titleStyle={styles.flex1}
Expand Down
5 changes: 4 additions & 1 deletion src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ function getLinkedTransaction(reportAction = {}) {
}

function getAllReportTransactions(reportID) {
return _.filter(allTransactions, (transaction) => transaction.reportID === reportID);
// `reportID` from the `/CreateDistanceRequest` endpoint return's number instead of string for created `transaction`.
// For reference, https://github.com/Expensify/App/pull/26536#issuecomment-1703573277.
// We will update this in a follow-up Issue. According to this comment: https://github.com/Expensify/App/pull/26536#issuecomment-1703591019.
return _.filter(allTransactions, (transaction) => `${transaction.reportID}` === `${reportID}`);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,19 @@ function getMoneyRequestInformation(
* @param {String} comment
* @param {String} created
* @param {String} [transactionID]
* @param {Number} amount
* @param {String} currency
* @param {String} merchant
*/
function createDistanceRequest(report, participant, comment, created, transactionID) {
function createDistanceRequest(report, participant, comment, created, transactionID, amount, currency, merchant) {
const {iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = getMoneyRequestInformation(
report,
participant,
comment,
0,
'USD',
amount,
currency,
created,
'',
merchant,
null,
null,
null,
Expand Down
13 changes: 11 additions & 2 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ function MoneyRequestConfirmPage(props) {
*/
const createDistanceRequest = useCallback(
(selectedParticipants, trimmedComment) => {
IOU.createDistanceRequest(props.report, selectedParticipants[0], trimmedComment, props.iou.created, props.iou.transactionID);
IOU.createDistanceRequest(
props.report,
selectedParticipants[0],
trimmedComment,
props.iou.created,
props.iou.transactionID,
props.iou.amount,
props.iou.currency,
props.iou.merchant,
);
},
[props.report, props.iou.created, props.iou.transactionID],
[props.report, props.iou.created, props.iou.transactionID, props.iou.amount, props.iou.currency, props.iou.merchant],
);

const createTransaction = useCallback(
Expand Down

0 comments on commit 7e3e760

Please sign in to comment.