-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix: Private personal details are not fetched when navigating by direct link #22906
Fix: Private personal details are not fetched when navigating by direct link #22906
Conversation
@Santhosh-Sellavel 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] |
Cc: @allroundexperts yours |
Reviewer Checklist
Screenshots/VideosWebScreen.Recording.2023-07-25.at.12.39.25.AM.movMobile Web - ChromeScreen.Recording.2023-07-25.at.12.50.07.AM.movMobile Web - SafariScreen.Recording.2023-07-25.at.12.47.32.AM.movDesktopScreen.Recording.2023-07-25.at.12.44.53.AM.moviOSScreen.Recording.2023-07-25.at.12.56.16.AM.movAndroidScreen.Recording.2023-07-25.at.12.58.22.AM.mov |
@allroundexperts any updates? |
Still on it. The changed files are a little more than what I expected. That's taking me some time! |
class PrivatePersonalDetailsProvider extends React.Component { | ||
componentDidMount() { | ||
if (this.props.network.isOffline || !isAuthenticated(this.props.session)) { | ||
return; | ||
} | ||
|
||
PersonalDetails.openPersonalDetailsPage(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
// Only open personal detail page if the network is online, and the state is transitioning from unauthenticated to authenticated | ||
if (this.props.network.isOffline || !isAuthenticated(this.props.session) || isAuthenticated(prevProps.session)) { | ||
return; | ||
} | ||
PersonalDetails.openPersonalDetailsPage(); | ||
} | ||
|
||
render() { | ||
return <PrivatePersonalDetailsContext.Provider value={this.props}>{this.props.children}</PrivatePersonalDetailsContext.Provider>; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more class components please.
export default function withPrivatePersonalDetails(WrappedComponent) { | ||
const WithPrivatePersonalDetails = forwardRef((props, ref) => ( | ||
<PrivatePersonalDetailsContext.Consumer> | ||
{(privatePersonalDetailsProps) => ( | ||
<WrappedComponent | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...privatePersonalDetailsProps} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
ref={ref} | ||
/> | ||
)} | ||
</PrivatePersonalDetailsContext.Consumer> | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of wrapping this in a Consumer
, lets just use the hook (src/hooks/usePrivatePersonalDetails.js
) that you created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole Context
approach does not make sense here. We just need to initialise the API call to read personal details here along with openApp
call. I think this will do what we want.
}, | ||
}), | ||
)(AddressPage); | ||
export default compose(withLocalize, withPrivatePersonalDetails)(AddressPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use Onyx
? Let's not re-invent the wheel here please.
const [addressStreet1, setAddressStreet1] = useState(''); | ||
const [addressStreet2, setAddressStreet2] = useState(''); | ||
const [addressCity, setAddressCity] = useState(''); | ||
const [addressState, setAddressState] = useState(''); | ||
const [addressZip, setAddressZip] = useState(''); | ||
const [addressCountry, setAddressCountry] = useState(''); | ||
|
||
useEffect(() => { | ||
const {address} = privatePersonalDetails; | ||
if (!address) { | ||
return; | ||
} | ||
const [street1, street2] = (address.street || '\n').split('\n'); | ||
setAddressStreet1(street1); | ||
setAddressStreet2(street2); | ||
setAddressCity(address.city); | ||
setAddressState(address.state); | ||
setAddressZip(address.zip); | ||
setAddressCountry(address.country); | ||
}, [privatePersonalDetails, privatePersonalDetails.address]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
const [dob, setDob] = useState(privatePersonalDetails.dob || ''); | ||
|
||
useEffect(() => { | ||
setDob(privatePersonalDetails.dob); | ||
}, [privatePersonalDetails.dob]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
}, | ||
}), | ||
)(DateOfBirthPage); | ||
export default compose(withLocalize, withPrivatePersonalDetails)(DateOfBirthPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous file.
useEffect(() => { | ||
setLegalFirstName(lodashGet(privatePersonalDetails, 'legalFirstName', '')); | ||
setLegalLastName(lodashGet(privatePersonalDetails, 'legalLastName', '')); | ||
}, [privatePersonalDetails, privatePersonalDetails.legalFirstName, privatePersonalDetails.legalLastName]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense to use a HoC
when we've shifted to functional components. I think this PR could have been much simpler.
@allroundexperts Can you please help check again? I though we have several files using React class component so I try to create the HOC. Sorry for this inconvenience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using similar pattern elsewhere? I think it would be better to add PersonalDetails.openPersonalDetailsPage
call along with the OpenApp
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm not yet, but I don't think fetching personalDetails along with OpenApp is a good idea. Firstly, we may not access personalDetail page, so fetching personalDetails at first is unnecessary. Secondly, we have many places that use openPage like PersonalDetails.openPublicProfilePage(accountID)
and it's not executed along with OpenApp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... You do have a valid point. Can you think of a way so that we just have to rely on onyx for getting data inside the component instead of using this hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still using data from onyx inside the component. we just use the hook to fetch data if needed and don't worry about the performance because we have the logic to prevent fetching data again if it's already in onyx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this again, I think this approach is fine actually. We won't have to repeat the usage of useEffect
on every page where we need this data.
@@ -118,7 +118,10 @@ function AddressPage(props) { | |||
}, []); | |||
|
|||
return ( | |||
<ScreenWrapper includeSafeAreaPaddingBottom={false}> | |||
<PersonalDetailsScreenWrapper | |||
privatePersonalDetails={props.privatePersonalDetails} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not really needed. You can just use Onyx
to get that data inside PersonalDetailsScreenWrapper
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I think its not much and should be fine as it is.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Tests well as well!
Hi! Can I get a quick summary of why we decided to go with a new component instead of a hook? I can definitely be convinced, but the hook seemed cleaner to me when it was proposed. Thanks! |
@dangrous We're still using the hook in the component. |
Right but I don't think the new component (PersonalDetailsScreenWrapper) was part of the proposal, unless I'm mistaken? |
It wasn't. Its just an optimisation that prevents us from repeating the |
Hm yeah, I get the idea behind it but it doesn't seem like a pattern we've really used before. I might prefer just replicating the loader and hook in each component; I realize that is a bit of duplicated code but I think it might be cleaner overall. Happy to open the discussion to Slack though if y'all want more opinions! |
@tienifr What do you think? |
Nops. I'm good. Lets revert that! |
This reverts commit d452118 Signed-off-by: tienifr <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two quick updates, looks great though!
Thanks, I've updated @dangrous. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.46-0 🚀
|
🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.47-0 🚀
|
🚀 Deployed to production by https://github.com/marcaaron in version: 1.3.46-2 🚀
|
🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.47-6 🚀
|
Details
Navigating to sub-pages under Personal details page by direct link does not fetch
private_personalDetails
data. This PR fixes that.Fixed Issues
$ #22606
PROPOSAL: #22606 (comment)
Tests
Offline tests
NA
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
22606-web.mp4
Mobile Web - Chrome
22606-mweb-chrome.mp4
Mobile Web - Safari
22606-mweb-safari.1.mp4
Desktop
22606-desktop.mp4
iOS
22606-ios-1.mp4
Android
22606-android.mp4