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

Refactor PersonalDetails_Update with a few new commands #9696

Merged
merged 28 commits into from
Aug 1, 2022

Conversation

Beamanator
Copy link
Contributor

@Beamanator Beamanator commented Jul 5, 2022

Details

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/211813

Tests

Same tests as: https://github.com/Expensify/Web-Expensify/pull/34219:

UpdateProfile

  1. Go to profile, update name & timezone, save
  2. Make sure everything updates correctly (& in multiple devices!)
  3. Verify you see this in the App logs:
[info] [Report] Handled onyxApiUpdate event sent by Pusher - [{"onyxMethod":"merge","key":"personalDetails","value":{"[email protected]":{"firstName":"TheE","lastName":"OriginalFake","pronouns":"__predefined_callMeByMyName"}}}]
[info] [Report] Handled onyxApiUpdate event sent by Pusher - [{"onyxMethod":"merge","key":"personalDetails","value":{"[email protected]":{"timezone":{"automatic":false,"selected":"Africa/Cairo"}}}}]

OpenProfile

  1. Make sure your timezone is set and is ready to update automatically
  2. In Onyx, manually change your timezone to a valid timezone, in a different time zone
  3. Open profile page
  4. Verify Tz updates back to your current timezone everywhere!
  5. Verify you see this in the App logs: [info] [Report] Handled onyxApiUpdate event sent by Pusher - [{"onyxMethod":"merge","key":"personalDetails","value":{"[email protected]":{"timezone":{"automatic":true,"selected":"Africa/Cairo"}}}}]

DeleteUserAvatar

  1. Delete your personal user avatar
  2. Verify you now get a default avatar set on all devices!
  3. Verify you see this in the App logs: [info] [Report] Handled onyxApiUpdate event sent by Pusher - [{"onyxMethod":"merge","key":"personalDetails","value":{"[email protected]":{"avatar":"https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/avatar_7.png"}}}]
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (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 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 included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • 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.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is
  • 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(themeColors.componentBG)
  • 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.

PR Reviewer Checklist

  • 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 verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • 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 proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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(themeColors.componentBG)
  • 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.

QA Steps

Same as "Tests" section, but don't worry about checking the logs

  • Verify that no errors appear in the JS console

Screenshots

Web & Desktop

Updating timezone by opening profile:

Screen.Recording.2022-07-19.at.4.38.22.PM.mov

Deleting profile image:

Screen.Recording.2022-07-19.at.4.40.31.PM.mov

Updating profile info

Screen.Recording.2022-07-19.at.4.42.18.PM.mov

Mobile Web

iOS

Android

@Beamanator Beamanator self-assigned this Jul 5, 2022
@Beamanator Beamanator changed the title [WIP] Refactor PersonalDetails_Update [HOLD #9560] Refactor PersonalDetails_Update Jul 15, 2022
@Beamanator Beamanator marked this pull request as ready for review July 15, 2022 16:36
@Beamanator Beamanator requested a review from a team as a code owner July 15, 2022 16:36
@melvin-bot melvin-bot bot requested review from Gonals and removed request for a team July 15, 2022 16:36
@Beamanator Beamanator changed the title [HOLD #9560] Refactor PersonalDetails_Update Refactor PersonalDetails_Update Jul 18, 2022
@Beamanator
Copy link
Contributor Author

The App PR we were waiting on has been merged into main & into this branch! Ready for review 👍

@Gonals
Copy link
Contributor

Gonals commented Jul 19, 2022

Seems like Travis is not happy 😁

@Gonals
Copy link
Contributor

Gonals commented Jul 19, 2022

Can we get a few screenshots?

@Gonals
Copy link
Contributor

Gonals commented Jul 19, 2022

This should be on HOLD until the Web counterpart merges, right?

@Beamanator Beamanator changed the title Refactor PersonalDetails_Update [HOLD Web-Expensify#34219] Refactor PersonalDetails_Update Jul 19, 2022
@Beamanator
Copy link
Contributor Author

Put on hold :D Dang travis!!

And ya.... Videos are good... But... annoying to make... but will do :D

@mountiny
Copy link
Contributor

@Beamanator So I see it in your videos as well, but it is expected we wont update the details for the user automatically? For example, I feel like it is confusing that I have updated the name and then I go back to the settings but the name is not updated yet, I need to refresh or close settings and go back to the profile settings which updates the name in UI as well

Comment on lines 271 to 282
optimisticData: [{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS,
value: {
[currentUserEmail]: {
firstName,
lastName,
pronouns,
timezone,
},
},
}],
Copy link
Contributor

Choose a reason for hiding this comment

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

@Beamanator should this optimistic data actually update it in the UI automatically? Is it that we do not rerender the RHS when we go back from the settings?

In profile settings:
image

Clicking back to the settings, still old name
image

I think that should be fixed because as user I would be perplexed what is correct.

@Beamanator
Copy link
Contributor Author

@mountiny I also saw that prop type timezone error (you mentioned here) but not for the account I was testing with - I think it's a bug in how we default a timezone when that account doesn't have a timezone set in an NVP - but I'm not 100% sure, didn't have enough time to investigate today

about why personal details aren't updating even after going away from the page & back, that's really weird I will test that out tomorrow 🤔 thanks for the thorough testing!

@mountiny
Copy link
Contributor

No, thank you for working on this!

@Beamanator
Copy link
Contributor Author

Ok @vitHoracek it looks like this is the fix you're looking for, right? I'm about to commit these changes

Screen.Recording.2022-07-29.at.1.06.42.PM.mov

@mountiny
Copy link
Contributor

mountiny commented Jul 29, 2022

@Beamanator YAAASS 😍

Comment on lines +280 to +283
displayName: getDisplayName(currentUserEmail, {
firstName,
lastName,
}),
Copy link
Contributor Author

@Beamanator Beamanator Jul 29, 2022

Choose a reason for hiding this comment

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

FYI this will need to be added in Web-E so that all clients get updated with this displayName, I plan to add this requirement in this issue: https://github.com/Expensify/Expensify/issues/220321

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but we should not get any problems when sending this. It will get updated for other users when their refresh, but it is not included in the Pusher update you saying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right right exactly @mountiny - nothing will break, only the client making the change will get these updates automatically, others will get it after refresh 👍

@Beamanator
Copy link
Contributor Author

Great!! This will not update on all clients yet (see my previous comment) but I'll fix that in a following Web-E PR 👍

@Beamanator Beamanator requested a review from mountiny July 29, 2022 11:14
@Beamanator
Copy link
Contributor Author

Actually before we merge this, I'm going to add firstName, lastName, and pronouns as their own params to UpdateProfile so that it will be fewer PRs to change from details to the individual params

@Beamanator
Copy link
Contributor Author

Ok now I think we're good to go again

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

I have one more outstanding question there.

Otherwise I think we are good to go with how the timezones work now, but we should update the test steps. Also I would copy them over from the Web-E so it is easier for QA to follow!

Great job Alex, this one is now easy

const oldTimezoneData = myPersonalDetails.timezone || {};
const newTimezoneData = {
automatic: lodashGet(oldTimezoneData, 'automatic', true),
selected: moment.tz.guess(true),
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed with Alex in DM, I think this function does not work as expected with the VPNs and it does not set you to the timezone of the area. However, that is how we have it now and I would argue it is better as in the chat you want others to see your actual timezone and not the VPN timezone.

hasSelfSelectedPronouns: !_.isEmpty(this.props.currentUserPersonalDetails.pronouns) && !this.props.currentUserPersonalDetails.pronouns.startsWith(CONST.PRONOUNS.PREFIX),
selectedTimezone: lodashGet(this.props.currentUserPersonalDetails, 'timezone.selected', CONST.DEFAULT_TIME_ZONE.selected),
isAutomaticTimezone: lodashGet(this.props.currentUserPersonalDetails, 'timezone.automatic', CONST.DEFAULT_TIME_ZONE.automatic),
hasSelfSelectedPronouns: !(currentUserDetails.pronouns || '').startsWith(CONST.PRONOUNS.PREFIX),
Copy link
Contributor

Choose a reason for hiding this comment

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

@Beamanator I think this change is not gonna result in the same boolean right?

if pronouns is empty, we will get false for hasSelfSelectedPronouns here:

!_.isEmpty(this.props.currentUserPersonalDetails.pronouns)

but if pronouns is empty with the new line, that would be startsWith(PREFIX) is false and negating the entire line will give true.

Nonetheless, even if it is correct, it is hard to understand 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dude good shout, this would probably cause weird behavior if pronouns is empty 🙃 👍

I can revert part of the refactor here, just keeping the currentPersonalDetails simplification

Copy link
Contributor

Choose a reason for hiding this comment

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

@Beamanator Sounds good!

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Thanks for working on thins and for all the changes!

@Beamanator
Copy link
Contributor Author

Added necessary check back (for has personal pronouns), brought tests here from the Web-E PR, and changed the timezone checks to not test by using a VM

@mountiny
Copy link
Contributor

mountiny commented Aug 1, 2022

Since Alberto approved the changes before, let's :shipit:

@mountiny mountiny merged commit fd7c59a into main Aug 1, 2022
@mountiny mountiny deleted the beaman-refactorPersonalDetailsUpdate branch August 1, 2022 11:00
@OSBotify
Copy link
Contributor

OSBotify commented Aug 1, 2022

✋ 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

OSBotify commented Aug 1, 2022

🚀 Deployed to staging by @mountiny in version: 1.1.87-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 failure ❌
🕸 web 🕸 failure ❌

Comment on lines +183 to +191
PersonalDetails.updateProfile(
this.state.firstName.trim(),
this.state.lastName.trim(),
this.state.pronouns.trim(),
{
automatic: this.state.isAutomaticTimezone,
selected: this.state.selectedTimezone,
},
}, true);
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This tiny change gave rise to #10215

Note: The main issue is opacity being incorrect, not the Growl being missing

@OSBotify
Copy link
Contributor

OSBotify commented Aug 4, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.87-9 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 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.

4 participants