Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.11k stars 2.61k forks source link

[HOLD for payment 2024-01-17] [$500] [WAVE 5][LOW] Settings - Year change by months does not change selection #33006

Closed izarutskaya closed 5 months ago

izarutskaya commented 6 months ago

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


Version Number: v1.4.12-0 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 Expensify/Expensify Issue URL: Issue reported by: Slack conversation: @

Action Performed:

  1. Open the app
  2. Open settings->profile->personal details->date of birth
  3. Click on the year and select a year, observe that after value is changed, both background colour and green tick location are on the selected year
  4. Click year again > now click the forward arrow of the month (>) until you get to January
  5. Click on the year again and notice that the green checkmark is on the previously selected year and the highlight year is the new year

Expected Result:

App should change background color as well as green tick position for the selected or current calendar year

Actual Result:

App changes background color but does not change green tick position on change of year value by changing months value in calendar

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

https://github.com/Expensify/App/assets/115492554/487e5060-ac97-425c-afd1-aa057e146c64

image

image

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0102b1c7f6c3df6359
  • Upwork Job ID: 1735031332000718848
  • Last Price Increase: 2023-12-13
  • Automatic offers:
    • mollfpr | Reviewer | 28064580
    • ishpaul777 | Contributor | 28064581
melvin-bot[bot] commented 6 months ago

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

melvin-bot[bot] commented 6 months ago

Job added to Upwork: https://www.upwork.com/jobs/~0102b1c7f6c3df6359

melvin-bot[bot] commented 6 months ago

Bug0 Triage Checklist (Main S/O)

melvin-bot[bot] commented 6 months ago

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

ishpaul777 commented 6 months ago

Proposal

Problem

Year change by months does not change selection

Root Cause

When we add a month (here) to selected date or move to previous (here) we only modify the currentDateView state and isSelected field in years state is not changed when year is also changes

Changes

we need to change selected year in years state when year is added(move to next month) or subtracted(moveToprevMonth)

    /**
     * Handles the user pressing the previous month arrow of the calendar picker.
     */
    moveToPrevMonth() {
        this.setState((prev) => {
            const prevMonth = subMonths(new Date(prev.currentDateView), 1);
            // if year is subtracted, we need to update the years list
            let newYears = prev.years;
            if (prevMonth.getFullYear() < prev.currentDateView.getFullYear()) {
                newYears = _.map(prev.years, (item) => ({
                    ...item,
                    isSelected: item.value === prevMonth.getFullYear(),
                }));
            }

            return {
                ...prev,
                currentDateView: prevMonth,
                years: newYears,
            };
        });
    }

    /**
     * Handles the user pressing the next month arrow of the calendar picker.
     */
    moveToNextMonth() {
        this.setState((prev) => {
            const nextMonth = addMonths(new Date(prev.currentDateView), 1);
            // if year is added, we need to update the years list
            let newYears = prev.years;
            if (nextMonth.getFullYear() > prev.currentDateView.getFullYear()) {
                newYears = _.map(prev.years, (item) => ({
                    ...item,
                    isSelected: item.value === nextMonth.getFullYear(),
                }));
            }

            return {
                ...prev,
                currentDateView: nextMonth,
                years: newYears,
            };
        });
    }
ZhenjaHorbach commented 6 months ago

Proposal

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

Settings - Year change by months does not change selection

What is the root cause of that problem?

The main problem is that the selected year changes thanks only to onYearSelected which call only when we set year

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

Instead of duplicating the logic for changing the selected year, we can simply add a listener

We can add new useEffect which will listen currentYear for YearPickerModal when our modal is not visible

https://github.com/Expensify/App/blob/3df907ce12d1085b71231aff126cb5288a5e8145/src/components/DatePicker/CalendarPicker/YearPickerModal.js#L36

    useEffect(() => {
        if (!props.isVisible) {
            props.onYearChange(props.currentYear);
        }
    }, [props.currentYear, props.isVisible]);

What alternative solutions did you explore? (Optional)

As alternative we can use componentDidUpdate inside CalendarPicker

https://github.com/Expensify/App/blob/e81ed8f4c548d0c1675a6d696772a914d115c2b1/src/components/DatePicker/CalendarPicker/index.js#L46

    componentDidUpdate(prevProps, prevState) {
        if (this.state.currentDateView.getFullYear() !== prevState.currentDateView.getFullYear()) {
            this.onYearSelected(this.state.currentDateView.getFullYear());
        }
    }
Christinadobrzyn commented 6 months ago

I can reproduce this - I think it's a low priority but I think it could be part of [ECARD] LOW: Settings - Remove unnecessary requirement for dateOfBirth when creating physical cards in Marqeta#316704

Adding it to that Wave to evaluate this change!

ishpaul777 commented 6 months ago

@Christinadobrzyn i think we should treat this as normal priorty issue because the Calendar component is widely used in app, in bank account flow, money request and date of birth, and it looks like visual inconsistency which feels broken, user may encounter this in a normal flow of using app

tienifr commented 6 months ago

Proposal

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

Settings - Year change by months does not change selection

What is the root cause of that problem?

  1. In CalendarPicker we store years but did not use it in CalendarPicker, we just pass it to YearPickerModal. So it can make our component re-renders unexpectedly
  2. To show the selected year, we have to check isSelected here, but when year changes by months, we did not call onYearSelected so years sections is not updated

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

  1. We should not store years in CalendarPicker, because we did not use it in CalendarPicker. We should calculate years in YearPickerModal. We will pass minYear, maxYear instead of years
  2. When calculate years in YearPickerModal, we check isSelected=value === props.currentYear so we can make sure the currentYear will be selected
    const initialYears = useRef(_.map(
        Array.from({length: props.maxYear - props.minYear + 1}, (v, i) => i + props.minYear),
        (value) => ({
            text: value.toString(),
            value,
            keyForList: value.toString(),
        }),
    ))

    const years = useMemo(()=>{
        return _.map(
            initialYears.current,
            (year) => ({
                ...year,
                isSelected: year.value === props.currentYear,
            }),
        )
    },[props.currentYear])

Result

https://github.com/Expensify/App/assets/113963320/5dcd56ef-7cfa-4e4b-99dc-c9aee0fe4fcd

Christinadobrzyn commented 6 months ago

Hi @ishpaul777 it looks like this job will be treated with our normal priority.

@mollfpr feel free to evaluate the provided proposal to see if any will work. Thanks!

flodnv commented 6 months ago

I think it could be part of https://github.com/Expensify/Expensify/issues/316704

FWIW this is unrelated

melvin-bot[bot] commented 6 months ago

@mollfpr, @Christinadobrzyn Whoops! This issue is 2 days overdue. Let's get this updated quick!

mollfpr commented 6 months ago

I feel the proposal from @ishpaul777 is the correct way to handle this issue. It makes it easier to maintain the prev/next month's function.

πŸŽ€ πŸ‘€ πŸŽ€ C+ reviewed!

melvin-bot[bot] commented 6 months ago

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

melvin-bot[bot] commented 6 months ago

πŸ“£ @mollfpr πŸŽ‰ 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[bot] commented 6 months ago

πŸ“£ @ishpaul777 πŸŽ‰ 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 πŸ“–

Christinadobrzyn commented 6 months ago

still working on a review - @danieldoglas when you have a moment can you check on this decision - https://github.com/Expensify/App/issues/33006#issuecomment-1859715285

mollfpr commented 6 months ago

@Christinadobrzyn, I think we already let @ishpaul777 work on the issue. We need to wait for the PR to be ready.

Christinadobrzyn commented 6 months ago

hi @mollfpr just checking on the PR review!

mollfpr commented 6 months ago

@Christinadobrzyn Yup, working on it!

melvin-bot[bot] commented 5 months ago

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

melvin-bot[bot] commented 5 months ago

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

If no regressions arise, payment will be issued on 2024-01-17. :confetti_ball:

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

melvin-bot[bot] commented 5 months ago

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:

mollfpr commented 5 months ago

[@mollfpr] The PR that introduced the bug has been identified. Link to the PR:

https://github.com/Expensify/App/pull/21792

[@mollfpr] 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:

https://github.com/Expensify/App/pull/21792/files#r1457723732

[@mollfpr] 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:

The regression step should be enough.

[@mollfpr] Determine if we should create a regression test for this bug. [@mollfpr] 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.

  1. Sign in to the App
  2. Navigate to settings -> profile -> DOB
  3. Click the forward arrow of the month (>) until you get to January. Note that the year has changed. Now open the year picker and verify the changed year is highlighted
  4. Click the backward arrow of the month (<) until you get to December; note the year has changed. Now open the year picker and verify the changed year is highlighted

@Christinadobrzyn Could you give the payment summary for the manual request in NewDot? Thank you!

danieldoglas commented 5 months ago

Just awaiting payment, not overdue. cc @Christinadobrzyn

Christinadobrzyn commented 5 months ago

Sorry for the delay here

Regression test here- https://github.com/Expensify/Expensify/issues/363007

Payouts due:

Issue Reporter: NA Contributor: $500 @ishpaul777 (Paid in Upwork) Contributor+: $500 @mollfpr - you get paid in NewDot or Upwork?

Eligible for 50% #urgency bonus? NA

Upwork job is here. The upwork job is now closed so let me know if you need payment through Upwork and I'll create a new job

mollfpr commented 5 months ago

Thanks @Christinadobrzyn I'll request the payment in NewDot.

JmillsExpensify commented 5 months ago

$500 approved for @mollfpr based on summary above.

Christinadobrzyn commented 5 months ago

awesome! I think we're good to close this. Thanks all!