Skip to content

Commit 577152d

Browse files
authored
Merge pull request #23802 from dukenv0307/fix/22691
Disable go to profile page for optimistic user
2 parents d228257 + b0c21aa commit 577152d

9 files changed

+65
-12
lines changed

src/components/MoneyRequestConfirmationList.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import {withOnyx} from 'react-native-onyx';
44
import _ from 'underscore';
55
import styles from '../styles/styles';
6+
import * as ReportUtils from '../libs/ReportUtils';
67
import * as OptionsListUtils from '../libs/OptionsListUtils';
78
import OptionsSelector from './OptionsSelector';
89
import ONYXKEYS from '../ONYXKEYS';
@@ -140,7 +141,14 @@ function MoneyRequestConfirmationList(props) {
140141
const unselectedParticipants = _.filter(props.selectedParticipants, (participant) => !participant.selected);
141142
if (props.hasMultipleParticipants) {
142143
const formattedSelectedParticipants = getParticipantsWithAmount(selectedParticipants);
143-
const formattedParticipantsList = _.union(formattedSelectedParticipants, unselectedParticipants);
144+
let formattedParticipantsList = _.union(formattedSelectedParticipants, unselectedParticipants);
145+
146+
if (!canModifyParticipants) {
147+
formattedParticipantsList = _.map(formattedParticipantsList, (participant) => ({
148+
...participant,
149+
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
150+
}));
151+
}
144152

145153
const myIOUAmount = IOUUtils.calculateAmount(selectedParticipants.length, props.iouAmount, true);
146154
const formattedPayeeOption = OptionsListUtils.getIOUConfirmationOptionsFromPayeePersonalDetail(
@@ -164,9 +172,13 @@ function MoneyRequestConfirmationList(props) {
164172
},
165173
);
166174
} else {
175+
const formattedSelectedParticipants = _.map(props.selectedParticipants, (participant) => ({
176+
...participant,
177+
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
178+
}));
167179
sections.push({
168180
title: translate('common.to'),
169-
data: props.selectedParticipants,
181+
data: formattedSelectedParticipants,
170182
shouldShow: true,
171183
indexOffset: 0,
172184
});
@@ -182,6 +194,7 @@ function MoneyRequestConfirmationList(props) {
182194
payeePersonalDetails,
183195
translate,
184196
shouldDisablePaidBySection,
197+
canModifyParticipants,
185198
]);
186199

187200
const selectedOptions = useMemo(() => {

src/components/OptionsList/BaseOptionsList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class BaseOptionsList extends Component {
160160
* @return {Component}
161161
*/
162162
renderItem({item, index, section}) {
163-
const isDisabled = this.props.isDisabled || section.isDisabled;
163+
const isDisabled = this.props.isDisabled || section.isDisabled || !!item.isDisabled;
164164
return (
165165
<OptionRow
166166
option={item}

src/components/ReportWelcomeText.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ function ReportWelcomeText(props) {
9999
{_.map(displayNamesWithTooltips, ({displayName, pronouns, accountID}, index) => (
100100
<Text key={`${displayName}${pronouns}${index}`}>
101101
<UserDetailsTooltip accountID={accountID}>
102-
<Text
103-
style={[styles.textStrong]}
104-
onPress={() => Navigation.navigate(ROUTES.getProfileRoute(accountID))}
105-
>
106-
{displayName}
107-
</Text>
102+
{ReportUtils.isOptimisticPersonalDetail(accountID) ? (
103+
<Text style={[styles.textStrong]}>{displayName}</Text>
104+
) : (
105+
<Text
106+
style={[styles.textStrong]}
107+
onPress={() => Navigation.navigate(ROUTES.getProfileRoute(accountID))}
108+
>
109+
{displayName}
110+
</Text>
111+
)}
108112
</UserDetailsTooltip>
109113
{!_.isEmpty(pronouns) && <Text>{` (${pronouns})`}</Text>}
110114
{index === displayNamesWithTooltips.length - 1 && <Text>.</Text>}

src/libs/ReportUtils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,26 @@ function getBankAccountRoute(report) {
396396
return isPolicyExpenseChat(report) ? ROUTES.getBankAccountRoute('', report.policyID) : ROUTES.SETTINGS_ADD_BANK_ACCOUNT;
397397
}
398398

399+
/**
400+
* Check if personal detail of accountID is empty or optimistic data
401+
* @param {String} accountID user accountID
402+
* @returns {Boolean}
403+
*/
404+
function isOptimisticPersonalDetail(accountID) {
405+
return _.isEmpty(allPersonalDetails[accountID]) || !!allPersonalDetails[accountID].isOptimisticPersonalDetail;
406+
}
407+
408+
/**
409+
* Check if report is a DM and personal detail of participant is optimistic data
410+
* @param {String} report
411+
* @returns {Boolean}
412+
*/
413+
function shouldDisableDetailPage(report) {
414+
const participants = lodashGet(report, 'participantAccountIDs', []);
415+
const isMultipleParticipant = participants.length > 1;
416+
return !isMultipleParticipant && isOptimisticPersonalDetail(participants[0]) && !report.parentReportID;
417+
}
418+
399419
/**
400420
* Checks if a report is a task report from a policy expense chat.
401421
*
@@ -2879,6 +2899,8 @@ export {
28792899
getAllPolicyReports,
28802900
getIOUReportActionMessage,
28812901
getDisplayNameForParticipant,
2902+
isOptimisticPersonalDetail,
2903+
shouldDisableDetailPage,
28822904
isChatReport,
28832905
isCurrentUserSubmitter,
28842906
isExpenseReport,

src/libs/actions/Report.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
475475
accountID,
476476
avatar: UserUtils.getDefaultAvatarURL(accountID),
477477
displayName: login,
478+
isOptimisticPersonalDetail: true,
478479
};
479480

480481
failurePersonalDetails[accountID] = allPersonalDetails[accountID] || null;

src/pages/ReportParticipantsPage.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ const getAllParticipants = (report, personalDetails, translate) => {
8686
};
8787

8888
function ReportParticipantsPage(props) {
89-
const participants = getAllParticipants(props.report, props.personalDetails, props.translate);
89+
const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({
90+
...participant,
91+
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
92+
}));
9093

9194
return (
9295
<ScreenWrapper includeSafeAreaPaddingBottom={false}>

src/pages/home/HeaderView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ function HeaderView(props) {
134134
const icons = ReportUtils.getIcons(reportHeaderData, props.personalDetails);
135135
const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
136136
const shouldShowBorderBottom = !isTaskReport || !props.isSmallScreenWidth;
137+
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);
137138

138139
return (
139140
<View
@@ -164,7 +165,7 @@ function HeaderView(props) {
164165
<PressableWithoutFeedback
165166
onPress={() => ReportUtils.navigateToDetailsPage(props.report)}
166167
style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}
167-
disabled={isTaskReport && !ReportUtils.isOpenTaskReport(props.report)}
168+
disabled={(isTaskReport && !ReportUtils.isOpenTaskReport(props.report)) || shouldDisableDetailPage}
168169
accessibilityLabel={title}
169170
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
170171
>

src/pages/home/report/ReportActionItemCreated.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function ReportActionItemCreated(props) {
5353
}
5454

5555
const icons = ReportUtils.getIcons(props.report, props.personalDetails);
56+
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);
5657

5758
return (
5859
<OfflineWithFeedback
@@ -77,6 +78,7 @@ function ReportActionItemCreated(props) {
7778
style={[styles.mh5, styles.mb3, styles.alignSelfStart]}
7879
accessibilityLabel={props.translate('common.details')}
7980
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
81+
disabled={shouldDisableDetailPage}
8082
>
8183
<MultipleAvatars
8284
icons={icons}

src/pages/home/report/ReportActionItemSingle.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import lodashGet from 'lodash/get';
2-
import React, {useCallback} from 'react';
2+
import React, {useCallback, useMemo} from 'react';
33
import {View} from 'react-native';
44
import PropTypes from 'prop-types';
55
import _ from 'underscore';
@@ -113,13 +113,19 @@ function ReportActionItemSingle(props) {
113113
}
114114
}, [isWorkspaceActor, props.report.reportID, actorAccountID, props.action.delegateAccountID]);
115115

116+
const shouldDisableDetailPage = useMemo(
117+
() => !isWorkspaceActor && ReportUtils.isOptimisticPersonalDetail(props.action.delegateAccountID ? props.action.delegateAccountID : actorAccountID),
118+
[props.action, isWorkspaceActor, actorAccountID],
119+
);
120+
116121
return (
117122
<View style={props.wrapperStyles}>
118123
<PressableWithoutFeedback
119124
style={[styles.alignSelfStart, styles.mr3]}
120125
onPressIn={ControlSelection.block}
121126
onPressOut={ControlSelection.unblock}
122127
onPress={showActorDetails}
128+
disabled={shouldDisableDetailPage}
123129
accessibilityLabel={actorHint}
124130
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
125131
>
@@ -158,6 +164,7 @@ function ReportActionItemSingle(props) {
158164
onPressIn={ControlSelection.block}
159165
onPressOut={ControlSelection.unblock}
160166
onPress={showActorDetails}
167+
disabled={shouldDisableDetailPage}
161168
accessibilityLabel={actorHint}
162169
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
163170
>

0 commit comments

Comments
 (0)