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

Fix - Distance Request Optimistic Data (26518) #26536

Merged
merged 6 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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);
Copy link
Contributor

@hayata-suenaga hayata-suenaga Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this pattern though.

We should get the distance request merchant string and set the string in IOU at the same place.

We can put the following code inside useEffect with the dependency array.

const distanceMerchant = DistanceRequestUtils.getDistanceMerchant(distance, unit, rate, currency, translate)
IOU.setMoneyRequestMerchant(distanceMerchant);

And for the title of MenuItemWithTopDescription, we can pass iou.merchant instead.

I gonna approve this PR right now, but please make a follow up PR @jeet-dhandha for the cleanup 🙇

We consider the issue to be complete after the follow-up PR is merged 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}, [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
2 changes: 1 addition & 1 deletion src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function getLinkedTransaction(reportAction = {}) {
}

function getAllReportTransactions(reportID) {
return _.filter(allTransactions, (transaction) => transaction.reportID === reportID);
return _.filter(allTransactions, (transaction) => `${transaction.reportID}` === `${reportID}`);
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this change ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test it out and see. Hopefully it has been fixed.

}

/**
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.merchat,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo? It should be props.iou.merchant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 🙇 . Sorry for that.

);
},
[props.report, props.iou.created, props.iou.transactionID],
[props.report, props.iou.created, props.iou.transactionID, props.iou.amount, props.iou.currency, props.iou.merchat],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slip of hand 🥲

);

const createTransaction = useCallback(
Expand Down