-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 #20276 from cloudpresser/cloudpresser/userDetailsT…
…ooltip Cloudpresser/user details tooltip
- Loading branch information
Showing
13 changed files
with
200 additions
and
46 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
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,52 @@ | ||
import React, {useCallback} from 'react'; | ||
import {View, Text} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Str from 'expensify-common/lib/str'; | ||
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import Avatar from '../Avatar'; | ||
import Tooltip from '../Tooltip'; | ||
import {propTypes, defaultProps} from './userDetailsTooltipPropTypes'; | ||
import styles from '../../styles/styles'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
function UserDetailsTooltip(props) { | ||
const userDetails = lodashGet(props.personalDetailsList, props.accountID, props.fallbackUserDetails); | ||
const renderTooltipContent = useCallback( | ||
() => ( | ||
<View style={[styles.alignItemsCenter, styles.ph2, styles.pv2]}> | ||
<View style={styles.emptyAvatar}> | ||
<Avatar | ||
containerStyles={[styles.actionAvatar]} | ||
source={userDetails.avatar} | ||
/> | ||
</View> | ||
|
||
<Text style={[styles.mt2, styles.textMicroBold, styles.textReactionSenders, styles.textAlignCenter]}> | ||
{String(userDetails.displayName).trim() ? userDetails.displayName : ''} | ||
</Text> | ||
|
||
<Text style={[styles.textMicro, styles.fontColorReactionLabel]}> | ||
{String(userDetails.login).trim() && !_.isEqual(userDetails.login, userDetails.displayName) ? Str.removeSMSDomain(userDetails.login) : ''} | ||
</Text> | ||
</View> | ||
), | ||
[userDetails.avatar, userDetails.displayName, userDetails.login], | ||
); | ||
|
||
if (!userDetails.displayName && !userDetails.login) { | ||
return props.children; | ||
} | ||
|
||
return <Tooltip renderTooltipContent={renderTooltipContent}>{props.children}</Tooltip>; | ||
} | ||
|
||
UserDetailsTooltip.propTypes = propTypes; | ||
UserDetailsTooltip.defaultProps = defaultProps; | ||
UserDetailsTooltip.displayName = 'UserDetailsTooltip'; | ||
|
||
export default withOnyx({ | ||
personalDetailsList: { | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
}, | ||
})(UserDetailsTooltip); |
28 changes: 28 additions & 0 deletions
28
src/components/UserDetailsTooltip/userDetailsTooltipPropTypes.js
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,28 @@ | ||
import PropTypes from 'prop-types'; | ||
import personalDetailsPropType from '../../pages/personalDetailsPropType'; | ||
|
||
const propTypes = { | ||
/** User's Account ID */ | ||
accountID: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, | ||
/** Fallback User Details object used if no accountID */ | ||
fallbackUserDetails: PropTypes.shape({ | ||
/** Avatar URL */ | ||
avatar: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
/** Display Name */ | ||
displayName: PropTypes.string, | ||
/** Login */ | ||
login: PropTypes.string, | ||
}), | ||
/** Component that displays the tooltip */ | ||
children: PropTypes.node.isRequired, | ||
/** List of personalDetails (keyed by accountID) */ | ||
personalDetailsList: PropTypes.objectOf(personalDetailsPropType), | ||
}; | ||
|
||
const defaultProps = { | ||
accountID: '', | ||
fallbackUserDetails: {displayName: '', login: '', avatar: ''}, | ||
personalDetailsList: {}, | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
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.