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/26946: Reset amount when edit waypoint #33397

Merged
merged 7 commits into from
Jan 2, 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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ const CONST = {
EXPENSIFY: 'Expensify',
VBBA: 'ACH',
},
DEFAULT_AMOUNT: 0,
TYPE: {
SEND: 'send',
SPLIT: 'split',
Expand Down
9 changes: 9 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ function setMoneyRequestAmount_temporaryForRefactor(transactionID, amount, curre
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount, currency});
}

/**
* Reset the money request amount, discarding the user-provided value. In the case of distance requests, this will effectively re-enable the default behavior of automatic amount calculation.
* @param {String} transactionID
Copy link
Contributor

Choose a reason for hiding this comment

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

Description:

Reset the money request amount, discarding the user-provided value. In the case of distance requests, this will effectively re-enable the default behavior of automatic amount calculation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

*/
function resetMoneyRequestAmount_temporaryForRefactor(transactionID) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {amount: CONST.IOU.DEFAULT_AMOUNT});
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this lead to a regression because it doesn't not take isDraft into account like this:

`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION : ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tgolen I will raise a quick PR to fix it

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this may be another regression w/ the same cause

}

/**
* @param {String} transactionID
* @param {String} created
Expand Down Expand Up @@ -3434,4 +3442,5 @@ export {
detachReceipt,
getIOUReportID,
editMoneyRequest,
resetMoneyRequestAmount_temporaryForRefactor,
};
4 changes: 4 additions & 0 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import {RecentWaypoint, Transaction} from '@src/types/onyx';
import {OnyxData} from '@src/types/onyx/Request';
import {WaypointCollection} from '@src/types/onyx/Transaction';
import * as IOU from './IOU';

let recentWaypoints: RecentWaypoint[] = [];
Onyx.connect({
Expand Down Expand Up @@ -58,6 +59,7 @@ function addStop(transactionID: string) {
}

function saveWaypoint(transactionID: string, index: string, waypoint: RecentWaypoint | null, isDraft = false) {
IOU.resetMoneyRequestAmount_temporaryForRefactor(transactionID);
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION : ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {
comment: {
waypoints: {
Expand Down Expand Up @@ -100,6 +102,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
}

function removeWaypoint(transaction: Transaction, currentIndex: string, isDraft: boolean) {
IOU.resetMoneyRequestAmount_temporaryForRefactor(transaction.transactionID);
// Index comes from the route params and is a string
const index = Number(currentIndex);
const existingWaypoints = transaction?.comment?.waypoints ?? {};
Expand Down Expand Up @@ -240,6 +243,7 @@ function getRouteForDraft(transactionID: string, waypoints: WaypointCollection)
* which will replace the existing ones.
*/
function updateWaypoints(transactionID: string, waypoints: WaypointCollection, isDraft = false): Promise<void> {
IOU.resetMoneyRequestAmount_temporaryForRefactor(transactionID);
return Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
comment: {
waypoints,
Expand Down
Loading