-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Stop using MY_PERSONAL_DETAILS and only use PERSONAL_DETAILS in Onyx #9560
Changes from all commits
1a05abf
8b67fd9
98092d7
09fe20d
413872f
dc7170b
630e90e
c6a6d82
9aa4772
a65ca25
c3ba3b0
b1a1eb7
dc7a183
b035b1d
5f9bf56
b005095
22e1150
085ed98
380dbaf
3d37ef3
67e1fd5
8aec239
31ab939
1def41d
00bd238
afa27df
6fc8e92
a6fbd64
59168f3
55568ac
cd60eca
83ae808
92a6cbb
e6bbd9c
c9e4421
6f371c0
58f74c8
ccb9d27
0deaba4
972c310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import getComponentDisplayName from '../libs/getComponentDisplayName'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
import personalDetailsPropType from '../pages/personalDetailsPropType'; | ||
|
||
const withCurrentUserPersonalDetailsPropTypes = { | ||
currentUserPersonalDetails: personalDetailsPropType, | ||
}; | ||
|
||
const withCurrentUserPersonalDetailsDefaultProps = { | ||
currentUserPersonalDetails: {}, | ||
}; | ||
|
||
export default function (WrappedComponent) { | ||
const WithCurrentUserPersonalDetails = (props) => { | ||
const currentUserEmail = props.session.email; | ||
|
||
return ( | ||
<WrappedComponent | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
ref={props.forwardedRef} | ||
currentUserPersonalDetails={props.personalDetails[currentUserEmail]} | ||
/> | ||
); | ||
}; | ||
|
||
WithCurrentUserPersonalDetails.displayName = `WithCurrentUserPersonalDetails(${getComponentDisplayName(WrappedComponent)})`; | ||
WithCurrentUserPersonalDetails.propTypes = { | ||
forwardedRef: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}), | ||
]), | ||
|
||
/** Personal details of all the users, including current user */ | ||
personalDetails: PropTypes.objectOf(personalDetailsPropType), | ||
|
||
/** Session of the current user */ | ||
session: PropTypes.shape({ | ||
email: PropTypes.string, | ||
}), | ||
}; | ||
|
||
WithCurrentUserPersonalDetails.defaultProps = { | ||
forwardedRef: undefined, | ||
personalDetails: {}, | ||
session: { | ||
email: '', | ||
}, | ||
}; | ||
|
||
const withCurrentUserPersonalDetails = React.forwardRef((props, ref) => ( | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
<WithCurrentUserPersonalDetails {...props} forwardedRef={ref} /> | ||
)); | ||
|
||
return withOnyx({ | ||
personalDetails: { | ||
key: ONYXKEYS.PERSONAL_DETAILS, | ||
}, | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
})(withCurrentUserPersonalDetails); | ||
} | ||
|
||
export { | ||
withCurrentUserPersonalDetailsPropTypes, | ||
withCurrentUserPersonalDetailsDefaultProps, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,27 @@ import LogOutPreviousUserPage from '../../../pages/LogOutPreviousUserPage'; | |
import networkPropTypes from '../../../components/networkPropTypes'; | ||
import {withNetwork} from '../../../components/OnyxProvider'; | ||
|
||
let currentUserEmail; | ||
Onyx.connect({ | ||
key: ONYXKEYS.MY_PERSONAL_DETAILS, | ||
key: ONYXKEYS.SESSION, | ||
callback: (val) => { | ||
// When signed out, val is undefined | ||
if (!val) { | ||
return; | ||
} | ||
|
||
const timezone = lodashGet(val, 'timezone', {}); | ||
currentUserEmail = val.email; | ||
}, | ||
}); | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.PERSONAL_DETAILS, | ||
callback: (val) => { | ||
if (!val) { | ||
return; | ||
} | ||
|
||
const timezone = lodashGet(val, currentUserEmail, 'timezone', {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB, it seems like there is a very remote chance that The subscriptions here feel out of place though and should be probably be moved into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this needed to be |
||
const currentTimezone = moment.tz.guess(true); | ||
|
||
// If the current timezone is different than the user's timezone, and their timezone is set to automatic | ||
|
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 with this one :)