Skip to content

Commit

Permalink
Merge pull request #8409 from Tushu17/make-avatar-pressable
Browse files Browse the repository at this point in the history
make avatar and welcome message pressable
  • Loading branch information
chiragsalian authored May 17, 2022
2 parents f2218b6 + 69e76f2 commit c16d2eb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
17 changes: 12 additions & 5 deletions src/components/ReportWelcomeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import compose from '../libs/compose';
import * as ReportUtils from '../libs/ReportUtils';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import ONYXKEYS from '../ONYXKEYS';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Tooltip from './Tooltip';

const personalDetailsPropTypes = PropTypes.shape({
/** The login of the person (either email or phone number) */
Expand Down Expand Up @@ -85,7 +88,7 @@ const ReportWelcomeText = (props) => {
<Text style={styles.textAlignCenter}>
{roomWelcomeMessage.phrase1}
</Text>
<Text style={[styles.textStrong]}>
<Text style={[styles.textStrong]} onPress={() => Navigation.navigate(ROUTES.getReportDetailsRoute(props.report.reportID))}>
{props.report.reportName}
</Text>
<Text>
Expand All @@ -99,11 +102,15 @@ const ReportWelcomeText = (props) => {
<Text style={styles.textAlignCenter}>
{props.translate('reportActionsView.beginningOfChatHistory')}
</Text>
{_.map(displayNamesWithTooltips, ({displayName, pronouns}, index) => (
{_.map(displayNamesWithTooltips, ({
displayName, pronouns, tooltip,
}, index) => (
<Text key={displayName}>
<Text style={[styles.textStrong]}>
{displayName}
</Text>
<Tooltip text={tooltip}>
<Text style={[styles.textStrong]} onPress={() => Navigation.navigate(ROUTES.getDetailsRoute(participants[index]))}>
{displayName}
</Text>
</Tooltip>
{!_.isEmpty(pronouns) && <Text>{` (${pronouns})`}</Text>}
{(index === displayNamesWithTooltips.length - 1) && <Text>.</Text>}
{(index === displayNamesWithTooltips.length - 2) && <Text>{` ${props.translate('common.and')} `}</Text>}
Expand Down
15 changes: 2 additions & 13 deletions src/components/Tooltip/index.native.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';

// We can't use the common component for the Tooltip as Web implementation uses DOM specific method to
// render the View which is not present on the Mobile.
const propTypes = {
/** Styles to be assigned to the Tooltip wrapper views */
containerStyles: PropTypes.arrayOf(PropTypes.object),

/** Children to wrap with Tooltip. */
children: PropTypes.node.isRequired,
};

const defaultProps = {
containerStyles: [],
};

/**
* @param {propTypes} props
* @returns {ReactNodeLike}
*/
const Tooltip = props => (
<View style={props.containerStyles}>
{props.children}
</View>
props.children
);

Tooltip.propTypes = propTypes;
Tooltip.defaultProps = defaultProps;
Tooltip.displayName = 'Tooltip';

export default Tooltip;
22 changes: 22 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as Localize from './Localize';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Expensicons from '../components/Icon/Expensicons';
import md5 from './md5';
import Navigation from './Navigation/Navigation';
import ROUTES from '../ROUTES';

let sessionEmail;
Onyx.connect({
Expand Down Expand Up @@ -481,6 +483,25 @@ function getReportName(report, personalDetailsForParticipants = {}, policies = {
return _.map(displayNamesWithTooltips, ({displayName}) => displayName).join(', ');
}

/**
* Navigate to the details page of a given report
*
* @param {Object} report
*/
function navigateToDetailsPage(report) {
const participants = lodashGet(report, 'participants', []);

if (isChatRoom(report) || isPolicyExpenseChat(report)) {
Navigation.navigate(ROUTES.getReportDetailsRoute(report.reportID));
return;
}
if (participants.length === 1) {
Navigation.navigate(ROUTES.getDetailsRoute(participants[0]));
return;
}
Navigation.navigate(ROUTES.getReportParticipantsRoute(report.reportID));
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand All @@ -507,4 +528,5 @@ export {
getRoomWelcomeMessage,
getDisplayNamesWithTooltips,
getReportName,
navigateToDetailsPage,
};
15 changes: 1 addition & 14 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import * as Report from '../../libs/actions/Report';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import MultipleAvatars from '../../components/MultipleAvatars';
import SubscriptAvatar from '../../components/SubscriptAvatar';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import DisplayNames from '../../components/DisplayNames';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import participantPropTypes from '../../components/participantPropTypes';
Expand All @@ -28,9 +26,6 @@ import Text from '../../components/Text';
import Tooltip from '../../components/Tooltip';

const propTypes = {
/** The ID of the report */
reportID: PropTypes.number.isRequired,

/** Toggles the navigationMenu open and closed */
onNavigationMenuButtonClicked: PropTypes.func.isRequired,

Expand Down Expand Up @@ -113,15 +108,7 @@ const HeaderView = (props) => {
]}
>
<Pressable
onPress={() => {
if (isChatRoom || isPolicyExpenseChat) {
return Navigation.navigate(ROUTES.getReportDetailsRoute(props.reportID));
}
if (participants.length === 1) {
return Navigation.navigate(ROUTES.getDetailsRoute(participants[0]));
}
Navigation.navigate(ROUTES.getReportParticipantsRoute(props.reportID));
}}
onPress={() => ReportUtils.navigateToDetailsPage(props.report)}
style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}
>
{shouldShowSubscript ? (
Expand Down
14 changes: 8 additions & 6 deletions src/pages/home/report/ReportActionItemCreated.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {View} from 'react-native';
import {Pressable, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import ONYXKEYS from '../../../ONYXKEYS';
Expand All @@ -17,7 +17,6 @@ const propTypes = {

/** Whether the user is not an admin of policyExpenseChat chat */
isOwnPolicyExpenseChat: PropTypes.bool,

}),

/** Personal details of all the users */
Expand All @@ -38,6 +37,7 @@ const defaultProps = {
const ReportActionItemCreated = (props) => {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.report);
const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies);

return (
<View style={[
styles.chatContent,
Expand All @@ -46,10 +46,12 @@ const ReportActionItemCreated = (props) => {
]}
>
<View style={[styles.justifyContentCenter, styles.alignItemsCenter, styles.flex1]}>
<RoomHeaderAvatars
icons={icons}
shouldShowLargeAvatars={isPolicyExpenseChat}
/>
<Pressable onPress={() => ReportUtils.navigateToDetailsPage(props.report)}>
<RoomHeaderAvatars
icons={icons}
shouldShowLargeAvatars={isPolicyExpenseChat}
/>
</Pressable>
<ReportWelcomeText report={props.report} />
</View>
</View>
Expand Down

0 comments on commit c16d2eb

Please sign in to comment.