Skip to content

[Payment due @marufsharifi] [Commuter Mileage Exclusion] [R1] Display and enforce fixed distance exclusions - #93848

Merged
Gonals merged 154 commits into
Expensify:mainfrom
fedirjh:commuter-exclusions-app
Aug 10, 2026
Merged

[Payment due @marufsharifi] [Commuter Mileage Exclusion] [R1] Display and enforce fixed distance exclusions#93848
Gonals merged 154 commits into
Expensify:mainfrom
fedirjh:commuter-exclusions-app

Conversation

@fedirjh

@fedirjh fedirjh commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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

  1. Open a workspace that has commuter Exclusions set with fixedDistance = 1.
  2. Create a distance expense from a 4.49 mi mapped route on that workspace.
  3. Verify on the confirmation step: the three-line breakdown shows under the Distance row (Original 4.49 mi / Removed 1.00 mi / Reimbursable 3.49 mi) and the amount reflects 3.49 × rate.
  4. Submit. Verify the transaction report shows the system message "Removed 1.00 commuter miles based on workspace distance settings." and the expense detail page also shows the breakdown.
  5. Verify :
    • When every workspace has exclusions, only Map and GPS tabs appear in DistanceRequestStartPage.
    • When some workspaces have exclusions:
      • All four distance tabs (Map / Manual / GPS / Odometer) appear
      • From a workspace with exclusions, switching the Manual or Odometer step and pressing Next surfaces blocking modal.
  • Verify that no errors appear in the JS console

Offline tests

  1. Toggle network off, create a distance expense on an exclusion workspace.
  2. Verify the optimistic breakdown (Original / Removed / Reimbursable) and the reduced amount render immediately. Note: the "Removed … commuter miles based on workspace distance settings" system message is created by the backend, so it does not appear while offline.
  3. Toggle network on, verify the server response confirms the values without flicker and the system message then appears.
  4. Repeat with the network failing the request — verify the optimistic transaction merge (breakdown + amount) reverts.

QA Steps

Same as Tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Screenshot 2026-06-30 at 11 03 59 AM Screenshot 2026-06-30 at 11 04 04 AM Screenshot 2026-06-29 at 4 51 47 PM Screenshot 2026-06-29 at 4 53 53 PM Screenshot 2026-06-29 at 5 09 48 PM Screenshot 2026-06-29 at 5 09 58 PM Screenshot 2026-06-29 at 5 10 26 PM
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

fedirjh added 6 commits June 17, 2026 14:07
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.
@melvin-bot

melvin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

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 --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

fedirjh added 22 commits June 17, 2026 16:29
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.
… 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.
@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98222 was identified to be related to this PR.

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98225 was identified to be related to this PR.

@lanitochka17

Copy link
Copy Markdown

Deploy Blocker #98228 was identified to be related to this PR

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98229 was identified to be related to this PR

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98235 was identified to be related to this PR

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #98239 was identified to be related to this PR.

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98248 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #98251 was identified to be related to this PR.

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #98252 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #98257 was identified to be related to this PR.

@marufsharifi

Copy link
Copy Markdown
Contributor

@fedirjh, could you please raise a separate small, focused PR for each issue? It makes them much easier to review and test, and keeps turnaround quick on both sides. Thanks so much for your work on this!

cc @Gonals

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #98284 was identified to be related to this PR.

@lanitochka17

Copy link
Copy Markdown

Deploy Blocker #98343 was identified to be related to this PR

@lanitochka17

Copy link
Copy Markdown

Deploy Blocker #98344 was identified to be related to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

#convert Relates to work in the #convert room

Projects

None yet

Development

Successfully merging this pull request may close these issues.