-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9560 from Expensify/puneet-personaldetails-refactor
Stop using MY_PERSONAL_DETAILS and only use PERSONAL_DETAILS in Onyx
- Loading branch information
Showing
16 changed files
with
189 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.