Skip to content

[HOLD for payment 2023-10-16] [HOLD for payment 2023-10-10] [$500] Web - City field is not clear when select another country #28007

Closed

Description

@kbecciv

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Go to home address page
  2. Select another country (Make sure the all fields is typed before)

Expected Result:

City field should be clear when select another country

Actual Result:

City field is not clear when select another country

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.72.8
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Screen.Recording.2023-09-20.at.15.04.01.mov
Recording.4674.mp4

Expensify/Expensify Issue URL:
Issue reported by: @DylanDylann
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1695197139968609

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e5128ed81517974f
  • Upwork Job ID: 1705190854472331264
  • Last Price Increase: 2023-09-22
  • Automatic offers:
    • Ollyws | Reviewer | 26911820
    • DylanDylann | Contributor | 26911821
    • DylanDylann | Reporter | 26911824

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 22, 2023
  2. changed the title [-]Web - City field is not clear when select another country[/-] [+][$500] Web - City field is not clear when select another country[/+] on Sep 22, 2023
  3. melvin-bot commented on Sep 22, 2023

    @melvin-bot
  4. melvin-bot commented on Sep 22, 2023

    @melvin-bot

    Triggered auto assignment to @michaelhaxhiu (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Sep 22, 2023
  6. melvin-bot commented on Sep 22, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅). Is this a valid bug?
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Sep 22, 2023

    @melvin-bot

    Triggered auto assignment to @zanyrenney (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

  8. melvin-bot commented on Sep 22, 2023

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (External)

  9. kbecciv commented on Sep 22, 2023

    @kbecciv
    Author

    Proposal by: @DylanDylann
    Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1695197139968609

    Proposal

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

    City field is not clear when select another country

    What is the root cause of that problem?

    We only use useState for country and state fields because we need to re-set 2 fields when changing country

    const handleAddressChange = (value, key) => {
    if (key !== 'country' && key !== 'state') {
    return;
    }
    if (key === 'country') {
    setCurrentCountry(value);
    setState('');
    return;
    }
    setState(value);
    };

    I think the city field also should be clear after changing country like state field.

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

    Firstly, we need to use useState for city field

    const [city, setCity] = useState(address.city);
    

    When country change we need to re-set city to empty like this

    const handleAddressChange = (value, key) => {
            if (key !== ‘country’ && key !== ‘state’ && key !== ‘city’) {          // UPDATE HERE
                return;
            }
            if (key === ‘country’) {
                setCurrentCountry(value);
                setState(‘’);
                setCity(‘’);         // UPDATE HERE
                return;
            }
            setState(value);
            setCity(value);
        };
    

    and then in here

    defaultValue={address.city || ''}

    we should use value instead of default value

    value={city || ‘’}
    
  10. abzokhattab commented on Sep 22, 2023

    @abzokhattab
    Contributor

    Proposal

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

    City field isn't clear when selecting another country

    What is the root cause of that problem?

    The city is not cleared on changing the country which is handled in handleAddressChange

    const handleAddressChange = (value, key) => {
    if (key !== 'country' && key !== 'state') {
    return;
    }
    if (key === 'country') {
    setCurrentCountry(value);
    setState('');
    return;
    }
    setState(value);
    };

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

    add another state for the city and also the zip code as it make sense to clear the zip code as well on changing the country

        const [city, setCity] = useState(address.city);
        const [zipCode, setZipCode] = useState(address.zip);
        const handleAddressChange = (value, key) => {
            switch (key) {
                case 'country':
                    setCurrentCountry(value);
                    setState('');
                    setCity('');
                    setZipCode('');
                    break;
                case 'state':
                    setState(value);
                    break;
                case 'city':
                    setCity(value);
                    break;
                case 'zipPostCode':
                    setZipCode(value);
                    break;
                default:
                    break;
            }
        };

    and also change the defaultValue property to value and add onChange handle for both the city and the zipcode components:

    defaultValue={address.city || ''}

    to

    value={city || ''}
    onValueChange={handleAddressChange}

    With this change we have to consider two points

    1. Change in Address Line 1 Behavior: Currently, when changing the address line 1 to an address in the USA, for example, the postcode, city, and state fields are cleared. This behavior is due to the onValueChange handler in the addressline component, where the order in which the values are processed here:
      const values = {
      street: `${streetNumber} ${streetName}`.trim(),
      // Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise.
      street2: subpremise,
      // When locality is not returned, many countries return the city as postalTown (e.g. 5 New Street
      // Square, London), otherwise as sublocality (e.g. 384 Court Street Brooklyn). If postalTown is
      // returned, the sublocality will be a city subdivision so shouldn't take precedence (e.g.
      // Salagatan, Upssala, Sweden).
      city: locality || postalTown || sublocality || cityAutocompleteFallback,
      zipCode,
      country: '',
      state: state || stateAutoCompleteFallback,
      lat: lodashGet(details, 'geometry.location.lat', 0),
      lng: lodashGet(details, 'geometry.location.lng', 0),
      address: lodashGet(details, 'formatted_address', ''),
      };
      . The city and zip code fields are processed before the country field. Consequently, when the country is changed, it triggers the setCity and setZipCodeas well, setting them to empty strings.

      To address this issue, two possible solutions can be considered:

      a. Reorder the values list so that the country is on top of the values object, followed by the other fields. This change would prevent the city and zip code from being overridden with empty values.

      b. OR Create a custom handler for changing the address line 1, separate from the general address change handler. This custom handler would update only the country field, ensuring that changing the country does not affect the city and zip code.
        const handleAddressLineChange = (value, key) => {
            switch (key) {
                case 'country':
                    setCurrentCountry(value);
                    break;
                case 'state':
                    setState(value);
                    break;
                case 'city':
                    setCity(value);
                    break;
                case 'zipPostCode':
                    setZipCode(value);
                    break;
                default:
                    break;
            }
        };

    And change the onValueChange handler for the AddressSearch component of the addressLine1

    onValueChange={handleAddressChange}
    1. Also we must consider chaining these new states with the useEffect mentioned in this issue so that the initial value is always correct: [HOLD for payment 2023-10-10] [$500] Web - Country and State fields are empty if accessed via deep link #27814 (comment)
        useEffect(() => {
          setState(address.state)
          setCity(address.city);
          setZipCode(address.zip);
          setCurrentCountry(address.country)
        }, [address]);

    again it's your choice to add a state for the zip code as well or not .. but it would be useful to reset the zip code as well in case you change the country

    POC

    Screen.Recording.2023-09-23.at.3.56.44.AM.mov
  11. 58 remaining items

  12. melvin-bot commented on Oct 9, 2023

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.79-5 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 2023-10-16. 🎊

    After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

    • External issue reporter
    • Contributor that fixed the issue
    • Contributor+ that helped on the issue and/or PR

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

    As a reminder, here are the bonuses/penalties that should be applied for any External issue:

    • Merged PR within 3 business days of assignment - 50% bonus
    • Merged PR more than 9 business days after assignment - 50% penalty
  13. melvin-bot commented on Oct 9, 2023

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@Ollyws] The PR that introduced the bug has been identified. Link to the PR:
    • [@Ollyws] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@Ollyws] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@Ollyws] Determine if we should create a regression test for this bug.
    • [@Ollyws] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@zanyrenney] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  14. zanyrenney commented on Oct 12, 2023

    @zanyrenney
    Contributor

    4 more days before we can pay this out!

  15. melvin-bot commented on Oct 16, 2023

    @melvin-bot

    @AndrewGable, @Ollyws, @zanyrenney, @DylanDylann Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  16. Ollyws commented on Oct 16, 2023

    @Ollyws
    Contributor

    BugZero Checklist:
    There's no PR responsible as this wasn't a regression, more of a new feature.
    I don't think a regression test is helpful here as it isn't an important flow nor is it very impactful.

  17. zanyrenney commented on Oct 16, 2023

    @zanyrenney
    Contributor

    I agree @Ollyws thanks!

  18. zanyrenney commented on Oct 16, 2023

    @zanyrenney
    Contributor

    summary of payments
    @Ollyws requires payment offer (Reviewer) - paid $750 ($500 + $250 urgency)
    @DylanDylann requires payment offer (Contributor) paid $750 ($500 + $250 urgency)
    @DylanDylann requires payment offer (Contributor) - paid $50 reporting bonus

  19. zanyrenney commented on Oct 16, 2023

    @zanyrenney
    Contributor

    all payments are now complete via upwork, closing!

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 productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions