Skip to content

Refactor Account settings menu data into a shared hook - #96870

Open
nabi-ebrahimi wants to merge 7 commits into
Expensify:mainfrom
nabi-ebrahimi:92752-shared-account-menu-source
Open

Refactor Account settings menu data into a shared hook#96870
nabi-ebrahimi wants to merge 7 commits into
Expensify:mainfrom
nabi-ebrahimi:92752-shared-account-menu-source

Conversation

@nabi-ebrahimi

@nabi-ebrahimi nabi-ebrahimi commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Extracts the existing Account and General Settings menu definitions from InitialSettingsPage into a shared useInitialSettingsPageMenuData hook.

InitialSettingsPage now consumes this shared source while continuing to own rendering, styles, focus handling, scrolling, account-switch cleanup, and page initialization.

This is a behavior-preserving prerequisite for adding Account navigation suggestions in a follow-up PR. It does not add Account destinations to Search Router.

Fixed Issues

$ #92752
PROPOSAL: #92752 (comment)

Tests

  1. Account menu order and navigation

    1. Open Account settings.
    2. Verify the visible Account rows remain in this relative order:
      Profile, optional Subscription, Wallet, Expense rules, optional Agents, Preferences, Copilot, Security.
    3. Open each visible Account row and return to Account settings.
    4. Expected: Each row remains in the correct position with its existing icon, badge, and indicator, and opens the correct settings page.
  2. General menu order and actions

    1. Open Account settings and scroll to the General section.
    2. Verify the visible rows remain in their existing order:
      optional Go to Expensify Classic, Help, What's new, About, Troubleshoot, Save the world, and Sign out.
    3. Open each non-sign-out row and return to Account settings.
    4. Expected: Each row performs its existing action, and What's new opens the existing external page.
  3. Sign-out action

    1. Open Account settings.
    2. Select Sign out.
    3. Complete the existing confirmation flow if it appears.
    4. Expected: The existing sign-out behavior works correctly without an error.
  4. Settings layout

    1. Open Account settings.
    2. Scroll through the Account and General sections.
    3. Expected: Section spacing, row styling, focused-row state, header, and scrolling remain unchanged.
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests.

QA Steps

Same as Tests.

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 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 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)
  • 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)
  • 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.
  • 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

Android: Native
Screen_Recording_20260724_095514_New.Expensify.Dev.mp4
Android: mWeb Chrome
Screen_Recording_20260724_094125_Chrome.mp4
iOS: Native
Screen.Recording.2026-07-24.at.10.32.35.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-07-24.at.10.35.28.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-24.at.9.15.42.AM.mov
Screen.Recording.2026-07-24.at.9.17.21.AM.mov
Screen.Recording.2026-07-24.at.9.21.08.AM.mov
Screen.Recording.2026-07-24.at.9.22.36.AM.mov
Screen.Recording.2026-07-24.at.9.36.11.AM.mov
Screen.Recording.2026-07-24.at.9.33.49.AM.mp4

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/pages/settings/InitialSettingsPage.tsx 97.82% <100.00%> (+10.51%) ⬆️
src/pages/settings/SettingsMenuItem.tsx 57.14% <ø> (ø)
...c/pages/settings/useInitialSettingsPageMenuData.ts 83.67% <83.67%> (ø)
... and 9 files with indirect coverage changes

@nabi-ebrahimi
nabi-ebrahimi force-pushed the 92752-shared-account-menu-source branch from 4101db0 to 085d77e Compare July 27, 2026 07:35
@nabi-ebrahimi
nabi-ebrahimi marked this pull request as ready for review July 27, 2026 09:06
@nabi-ebrahimi
nabi-ebrahimi requested review from a team as code owners July 27, 2026 09:06
@melvin-bot

melvin-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

@marufsharifi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed request for a team July 27, 2026 09:06
@joekaufmanexpensify

Copy link
Copy Markdown
Contributor

No product review needed

@joekaufmanexpensify
joekaufmanexpensify removed their request for review July 27, 2026 19:53
@trjExpensify

Copy link
Copy Markdown
Contributor

@marufsharifi this is waiting on you to be reviewed, right? (CC: @carlosmiceli)

@marufsharifi

Copy link
Copy Markdown
Contributor

@trjExpensify, yep—I’ll prioritize this today. Thanks!

@trjExpensify

Copy link
Copy Markdown
Contributor

Thank you 👍

Comment thread src/pages/settings/useInitialSettingsPageMenuData.ts
Comment thread src/pages/settings/useInitialSettingsPageMenuData.ts Outdated
@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Review: LGTM — clean, behavior-preserving extraction. No blocking issues found.

The menu-building logic (Onyx reads, brick-road indicators, sign-out, classic-redirect, account/general items) moves cleanly into useInitialSettingsPageMenuData.ts, and InitialSettingsPage keeps rendering, focus, scrolling, and the status emoji. The added ordering assertions in the test are a nice behavior-lock for a refactor like this.

Verification performed
  • tsc --noEmit: clean for the three changed files.
  • eslint on the changed files: clean.
  • Confirmed no dangling imports/vars left in InitialSettingsPagetranslate, Navigation, ROUTES, StyleProp/ViewStyle are all still used.
  • MenuData type export moved to the hook; the only external importer, SettingsMenuItem.tsx:11, was updated. No other file imports the type from InitialSettingsPage.
  • CI: all checks green except the PR Reviewer Checklist chore (not a code issue).

Equivalences I checked (all preserve behavior):

  • Icon split — only Emoji stays in the page (used by the status button); the rest move to the hook where the menu icons are consumed. ✅
  • amountOwed > 0 vs old (amountOwed ?? 0) > 0 — equivalent, since amountOwed defaults to 0 from the Onyx read.
  • sectionStyle dropped from the type and passed as an argument to getMenuItemsSection instead; styles.pt4 passed directly vs the old {...styles.pt4} spread is functionally identical.
  • Dropping as const on the security translationKey is fine — the field is typed TranslationPaths and typecheck passes.

Optional (non-blocking): the hook rebuilds accountMenuItemsData / generalMenuItemsData on every render. That's identical to the pre-refactor behavior (they were computed inline each render), so it's not a regression — just flagging it since the follow-up PR will consume this hook from Search Router too, where memoizing the returned objects may be worth it.

@marufsharifi

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi, could you please take a look at the above comments. thanks.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

🤖 Review: LGTM — clean, behavior-preserving extraction. No blocking issues found.

The menu-building logic (Onyx reads, brick-road indicators, sign-out, classic-redirect, account/general items) moves cleanly into useInitialSettingsPageMenuData.ts, and InitialSettingsPage keeps rendering, focus, scrolling, and the status emoji. The added ordering assertions in the test are a nice behavior-lock for a refactor like this.

Verification performed
Optional (non-blocking): the hook rebuilds accountMenuItemsData / generalMenuItemsData on every render. That's identical to the pre-refactor behavior (they were computed inline each render), so it's not a regression — just flagging it since the follow-up PR will consume this hook from Search Router too, where memoizing the returned objects may be worth it.

Thanks for the review. The optional memoization is unchanged from the previous behavior, and both React compilers pass, so I’ll keep this PR focused on the extraction.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@marufsharifi conflicts are resolved and all review comments have been addressed. Please take another look when you have a chance. Thanks!

@marufsharifi marufsharifi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewing

Comment thread src/pages/settings/useInitialSettingsPageMenuData.ts Outdated
Comment thread src/pages/settings/useInitialSettingsPageMenuData.ts Outdated
Comment thread src/pages/settings/InitialSettingsPage.tsx Outdated
@marufsharifi

Copy link
Copy Markdown
Contributor

@MelvinBot Review

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Re-review: LGTM — still a clean, behavior-preserving extraction after the main merge. No blocking issues.

I re-verified the current head (144fd04) since conflicts were resolved. The menu-building logic (Onyx reads, brick-road indicators, sign-out, classic-redirect, account/general items) lives in useInitialSettingsPageMenuData.ts, and InitialSettingsPage just consumes accountMenuItemsData/generalMenuItemsData and owns rendering, focus, scrolling, and account-switch cleanup.

Verification performed
  • Typecheck (tsgo -p tsconfig.json): exit 0, zero errors project-wide — no errors referencing any of the four changed files.
  • ESLint on the four changed files: 0 errors. Only 2 pre-existing eslint-seatbelt warnings (no-unsafe-type-assertion) in the test file — allowed, not introduced as errors.
  • CI: all checks green except the PR Reviewer Checklist / checklist chore (not a code issue).
  • Menu order preserved: accountItems is Profile → Wallet → Expense rules → Preferences → Copilot → Security, with Agents spliced after Rules and Subscription spliced at index 1 — matching the new full-order assertion in InitialSettingsPageTest.tsx:208.
  • Type export moved to the hook; its only external importer, SettingsMenuItem.tsx:11, was updated.
  • Sign-out flow (offline confirm modal + GPS trip cleanup + recursive force-signout) and the classicRedirect / nudge-migration gating carried over unchanged into the hook.

The added full-order test is a nice behavior-lock for a refactor like this. Nothing else to flag.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@marufsharifi thanks for the review. All comments have been addressed. Please take another look when you have a chance.

@marufsharifi

Copy link
Copy Markdown
Contributor

@nabi-ebrahimi, could you please merge the main. thanks.

@nabi-ebrahimi

Copy link
Copy Markdown
Contributor Author

@nabi-ebrahimi, could you please merge the main. thanks.

Merged the main, thanks

@marufsharifi

marufsharifi commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • 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 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)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-08-04.at.4.08.48.PM.mov
Android: mWeb Chrome
Screen_Recording_20260804_161314_Chrome.mp4
iOS: HybridApp
Screen.Recording.2026-08-04.at.4.53.07.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-08-04.at.4.16.20.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-04.at.11.59.53.AM.mov
Screen.Recording.2026-08-04.at.11.57.03.AM.mov
Screen.Recording.2026-08-04.at.11.59.02.AM.mov

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants