Skip to content

[Due for payment 2026-01-27] [Odometer] Distance expense category removed on 2nd policy switch #79598

Closed

Description

@Julesssss

Problem

Coming from this, a bug exists for Distance Expenses. The category field is hidden on the confirm details page every other time that the workspace is changed.

Creating a seperate issue as it occurs for all distance expense issues and shouldn't block this PR.

535570556-ca3d7ee0-16a6-4659-afa3-1837d9d2d656.mov
Issue OwnerCurrent Issue Owner: @heyjennahay

Activity

  1. added theissue type on Jan 14, 2026
  2. Eskalifer1 commented on Jan 14, 2026

    @Eskalifer1
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Distance expense category removed on 2nd policy switch

    What is the root cause of that problem?

    For distance requests, the default value is set here:

    useEffect(() => {
    for (const item of transactions) {
    if (!isDistanceRequest || !!item?.category) {
    continue;
    }
    setMoneyRequestCategory(item.transactionID, defaultCategory, policy);
    }
    // Prevent resetting to default when unselect category
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [transactionIDs, requestType, defaultCategory, policy?.id]);

    However, this useEffect does not work every time participants changes, so it works only once when one of the parameters changes, which is not a very reliable approach.

    What changes do you think we should make in order to solve the problem?

    We can do the following:

    1. Pass the option value here in onFinish to make it easier to get policyID:

      if (!option.isSelfDM) {
      onFinish();
      }

      (This step can be skipped if we can get the policyID in another way)

    2. We get this value here:

      const goToNextStep = useCallback(() => {

    3. And here we set the category value when participants change:

      const category = isMovingTransactionFromTrackExpense && transaction?.category ? transaction?.category : '';
      setMoneyRequestCategory(transaction.transactionID, category, undefined);

    We need to add logic for obtaining the default category, and if it is a distance request, then set it:

                const policy = option?.item && option?.policyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${option?.policyID}`] : undefined;
                const policyDistance = Object.values(policy?.customUnits ?? {}).find((customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
                const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
                const defaultCategory = policyDistance?.defaultCategory ?? '';
    
                const finalCategory = !!category ? category : isDistanceRequest ? defaultCategory : '';
    
                setMoneyRequestCategory(transaction.transactionID, finalCategory, undefined);

    PS: Implementation details can be discussed during the PR.

    What alternative solutions did you explore? (Optional)

    We can add some information related to participants, related to participants:

    useEffect(() => {
    for (const item of transactions) {
    if (!isDistanceRequest || !!item?.category) {
    continue;
    }
    setMoneyRequestCategory(item.transactionID, defaultCategory, policy);
    }
    // Prevent resetting to default when unselect category
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [transactionIDs, requestType, defaultCategory, policy?.id]);

    For example, we can simply add participants or ids participants.
    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  3. imadirtydog commented on Jan 14, 2026

    @imadirtydog

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Distance expense category removed on 2nd policy switch

    What is the root cause of that problem?

    In the useEffect here

    We are doing:

    const existingCategory = existingTransaction?.category;
    
    

    but the existingTransaction is undefined, because at this point we are working only with a draft.

    What changes do you think we should make in order to solve the problem?

    We can move the useEffect below definition of defaultCategory and modify the useEffect in such a way:

        useEffect(() => {
            for (const item of transactions) {
                if (!item.category) {
                    // If the expense had his category cleared due to unsaved changes (i.e. changing to recipient to one that does not have category)
                    // then we should reset the category to it's last saved value
                    const existingCategory = existingTransaction?.category ?? defaultCategory;
                    if (existingCategory) {
                        const isExistingCategoryEnabled = policyCategories?.[existingCategory]?.enabled;
                        if (isExistingCategoryEnabled) {
                            setMoneyRequestCategory(item.transactionID, existingCategory, policy);
                        }
                    }
                    continue;
                }
            }
            // We don't want to clear out category every time the transactions change
            // eslint-disable-next-line react-hooks/exhaustive-deps
        }, [policy?.id, policyCategories, transactionsCategories]);
    
    
    

    (adding ?? defaultCategory).

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  4. added
    InternalRequires API changes or must be handled by Expensify staff
    on Jan 14, 2026
  5. Julesssss commented on Jan 14, 2026

    @Julesssss
    ContributorAuthor

    FYI @Eskalifer1 this was not opened for external contributors. I created it for @DylanDylann to implement based on a bug he found in the linked PR. I'll leave it up to him whether he want's to implement or switch to C+ reviewer though.

  6. Eskalifer1 commented on Jan 14, 2026

    @Eskalifer1
    Contributor

    Hi @Julesssss Oh, I see, it seems that this bug is already in production and does not actually relate to Odometr's functionality. But i'm totally okay with that!

  7. melvin-bot commented on Jan 17, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  8. melvin-bot commented on Jan 19, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  9. 5 remaining items

  10. melvin-bot commented on Jan 20, 2026

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  11. melvin-bot commented on Jan 20, 2026

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.3.4-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-01-27. 🎊

    For reference, here are some details about the assignees on this issue:

    • @DylanDylann requires payment through NewDot Manual Requests
  12. melvin-bot commented on Jan 27, 2026

    @melvin-bot

    Issue is ready for payment but no BZ is assigned. @heyjennahay you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

  13. heyjennahay commented on Jan 28, 2026

    @heyjennahay
    Contributor

    Hi @DylanDylann just checking, is a BugZero checklist needed for this issue?

  14. DylanDylann commented on Jan 29, 2026

    @DylanDylann
    Contributor

    Regression Test Proposal

    1. Create odometer via FAB button
    2. In the confirmation page
    3. Change the participant
    4. Verify that the category isn't removed
  15. heyjennahay commented on Feb 3, 2026

    @heyjennahay
    Contributor
  16. Julesssss commented on Feb 3, 2026

    @Julesssss
    ContributorAuthor

    Payment to be grouped under the Odometer project

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2InternalRequires API changes or must be handled by Expensify staff

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions