Skip to content

Commit

Permalink
Merge pull request #31491 from Krishna2323/krishna2323/issue/31128
Browse files Browse the repository at this point in the history
fix: Distance - The title 'Distance' changing to 'Merchant' when toggling on Billable
  • Loading branch information
iwiznia authored Nov 20, 2023
2 parents fb8bdb7 + 3e59d00 commit cdb47b7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,13 @@ function MoneyRequestView({report, parentReport, policyCategories, shouldShowHor
/>
</OfflineWithFeedback>
)}

{shouldShowBillable && (
<View style={[styles.flexRow, styles.optionRow, styles.justifyContentBetween, styles.alignItemsCenter, styles.ml5, styles.mr8]}>
<Text color={!transactionBillable ? theme.textSupporting : undefined}>{translate('common.billable')}</Text>
<Switch
accessibilityLabel={translate('common.billable')}
isOn={transactionBillable}
onToggle={(value) => IOU.editMoneyRequest(transaction.transactionID, report.reportID, {billable: value})}
onToggle={(value) => IOU.editMoneyRequest(transaction, report.reportID, {billable: value})}
/>
</View>
)}
Expand Down
20 changes: 16 additions & 4 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ function createDistanceRequest(report, participant, comment, created, transactio
* @param {Object} [transactionChanges.waypoints]
*
*/
function updateDistanceRequest(transactionID, transactionThreadReportID, transactionChanges) {
function editDistanceMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) {
const optimisticData = [];
const successData = [];
const failureData = [];
Expand Down Expand Up @@ -1771,7 +1771,7 @@ function setDraftSplitTransaction(transactionID, transactionChanges = {}) {
* @param {Number} transactionThreadReportID
* @param {Object} transactionChanges
*/
function editMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) {
function editRegularMoneyRequest(transactionID, transactionThreadReportID, transactionChanges) {
// STEP 1: Get all collections we're updating
const transactionThread = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`];
const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
Expand Down Expand Up @@ -1985,6 +1985,19 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
);
}

/**
* @param {object} transaction
* @param {Number} transactionThreadReportID
* @param {Object} transactionChanges
*/
function editMoneyRequest(transaction, transactionThreadReportID, transactionChanges) {
if (TransactionUtils.isDistanceRequest(transaction)) {
editDistanceMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges);
} else {
editRegularMoneyRequest(transaction.transactionID, transactionThreadReportID, transactionChanges);
}
}

/**
* @param {String} transactionID
* @param {Object} reportAction - the money request reportAction we are deleting
Expand Down Expand Up @@ -2962,7 +2975,6 @@ function getIOUReportID(iou, route) {

export {
createDistanceRequest,
editMoneyRequest,
deleteMoneyRequest,
splitBill,
splitBillAndOpenReport,
Expand Down Expand Up @@ -2992,8 +3004,8 @@ export {
setMoneyRequestReceipt,
setUpDistanceTransaction,
navigateToNextPage,
updateDistanceRequest,
replaceReceipt,
detachReceipt,
getIOUReportID,
editMoneyRequest,
};
2 changes: 1 addition & 1 deletion src/pages/EditRequestDistancePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup}
}

transactionWasSaved.current = true;
IOU.updateDistanceRequest(transaction.transactionID, report.reportID, {waypoints});
IOU.editMoneyRequest(transaction, report.reportID, {waypoints});

// If the client is offline, then the modal can be closed as well (because there are no errors or other feedback to show them
// until they come online again and sync with the server).
Expand Down
6 changes: 1 addition & 5 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ function EditRequestPage({report, route, parentReport, policyCategories, policyT

// Update the transaction object and close the modal
function editMoneyRequest(transactionChanges) {
if (TransactionUtils.isDistanceRequest(transaction)) {
IOU.updateDistanceRequest(transaction.transactionID, report.reportID, transactionChanges);
} else {
IOU.editMoneyRequest(transaction.transactionID, report.reportID, transactionChanges);
}
IOU.editMoneyRequest(transaction, report.reportID, transactionChanges);
Navigation.dismissModal(report.reportID);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ describe('actions/IOU', () => {
return waitForBatchedUpdates();
})
.then(() => {
IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'});
IOU.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'});
return waitForBatchedUpdates();
})
.then(
Expand Down Expand Up @@ -1613,7 +1613,7 @@ describe('actions/IOU', () => {
})
.then(() => {
fetch.fail();
IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'});
IOU.editMoneyRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'});
return waitForBatchedUpdates();
})
.then(
Expand Down

0 comments on commit cdb47b7

Please sign in to comment.