Skip to content

Reverse step order in Add Contact Method flow#77429

Merged
carlosmiceli merged 27 commits intoExpensify:mainfrom
cretadn22:reserver-the-order-new-contact-method
Jan 10, 2026
Merged

Reverse step order in Add Contact Method flow#77429
carlosmiceli merged 27 commits intoExpensify:mainfrom
cretadn22:reserver-the-order-new-contact-method

Conversation

@cretadn22
Copy link
Contributor

@cretadn22 cretadn22 commented Dec 11, 2025

Explanation of Change

Fixed Issues

$ #60577
PROPOSAL: #60577 (comment)

Tests

  1. Navigate to Settings
  2. Click Contact method
  3. Click New Contact method
  4. Ask to verify the old email address
  5. Enter a new email address
  6. Verify new email address
  7. The flow should be validating the old email address (Step 4) and then validating the new email address (Step 6)
  • Verify that no errors appear in the JS console

Offline tests

  1. Navigate to Settings
  2. Click Contact method
  3. Click New Contact method
  4. Ask to verify the old email address
  5. Enter a new email address
  6. Verify new email address
  7. The flow should be validating the old email address (Step 4) and then validating the new email address (Step 6)

QA Steps

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

  1. Navigate to Settings
  2. Click Contact method
  3. Click New Contact method
  4. Ask to verify the old email address
  5. Enter a new email address
  6. Verify new email address
  7. The flow should be validating the old email address (Step 4) and then validating the new email address (Step 6)
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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

Android: Native
pixel-9a.mp4
Android: mWeb Chrome
mobile.mp4
iOS: Native
Simulator.Screen.Recording.-.iPhone.16e.-.2025-12-14.at.23.33.58.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.16e.-.2025-12-14.at.20.33.44.mp4
MacOS: Chrome / Safari
Screen.Recording.2025-12-14.at.19.50.19.mp4

@cretadn22 cretadn22 requested review from a team as code owners December 11, 2025 18:24
@melvin-bot melvin-bot bot requested review from heyjennahay and suneox and removed request for a team December 11, 2025 18:24
@melvin-bot
Copy link

melvin-bot bot commented Dec 11, 2025

@suneox 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 the request for review from a team December 11, 2025 18:24
@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/API/types.ts 100.00% <ø> (ø)
...s/settings/Profile/Contacts/ContactMethodsPage.tsx 80.95% <ø> (ø)
src/components/Form/FormProvider.tsx 58.33% <50.00%> (-0.09%) ⬇️
...ings/Profile/Contacts/ContactMethodDetailsPage.tsx 54.81% <0.00%> (ø)
src/ROUTES.ts 12.65% <0.00%> (-0.04%) ⬇️
.../Contacts/NewContactMethodConfirmMagicCodePage.tsx 0.00% <0.00%> (ø)
src/libs/actions/User.ts 25.76% <80.95%> (+2.41%) ⬆️
...settings/Profile/Contacts/NewContactMethodPage.tsx 0.00% <0.00%> (ø)
... and 27 files with indirect coverage changes

@cretadn22
Copy link
Contributor Author

@suneox I’ve just pushed a few updates to complete the PR.

@suneox
Copy link
Contributor

suneox commented Dec 15, 2025

@suneox I’ve just pushed a few updates to complete the PR.

Thank for update I'll take a look at this one today

@suneox
Copy link
Contributor

suneox commented Dec 15, 2025

@cretadn22 We have an issue after verifying the magic code on the primary account, the user dismiss the input new email contact method flow and starts over. Even though the magic code verification page is skipped, the ResendValidateCode API is still being called. Please take a look at 1:00–1:25.

Expected result: the ResendValidateCode API should not be called

CleanShot.2025-12-15.at.23.07.10.mp4

@suneox
Copy link
Contributor

suneox commented Dec 15, 2025

From the video at 1:40–2:05:

Expected result

When entering an invalid contact method, an error should be displayed on the input page.

Actual result

No error is shown on the input form, and the user can add multiple emails with the same error to Contact Methods.

@carlosmiceli Please let me know if the expected result is correct.

cc: @heyjennahay @cretadn22

@carlosmiceli
Copy link
Contributor

Hey @fedirjh, would you be able to look at the issue mentioned by @suneox above? Seems related to the BE changes we worked on last time.

@cretadn22
Copy link
Contributor Author

@fedirjh For this bug (#77429 (comment)), the API error should be stored in formState?.errors (in this form it's newContactMethodForm)

@fedirjh
Copy link
Contributor

fedirjh commented Dec 16, 2025

the API error should be stored in formState?.errors (in this form it's newContactMethodForm)

@suneox @cretadn22 I think this is a FE issue, we should show the error message and block navigation if any errors occur.

@cretadn22
Copy link
Contributor Author

cretadn22 commented Dec 17, 2025

@suneox @fedirjh Normally, server-side errors in a form should be stored in the form field so that the FormProvider can detect them and display them according to the intended design (we don't need to handle server error manually).

const hasServerError = useMemo(() => !!formState && !isEmptyObject(formState?.errors), [formState]);

In this case, however, the server error is being saved in a different location by Backend, which prevents it from being shown correctly.

I can address this on the FE side by adding an effect to copy the server error to the appropriate place, but this would essentially be a workaround rather than a root fix. Do you agree with proceeding with this approach?

   const loginData = pendingContactAction?.contactMethod ? loginList?.[pendingContactAction?.contactMethod] : undefined;
    const validateLoginError = getLatestErrorField(loginData, 'addedLogin')
    useEffect(() => {
        setErrorsOn(validateLoginError)
    }, [validateLoginError])



function setErrorsOn(errors) {
    Onyx.set(ONYXKEYS.FORMS.NEW_CONTACT_METHOD_FORM, {
        errors
    })
}

@suneox
Copy link
Contributor

suneox commented Dec 17, 2025

@cretadn22 Could you try to capture the error at 2:14–2:17, since it is already being returned from the backend?

CleanShot 2025-12-17 at 19 25 24@2x

@cretadn22
Copy link
Contributor Author

@suneox yes, the server error is saved in Onyx. I only try to display it

@cretadn22
Copy link
Contributor Author

Issue 1: There is no action or error shown when the magic code expires.

For this issue, I think we should navigate back to NewContactMethodConfirmMagicCodePage instead of showing the error message on NewContactMethodPage. What do you think?

@suneox
Copy link
Contributor

suneox commented Dec 30, 2025

@carlosmiceli We’re currently stuck on an unconsidered edge case and need confirmation on the expected behavior for issue 1: how should we handle an expired magic code?

Option 1:
Should we skip the logic that preserves the verified primary account state?
Currently, once the magic code is verified on the primary account, adding a new contact method skips directly to the “New contact method” step. However, the magic code verification response does not include expiration information.
(Skipping this step would mean the primary account is always re-verified whenever the user performs the “New contact method” action)

Option 2:
If an error occurs at the “Add contact method” step, should we automatically reset the flow and return the user to the beginning?

For Issue 2:
Is the current expected behavior still correct? We can clear the “add contact method” error state after the modal is dismissed.

cc: @fedirjh @cretadn22

@carlosmiceli
Copy link
Contributor

For issue 1, I think resetting the flow is easiest and less prone to more bugs.

For issue 2, don't we reset the modal to the beginning of the flow if we close the modal anyway? I think it's ok not to keep the modal state if it's closed in this flow.

@cretadn22
Copy link
Contributor Author

@suneox With that in mind, issue 2 looks fine as expectation. For issue 1, we will need to reset the flow to NewContactMethodConfirmMagicCodePage when the backend returns a “magic code expired” error without displaying an error message.

@suneox
Copy link
Contributor

suneox commented Jan 2, 2026

For issue 1, we will need to reset the flow to NewContactMethodConfirmMagicCodePage when the backend returns a “magic code expired” error without displaying an error message.

@carlosalmonte04 Regarding issue 1, since we don't have reliable information indicating whether the current account validation has expired, what do you think about applying both option 1 and option 2?
On the ContactMethodsPage, we would navigate to validate the current account every time the user clicks “New contact method,” without checking whether the account was previously validated. Then, at step 2 add new contact method if we receive a magic code expired error for current account, we would reset the flow as well.

cc: @cretadn22 @fedirjh

@cretadn22
Copy link
Contributor Author

cc @carlosmiceli for above solution ☝️

@carlosmiceli
Copy link
Contributor

@suneox @cretadn22 that seems to cover all cases, right? Sure, let's combine the solutions.

@cretadn22
Copy link
Contributor Author

cretadn22 commented Jan 6, 2026

If an error occurs at the “Add contact method” step, should we automatically reset the flow and return the user to the beginning?

@suneox @carlosmiceli I just want to double confirm this point. The “Add contact method” flow can fail for multiple reasons, not only because the validation code has expired. Do we want to reset the flow for any error, or only for expired code case?

If the intent is to reset the flow only when the validation code is expired, we may need a workaround to reliably detect that scenario from the BE response.

Screenshot 2026-01-06 at 17 58 38

Option 3: Otherwise, what do you think about applying only option 1? And If we require a validation code every time the user starts the flow, the “expired code” case should be much less likely to occur. If it happens we will display the error message in that page (similar to other server error).

Screenshot 2026-01-06 at 18 09 30

@suneox
Copy link
Contributor

suneox commented Jan 6, 2026

Keeping option 1 and showing an error in this case looks good to me

…t into NewContactMethodPage for error handling
…avigation logic in NewContactMethodConfirmMagicCodePage
@cretadn22
Copy link
Contributor Author

@suneox Could you please take another look and review this PR? Thank you

@melvin-bot melvin-bot bot requested a review from carlosmiceli January 10, 2026 12:26
@carlosmiceli carlosmiceli merged commit 2272d8d into Expensify:main Jan 10, 2026
31 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.3.0-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 9.3.0-8 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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