-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat: Edit Distance Rate flow #40021
Merged
neil-marcellini
merged 26 commits into
Expensify:main
from
paultsimura:feat/36987-rate-edit
Aug 5, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a3ea866
Init: Edit Rate flow
paultsimura d514b30
Merge branch 'fork/feat/36985-create-new-rate-field' into feat/36987-…
paultsimura 967921b
Rate edit: initial commit
paultsimura 2c07b55
Merge branch 'main' into feat/36987-rate-edit
paultsimura ed1f907
Merge branch 'fork/feat/36985-create-new-rate-field' into feat/36987-…
paultsimura 180d885
Merge branch 'main' into feat/36987-rate-edit
paultsimura 1158ffd
Merge branch 'main' into feat/36987-rate-edit
paultsimura 21054fe
Some progress with edit rate
paultsimura 2223b04
Merge branch 'refs/heads/main' into feat/36987-rate-edit
paultsimura 8167592
Almost final changes for Rate Edit flow
paultsimura 5cd792a
Use pending field indicator
paultsimura de51398
Merge branch 'refs/heads/main' into feat/36987-rate-edit
paultsimura 05d522e
Move getDistanceInMeters to DistanceRequestUtils to avoid circular deps
paultsimura 03bd854
Fix type
paultsimura b7fa71e
Lint
paultsimura 42e2db9
Merge branch 'Expensify:main' into feat/36987-rate-edit
paultsimura a2ad2db
Move getDistanceInMeters into TransactionUtils
paultsimura b5544b1
Lint
paultsimura db7639a
Fix file name
paultsimura fe0e98e
Lint
paultsimura 867e85e
Merge branch 'Expensify:main' into feat/36987-rate-edit
paultsimura 6ccacb8
Always show wrapper for the rate page
paultsimura ebdbe0e
Merge branch 'refs/heads/main' into feat/36987-rate-edit
paultsimura 65a07ff
Edit Rate: code cleanup
paultsimura 2029ec5
Merge branch 'refs/heads/main' into feat/36987-rate-edit
paultsimura 63865a3
Edit Rate: code cleanup
paultsimura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,7 @@ type TransactionDetails = { | |
currency: string; | ||
merchant: string; | ||
waypoints?: WaypointCollection | string; | ||
customUnitRateID?: string; | ||
comment: string; | ||
category: string; | ||
billable: boolean; | ||
|
@@ -2719,6 +2720,7 @@ function getTransactionDetails(transaction: OnyxInputOrEntry<Transaction>, creat | |
comment: TransactionUtils.getDescription(transaction), | ||
merchant: TransactionUtils.getMerchant(transaction), | ||
waypoints: TransactionUtils.getWaypoints(transaction), | ||
customUnitRateID: TransactionUtils.getRateID(transaction), | ||
category: TransactionUtils.getCategory(transaction), | ||
billable: TransactionUtils.getBillable(transaction), | ||
tag: TransactionUtils.getTag(transaction), | ||
|
@@ -2813,6 +2815,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry<ReportAction> | |
CONST.EDIT_REQUEST_FIELD.DATE, | ||
CONST.EDIT_REQUEST_FIELD.RECEIPT, | ||
CONST.EDIT_REQUEST_FIELD.DISTANCE, | ||
CONST.EDIT_REQUEST_FIELD.DISTANCE_RATE, | ||
]; | ||
|
||
if (!ReportActionsUtils.isMoneyRequestAction(reportAction) || !canEditMoneyRequest(reportAction)) { | ||
|
@@ -2852,6 +2855,11 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry<ReportAction> | |
return !isInvoiceReport(moneyRequestReport) && !TransactionUtils.isReceiptBeingScanned(transaction) && !TransactionUtils.isDistanceRequest(transaction) && isRequestor; | ||
} | ||
|
||
if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.DISTANCE_RATE) { | ||
// The distance rate can be modified only on the distance expense reports | ||
return isExpenseReport(moneyRequestReport) && TransactionUtils.isDistanceRequest(transaction); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -3291,6 +3299,19 @@ function getModifiedExpenseOriginalMessage( | |
originalMessage.billable = transactionChanges?.billable ? Localize.translateLocal('common.billable').toLowerCase() : Localize.translateLocal('common.nonBillable').toLowerCase(); | ||
} | ||
|
||
if ('customUnitRateID' in transactionChanges) { | ||
originalMessage.oldAmount = TransactionUtils.getAmount(oldTransaction, isFromExpenseReport); | ||
originalMessage.oldCurrency = TransactionUtils.getCurrency(oldTransaction); | ||
originalMessage.oldMerchant = TransactionUtils.getMerchant(oldTransaction); | ||
|
||
const modifiedData = TransactionUtils.calculateAmountForUpdatedWaypointOrRate(oldTransaction, transactionChanges, policy, isFromExpenseReport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: Maybe call this |
||
|
||
// For the originalMessage, we should use the non-negative amount, similar to what TransactionUtils.getAmount does for oldAmount | ||
originalMessage.amount = Math.abs(modifiedData.modifiedAmount); | ||
originalMessage.currency = modifiedData.modifiedCurrency; | ||
originalMessage.merchant = modifiedData.modifiedMerchant; | ||
} | ||
|
||
return originalMessage; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this so the
RateAndUnit
is more consistent with theMileageRate
and we could use thecurrency
from their union type:MileageRate | RateAndUnit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB: IMO let's delete this type and just use
MileageRate
, sinceRateAndUnit
is a subset of it, and the name is not great and now inaccurate. It can be cleaned up in a follow up.