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 - The title 'Distance' changing to 'Merchant' when toggling on Billable #31491

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.editMoneyOrDistanceRequest(transaction, report.reportID, {billable: value})}
/>
</View>
)}
Expand Down
16 changes: 14 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,19 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC
);
}

/**
* @param {object} transaction
* @param {Number} transactionThreadReportID
* @param {Object} transactionChanges
*/
function editMoneyOrDistanceRequest(transaction, transactionThreadReportID, transactionChanges) {
if (TransactionUtils.isDistanceRequest(transaction)) {
updateDistanceRequest(transaction.transactionID, transactionThreadReportID, transactionChanges);
} else {
editMoneyRequest(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,
editMoneyOrDistanceRequest,
};
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.editMoneyOrDistanceRequest(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.editMoneyOrDistanceRequest(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.editMoneyOrDistanceRequest(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.editMoneyOrDistanceRequest(transaction, thread.reportID, {amount: 20000, comment: 'Double the amount!'});
return waitForBatchedUpdates();
})
.then(
Expand Down
Loading