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

Use updateMoneyRequestBillable #33245

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate

let amountDescription = `${translate('iou.amount')}`;

const saveBillable = useCallback(
(newBillable) => {
// If the value hasn't changed, don't request to save changes on the server and just close the modal
if (newBillable === TransactionUtils.getBillable(transaction)) {
Navigation.dismissModal();
return;
}
IOU.updateMoneyRequestBillable(transaction.transactionID, report.reportID, newBillable);
Navigation.dismissModal();
Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins @c3024,Coming from this PR, why do we need to call Navigation.dismissModal();?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we just wanted to navigate the user back once they edit the billable field.

Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins, do you mean we want to navigate back (close the RHP) if report is opened in RHP? I don't think we should be doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should do that if the report is opened from the central pane (original design in this PR). If the report is opened in the RHP, I agree that we should just navigate back.

Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins, I think we don't need to do anything in both cases. When report is opened in central pane we shouldn't navigate when toggling billable value and same for RHP, we should not close the RHP just because of updating billable value. The RHP should remain open like it is opened when any other field is edited. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tested again and I think that makes sense. Toggling billable when opening the thread from the central pane doesn't dismiss the modal, so we should do the same for the RHP

Screen.Recording.2024-07-09.at.9.51.45.AM.mov

},
[transaction, report],
);

if (isCardTransaction) {
if (formattedOriginalAmount) {
amountDescription += ` • ${translate('iou.original')} ${formattedOriginalAmount}`;
Expand Down Expand Up @@ -354,7 +367,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
<Switch
accessibilityLabel={translate('common.billable')}
isOn={transactionBillable}
onToggle={(value) => IOU.editMoneyRequest(transaction, report.reportID, {billable: value})}
onToggle={saveBillable}
/>
</View>
{hasViolations('billable') && (
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,21 @@ function updateMoneyRequestDate(transactionID, transactionThreadReportID, val) {
API.write('UpdateMoneyRequestDate', params, onyxData);
}

/**
* Updates the billable field of a money request
*
* @param {String} transactionID
* @param {Number} transactionThreadReportID
* @param {String} val
*/
function updateMoneyRequestBillable(transactionID, transactionThreadReportID, val) {
const transactionChanges = {
billable: val,
};
const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, true);
API.write('UpdateMoneyRequestBillable', params, onyxData);
}

/**
* Updates the merchant field of a money request
*
Expand Down Expand Up @@ -3605,6 +3620,7 @@ export {
setUpDistanceTransaction,
navigateToNextPage,
updateMoneyRequestDate,
updateMoneyRequestBillable,
updateMoneyRequestMerchant,
updateMoneyRequestTag,
updateMoneyRequestAmountAndCurrency,
Expand Down
Loading