Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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
1 of 6 tasks
kbecciv opened this issue Sep 22, 2023 · 45 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kbecciv
Copy link

kbecciv commented Sep 22, 2023

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
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Sep 22, 2023
@melvin-bot melvin-bot bot changed the title Web - City field is not clear when select another country [$500] Web - City field is not clear when select another country Sep 22, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01e5128ed81517974f

@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 22, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 22, 2023

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

@kbecciv
Copy link
Author

kbecciv commented Sep 22, 2023

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 || ‘’}

@abzokhattab
Copy link
Contributor

abzokhattab commented Sep 22, 2023

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

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Sep 22, 2023

Proposal

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

City field doesn't clear when select another country

What is the root cause of that problem?

We do not clear the field after changing the country

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

we have input which needs to be added the ability to change values externally like changing state or country using value prop

<TextInput
inputID="city"
label={translate('common.city')}
accessibilityLabel={translate('common.city')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={address.city || ''}
maxLength={CONST.FORM_CHARACTER_LIMIT}
spellCheck={false}
/>

But instead of creating a new useState, it would be nice to create one useState for all inputs like

const [personalDetails, setPersonalDetails] = useState({
   country: PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country')),
   state: address.state,
   city: address.city || ''
});

And update this function like

     const handleAddressChange = (value, key) => {
        if (key === 'country') {
             setPersonalDetails({
                ...personalDetails,
                state:'',
                country: value,
                city:'',
             })
            return;
        }
         if (key !== 'state' && key !== 'city') {
            return;
        }
        setPersonalDetails({
                ...personalDetails,
                [key]: value
         });
    };

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

This approach allows us to save from unnecessary rerenders and new useStates.

What alternative solutions did you explore? (Optional)

NA

@melvin-bot melvin-bot bot added the Overdue label Sep 25, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Sep 25, 2023

@DylanDylann's proposal looks good to me.
🎀👀🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

Triggered auto assignment to @AndrewGable, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@abzokhattab
Copy link
Contributor

Just to bring your attention @Ollyws, this approach will bring a breaking change that has to be fixed, which is mentioned in my proposal. you can have a look at it.

@zanyrenney
Copy link
Contributor

dupe assignment, so unassigning myself as i am the second assignee for @michaelhaxhiu to manage.

@zanyrenney zanyrenney removed their assignment Sep 26, 2023
@DylanDylann
Copy link
Contributor

@abzokhattab This is another bug and I also suggest fixing it in my original proposal for both issues here

@DylanDylann
Copy link
Contributor

@AndrewGable Could you give some of your opinion on this issue when you have a chance?

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 27, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 27, 2023

📣 @Ollyws 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Sep 27, 2023

📣 @DylanDylann 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@eVoloshchak
Copy link
Contributor

@DylanDylann, this bug wasn't present when #28404 was merged
(use gh pr checkout 28404 to double-check)

Screen.Recording.2023-10-04.at.18.33.23.mov

@Ollyws
Copy link
Contributor

Ollyws commented Oct 4, 2023

@DylanDylann
I don't know if it's fair to call it a regression that was our fault, because it occured from an unfortunate, last-minute merge that was outside of the review process.
But I think we should fix it anyway, we just need to add setCity to this useEffect.

@AndrewGable How does a situation like this usually work, If a merge conflict resolution causes a regression?

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Oct 4, 2023
@DylanDylann
Copy link
Contributor

DylanDylann commented Oct 4, 2023

@Ollyws No problem, The PR is ready

@AndrewGable Just a note. In this issue #27814, I proposed a solution to fix both bugs #28007 and #27814 (even though the regression #27814 (comment) ). But It is not selected because the C+ contributor doesn't think #28007 is a bug. And then when #28007 is accepted as a bug, I mentioned that we also need to fix the same case with the city field in here because It is same bug with OP but there is no response.

I tried to give more value and collaborate to have good work.

@melvin-bot
Copy link

melvin-bot bot commented Oct 5, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @DylanDylann got assigned: 2023-09-27 19:33:13 Z
  • when the PR got merged: 2023-10-05 17:11:58 UTC
  • days elapsed: 5

On to the next one 🚀

@AndrewGable
Copy link
Contributor

@zanyrenney - Let's just pay this out with the 50% bonus as noted here the regression was out of our control and fixed quickly.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Oct 9, 2023
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2023-10-10] [$500] Web - City field is not clear when select another country [HOLD for payment 2023-10-16] [HOLD for payment 2023-10-10] [$500] Web - City field is not clear when select another country Oct 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 9, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 9, 2023

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:

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Oct 10, 2023
@zanyrenney
Copy link
Contributor

4 more days before we can pay this out!

@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Oct 12, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 16, 2023

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

@Ollyws
Copy link
Contributor

Ollyws commented Oct 16, 2023

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.

@melvin-bot melvin-bot bot removed the Overdue label Oct 16, 2023
@zanyrenney
Copy link
Contributor

I agree @Ollyws thanks!

@zanyrenney
Copy link
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

@zanyrenney
Copy link
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
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

10 participants