[Payment due @marufsharifi] [Commuter Mileage Exclusion] [R1] Display and enforce fixed distance exclusions - #93848
Conversation
Foundation for the commuter exclusion feature: - TransactionCustomUnit gains commuterExclusion, reimbursableDistance, commuterExclusionType, and commuterExclusionMethod so the App can carry the PHP-computed exclusion metadata through Onyx. - Policy gains the commuterExclusions config object (method, fixedDistance, fixedDistanceUnit) so feature gating and the optimistic client-side compute can read it. - CONST.COMMUTER_EXCLUSIONS namespaces the method/type enums; a new COMMUTER_EXCLUSION report action type and a POLICYCHANGELOG_UPDATE_COMMUTER_EXCLUSIONS policy-change-log type are registered for the system message and workspace audit log. - en.ts adds the three-line breakdown labels, the manual/odometer blocked error copy, and the system-message fallback.
Add a DistanceWithCommuterExclusion component that reads
comment.customUnit.{quantity,commuterExclusion,reimbursableDistance,
distanceUnit} and renders a three-line breakdown (original distance,
removed commute distance, reimbursable distance). The component
renders nothing when commuterExclusion is not set or non-positive.
Mount it next to the existing DistanceField in
TransactionDetailsFields (the confirmation / IOURequestStepConfirmation
surface) and after the rate row in MoneyRequestView (the expense
detail / history surface), so both creation and post-creation views
show the same breakdown.
- DistanceRequestStartPage hides the Manual and Odometer tabs when every workspace the user belongs to has commuterExclusions configured. If at least one workspace lacks exclusions, all four tabs stay visible (the user can still pick that workspace). - useConfirmationValidation: allow zero-amount submission when the transaction carries a positive commuterExclusion, so a fully excluded distance expense (reimbursable = 0) can still be submitted in the split-bill-edit branch. The existing distance-request guard already handles the create branch.
- OriginalMessage gains OriginalMessageCommuterExclusion ({distance,
unit}) keyed under CONST.REPORT.ACTIONS.TYPE.COMMUTER_EXCLUSION so
callers reading the original message are properly typed.
- ReportActionsUtils.getCommuterExclusionMessage formats the system
message via the existing distance.commuterExclusion.systemMessage
i18n key.
- ActionContentRouter renders the COMMUTER_EXCLUSION action as a
ReportActionItemBasicMessage, matching the existing pattern used
for plaid/company-card system messages.
The COMMUTER_EXCLUSION action type is already in
CONST.REPORT.ACTIONS.TYPE and therefore in the supportedActionTypes
set built dynamically in ReportActionsUtils, so it is treated as a
visible chat action without further changes.
When the destination policy has a fixedDistance commuter exclusion
configured (method === "fixedDistance" with a positive fixedDistance),
createDistanceRequest now writes:
- A merge onto the optimistic transaction that fills the four new
comment.customUnit fields (commuterExclusion, reimbursableDistance,
commuterExclusionMethod) and sets modifiedAmount / modifiedMerchant
from the reimbursable distance, so the three-line breakdown and the
reduced amount render instantly without waiting on the server.
- An optimistic COMMUTER_EXCLUSION report action posted to
reportActions_${chatReportID} (pendingAction: ADD), so the system
message renders instantly too. ActionContentRouter picks this up
and renders the localized breakdown.
Failure data reverts both side effects (transaction fields cleared,
optimistic action removed). For commuterExclusions undefined and for
the not-yet-supported homeAndOffice method, behavior is unchanged.
Adds buildOptimisticCommuterExclusionReportAction in ReportUtils
following the existing buildOptimisticCancelPaymentReportAction
pattern.
When the destination policy has commuterExclusions configured, the user is no longer allowed to submit a manual or odometer distance expense — the exclusion is computed off the mapped route, so the mapped flow is the only correct entry. Show a localized form error explaining why, instead of silently accepting an entry that the backend wouldn't apply exclusions to. This complements the tab-hiding in DistanceRequestStartPage (which only hides the tabs when *every* workspace the user belongs to has exclusions); when the user has any non-exclusion workspace, the tabs stay visible but selecting an exclusion workspace on submission surfaces this error.
|
Hey, I noticed you changed If you want to automatically generate translations for other locales, an Expensify employee will have to:
Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running: npx ts-node ./scripts/generateTranslations.ts --helpTypically, you'd want to translate only what you changed by running |
Remove the top-level COMMUTER_EXCLUSIONS object and use the existing COMMUTER_EXCLUSION_METHOD and COMMUTER_EXCLUSION_TYPE constants within CONST.POLICY instead.
Add getCommuterExclusionBreakdown to compute the excluded commuter distance and reimbursable distance (from the transaction or previewed from the policy), and getDistanceUnitLabel to return the translated, pluralized unit label.
Render the distance field as "Distance · Original: X" with the reimbursable distance as the main value and a "Removed X commuter" line via the shared DistanceWithCommuterExclusion component, on both the confirmation page and the expense view. Add the supporting translation strings.
Base the distance request amount on the reimbursable distance after the commuter exclusion, and build the optimistic transaction fields and system action on creation. Derive the quantity from the route distance when it isn't populated yet so the exclusion is reflected immediately for route-based requests.
Build the commuter exclusion and fixed-distance report action messages from a preformatted distance, and render the commuter exclusion message as HTML linking to the workspace distance settings.
…references. Update distance request handling to calculate reimbursable distance using server-side logic instead of optimistic actions.
For distance requests, always use the computed distanceRequestAmount since it accounts for commuter exclusions and rate changes. This avoids stale iouAmount values that don't reflect the current commuter exclusion.
- Return commuterExclusionBreakdown from useDistanceRequestState - Create commuterExclusionData in MoneyRequestConfirmationList with proper unit fallbacks to handle undefined cases - Update DistanceField to display commuter exclusion UI using the computed breakdown, with fallback for unit prop
When commuter exclusion applies, display the reimbursable distance (not the full distance) in the merchant text so it matches the calculated amount.
In offline mode, the transaction may not have commuterExclusion stored yet. Fall back to computing it from the policy's commuterExclusions config, enabling instant display of commuter exclusion breakdown before the server response.
Move quantity derivation into getCommuterExclusionBreakdown and let getDistanceForDisplay render the reimbursable distance via an optional commuterExclusionData param, removing duplicated formatting across MoneyRequestView and DistanceField.
…d getDistanceForDisplay
… original distance Share the display-unit formatting between getDistanceForDisplay, MoneyRequestView, and DistanceField instead of duplicating ad-hoc toFixed formatting.
Add isCommuterDistance flag and delegate the unit word to getDistanceUnitLabel, replacing duplicated commuter distance formatting in DistanceWithCommuterExclusion and ReportActionsUtils.
Updated the useDistanceRequestState hook to utilize commuterExclusionData instead of commuterExclusionBreakdown for improved clarity and consistency. Adjusted related components to reflect this change, ensuring proper data flow and display for distance requests.
|
Deploy Blocker #98222 was identified to be related to this PR. |
|
Deploy Blocker #98225 was identified to be related to this PR. |
|
Deploy Blocker #98228 was identified to be related to this PR |
|
Deploy Blocker #98229 was identified to be related to this PR |
|
Deploy Blocker #98235 was identified to be related to this PR |
|
Deploy Blocker #98239 was identified to be related to this PR. |
|
Deploy Blocker #98248 was identified to be related to this PR. |
|
Deploy Blocker #98251 was identified to be related to this PR. |
|
Deploy Blocker #98252 was identified to be related to this PR. |
|
Deploy Blocker #98257 was identified to be related to this PR. |
|
Deploy Blocker #98284 was identified to be related to this PR. |
|
Deploy Blocker #98343 was identified to be related to this PR |
|
Deploy Blocker #98344 was identified to be related to this PR. |
Explanation of Change
Implements the App-side slice of the workspace commuter exclusion feature (App issue #642599). PHP-side (Web-Expensify) lands in https://github.com/Expensify/Web-Expensify/pull/53798.
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/642599
$ https://github.com/Expensify/Expensify/issues/651462
$ https://github.com/Expensify/Expensify/issues/642598
PROPOSAL:
Tests
fixedDistance=1.4.49mi mapped route on that workspace.DistanceRequestStartPage.Offline tests
QA Steps
Same as Tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari