Skip to content

[Refactor] Split IOURequestStepConfirmation, MoneyRequestConfirmationList, and useExpenseSubmission per expense type #99449

Open
2 of 2 issues completed

Description

@melvin-bot

Background

The confirmation step is implemented as one component, IOURequestStepConfirmation (~1050 lines), rendering one list component, MoneyRequestConfirmationList (693 lines), and submitting through one hook, useExpenseSubmission (1229 lines).

These three units serve nine expense types (manual, scan, per-diem, time, and five distance variants) across six flows (submit, track, split, invoice, pay, and the new-manual-expense-flow beta). Type- and flow-specific behavior is selected at runtime through boolean flags: the list component alone carries 55 type/flow conditionals (isPerDiemRequest, isOdometerDistanceRequest, isTypeInvoice, …), and the page passes those flags down through props.

The useExpenseSubmission hook subscribes to ~29 Onyx keys to feed seven distinct API submit paths (RequestMoney, TrackExpense, CreateDistanceRequest, CreatePerDiemRequest, three split commands, SendInvoice, SendMoney), of which any given submission uses exactly one. In total a confirmation mount establishes ~65 Onyx subscriptions and runs the effects of every expense type, including hooks for types not in use.

Problem

When different expense types share one confirmation component, one list, and one submission hook wired together by boolean flags, opening the confirmation screen for any expense pays the subscriptions and effects of all nine types on the final step of every submission. The same sharing means any change to one type's confirmation behavior executes inside every other type's flow — regressing unrelated submissions and making every change slower and riskier to review.

Plan (bottom-up)

Following review feedback, we'll start at the leaves and work up the tree, so each step is an improvement on its own and lower-level components are decomposed before the pages that compose them:

  1. Fork MoneyRequestConfirmationListFooter per type — InvoiceFooter, ScanFooter, etc. (it already has some sections decomposed). MoneyRequestConfirmationListFooter.tsx stays as a dispatcher for now.
  2. Split MoneyRequestConfirmationList (already decomposed into sections/controllers), reusing the per-flow footers created in step 1.
  3. Split useExpenseSubmission.ts into a shared core plus one hook per API path, each owning only the Onyx subscriptions its call reads.
  4. Fork IOURequestStepConfirmation.tsx into an index.tsx dispatcher plus per-type variants, composing the forks and submission hooks from the previous steps.

Each fork may not be fully decomposed initially, but every step is a net improvement over what we have today. A POC of one flow fork will be shared first to validate the approach. Reviews welcome from @roryabraham given his decomposition context.

Reported in Slack.

Issue OwnerCurrent Issue Owner: @situchan

Activity

  1. VickyStash commented on Aug 26, 2026

    @VickyStash
    Contributor

    Update:
    I've started my work on turning MoneyRequestConfirmationListFooter into a dispatcher with per-type forks:

    • Turned MoneyRequestConfirmationListFooter into a dispatcher
    • Extracted first footer (PerDiemFooter), the rest is stored in Default as if now, and it will be cut off as new footers are extracted.
    • Right now, working on moving type-specific fields data out of ConfirmationFieldList, mostly relatest to TransactionDetailsFields block (it has condition rendering of AmountField, DistanceField, TimeFields)

    WIP updates can be found in #99578

  2. VickyStash commented on Aug 27, 2026

    @VickyStash
    Contributor

    Updates:

    • Updated TransactionDetailsFields to be type-specific
    • Run AI reviewers and working on the feedback
    • Made clean up
    • Moved ConfirmationFieldsProvider up (have one test failing which I need to check)

    So PR 1 will have:

    • MoneyRequestConfirmationListFooter forking setup
    • Extracted PerDiemFooter and TimeFooter

    This way it's easier to evaluate the structure before we move forward with other footers.

    TODOs for PR 1:

    • Check jest test
    • Polish the code
    • Testing and PR preparation for review

    PR draft: #99578

  3. VickyStash commented on Aug 27, 2026

    @VickyStash
    Contributor

    Also, here the high level of new structure:

    High level new structure description

    Layer 1

    Footer Owns
    PerDiemFooter per-diem subrate fields. No receipt, no compact mode, no distance
    TimeFooter hours/rate fields
    DistanceMapFooter route map + Distance/Rate. Covers distance, distance-map, distance-gps
    DistanceManualFooter Distance/Rate, no map
    DistanceOdometerFooter Distance/Rate, no map, odometer stitch error
    ScanFooter compact mode + show-more
    ManualFooter baseline

    Layer 2

    Each list variant renders exactly one footer variant, and mounts only the controllers its expense type needs.

    List variant Footer Mounts Skips
    PerDiemConfirmationList PerDiemFooter — distance controller + state, tax controller + useTaxAmount, commuter guard
    TimeConfirmationList TimeFooter — same
    DistanceMapConfirmationList DistanceMapFooter useDistanceRequestState + DistanceRequestController, TaxController commuter guard, receipt training
    DistanceManualConfirmationList DistanceManualFooter same + useCommuterExclusionGuard receipt training
    DistanceOdometerConfirmationList DistanceOdometerFooter same + odometer stitcher receipt training
    ScanConfirmationList ScanFooter useReceiptTraining, TaxController distance controller + state, commuter guard
    ManualConfirmationList ManualFooter TaxController, FieldAutoSelector distance controller + state, commuter guard, receipt training

    Layer 3

    Page variants are keyed on the submission path, not on iouType. One variant per API command, so each composes exactly one submission hook by construction.

    Page variant Path Hook Types it can reach Switches on type?
    DistanceConfirmation CreateDistanceRequest useDistanceSubmission DistanceMap, DistanceManual, DistanceOdometer yes (3)
    SplitConfirmation the three split commands useSplitSubmission Manual, Scan yes (2)
    InvoiceConfirmation SendInvoice useInvoiceSubmission Manual no
    TrackConfirmation TrackExpense useTrackExpenseSubmission Manual, Scan, Distance×3 yes (5)
    PerDiemConfirmation CreatePerDiemExpense usePerDiemSubmission PerDiem no
    RequestMoneyConfirmation RequestMoney useRequestMoneySubmission Manual, Scan, Time, and the residual edges yes
    PayConfirmation SendMoney useSendMoneySubmission Manual no

    Page examples:

    // variants/PerDiemConfirmation.tsx
    
    function PerDiemConfirmation({transaction, report, policy, action, iouType, participants, ...}) {
        const {createTransaction, isConfirmed, formHasBeenSubmitted} = usePerDiemSubmission({...});
      
      ....
    
        return (
            <>
                <PerDiemConfirmationList
                    transaction={transaction}
                    policy={policy}
                    action={action}
                    iouType={iouType}
                    participants={participants}
                    visibility={{shouldShowCategories, ...}}
                    onConfirm={handleConfirm}
                />
                <SubmitExpenseOrchestrator createTransaction={createTransaction} ... />
            </>
        );
    }
    // variants/TrackConfirmation.tsx
    
    function TrackConfirmation({transaction, report, policy, action, iouType, participants, ...}) {
        const {createTransaction, isConfirmed, formHasBeenSubmitted} = useTrackExpenseSubmission({...});
         ...
        const renderList = () => {
            switch (resolveConfirmationVariant(transaction, action)) {
                case 'scan':             return <ScanConfirmationList {...} />;
                case 'perDiem':          return <PerDiemConfirmationList {...} />;
                case 'distanceMap':      return <DistanceMapConfirmationList {...} />;
                case 'distanceManual':   return <DistanceManualConfirmationList {...} />;
                case 'distanceOdometer': return <DistanceOdometerConfirmationList {...} />;
                default:                 return <ManualConfirmationList {...} />;
            }
        };
    
        return (
            <>
                <DraftWorkspaceOpener isCreatingTrackExpense={isCreatingTrackExpense} ... />
                <ExpenseDefaultsSetter isCreatingTrackExpense={isCreatingTrackExpense} ... />
                {renderList()}
                <SubmitExpenseOrchestrator createTransaction={createTransaction} ... />
            </>
        );
    }
  4. VickyStash commented on Aug 28, 2026

    @VickyStash
    Contributor

    First PR is open for review: #99578

  5. VickyStash commented on Aug 31, 2026

    @VickyStash
    Contributor

    UPD:

  6. 105 remaining items

  7. added and removed
    ReviewingHas a PR in review
    on Nov 9, 2026
  8. melvin-bot commented on Nov 9, 2026

    @melvin-bot
    Author

    @situchan

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

  9. situchan commented on Nov 11, 2026

    @situchan
    Contributor

    Not overdue

  10. VickyStash commented on Nov 12, 2026

    @VickyStash
    Contributor

    The last PR here was deployed to prod 2 days ago, I think we can move forward here after the 7-day regression period

  11. situchan commented on Nov 17, 2026

    @situchan
    Contributor

    @VickyStash this project is done right?

  12. VickyStash commented on Nov 17, 2026

    @VickyStash
    Contributor

    @situchan Yes, I think so

  13. situchan commented on Nov 17, 2026

    @situchan
    Contributor

    @MelvinBot list all PRs linked to this issue

  14. removed
    Skip PaymentSkips all the payment process steps for an issue. Use it for fixed-price projects.
    on Nov 17, 2026
  15. situchan commented on Nov 17, 2026

    @situchan
    Contributor
    1. Split the confirmation footer into a dispatcher and per-type variants pt1 #99578
    2. Split the confirmation footer by variants pt2 #100041
    3. Split MoneyRequestConfirmationList #101198 (x1.5) - 39 commits, 37 files, +1,757/-1,219
    4. Split useExpenseSubmission hook #101746 (x2) - 22 commits, 23 files, +2,627/-1,277
    5. MoneyRequestConfirmationList follow-up: stabilize controller props, dedupe variant shell, single-path context #102405
    6. Restructure IOURequestStepConfirmation ahead of the per-path split #103720
    7. Split IOURequestStepConfirmation per submission path #104343 (x1.5) - 28 commits, 30 files, +746/-2,214
    8. [No QA] Add unit tests for useExpenseSubmission submission utils #103438 (x0.5)
    9. [No QA] Add tests for the per-path expense submission hooks #106128 (x0.5)

    Why the work exceeded the issue:
    The PRs rework the confirmation step that every expense submission runs through.
    For each PR (except unit tests), I ran a full regression pass across every submission path.

    Regressions caused by this PR: None. The blockers linked to this issue (#102484, #103271, #103352) were caused by #101301 and #102258 (not our PRs).

    Core flow changes: Expense confirmation and submission for manual, scan, per diem, time and distance expenses, across submit, track, split, invoice and pay

    Total: $250 (I was assigned on Aug 31) x 10 = $2500

    cc: @mountiny

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

Metadata

Metadata

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions