Skip to content
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

Disable go to profile page for optimistic user #23802

Merged
merged 8 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import styles from '../styles/styles';
import * as ReportUtils from '../libs/ReportUtils';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import OptionsSelector from './OptionsSelector';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -140,7 +141,14 @@ function MoneyRequestConfirmationList(props) {
const unselectedParticipants = _.filter(props.selectedParticipants, (participant) => !participant.selected);
if (props.hasMultipleParticipants) {
const formattedSelectedParticipants = getParticipantsWithAmount(selectedParticipants);
const formattedParticipantsList = _.union(formattedSelectedParticipants, unselectedParticipants);
let formattedParticipantsList = _.union(formattedSelectedParticipants, unselectedParticipants);

if (!canModifyParticipants) {
formattedParticipantsList = _.map(formattedParticipantsList, (participant) => ({
...participant,
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
}));
}

const myIOUAmount = IOUUtils.calculateAmount(selectedParticipants.length, props.iouAmount, true);
const formattedPayeeOption = OptionsListUtils.getIOUConfirmationOptionsFromPayeePersonalDetail(
Expand All @@ -164,9 +172,13 @@ function MoneyRequestConfirmationList(props) {
},
);
} else {
const formattedSelectedParticipants = _.map(props.selectedParticipants, (participant) => ({
...participant,
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #33976.
workspace's accountID is always 0, which resulting in it's always disabled. :)

}));
sections.push({
title: translate('common.to'),
data: props.selectedParticipants,
data: formattedSelectedParticipants,
shouldShow: true,
indexOffset: 0,
});
Expand All @@ -182,6 +194,7 @@ function MoneyRequestConfirmationList(props) {
payeePersonalDetails,
translate,
shouldDisablePaidBySection,
canModifyParticipants,
]);

const selectedOptions = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/OptionsList/BaseOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class BaseOptionsList extends Component {
* @return {Component}
*/
renderItem({item, index, section}) {
const isDisabled = this.props.isDisabled || section.isDisabled;
const isDisabled = this.props.isDisabled || section.isDisabled || !!item.isDisabled;
return (
<OptionRow
option={item}
Expand Down
16 changes: 10 additions & 6 deletions src/components/ReportWelcomeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ function ReportWelcomeText(props) {
{_.map(displayNamesWithTooltips, ({displayName, pronouns, accountID}, index) => (
<Text key={`${displayName}${pronouns}${index}`}>
<UserDetailsTooltip accountID={accountID}>
<Text
style={[styles.textStrong]}
onPress={() => Navigation.navigate(ROUTES.getProfileRoute(accountID))}
>
{displayName}
</Text>
{ReportUtils.isOptimisticPersonalDetail(accountID) ? (
<Text style={[styles.textStrong]}>{displayName}</Text>
) : (
<Text
style={[styles.textStrong]}
onPress={() => Navigation.navigate(ROUTES.getProfileRoute(accountID))}
>
{displayName}
</Text>
)}
</UserDetailsTooltip>
{!_.isEmpty(pronouns) && <Text>{` (${pronouns})`}</Text>}
{index === displayNamesWithTooltips.length - 1 && <Text>.</Text>}
Expand Down
22 changes: 22 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,26 @@ function getBankAccountRoute(report) {
return isPolicyExpenseChat(report) ? ROUTES.getBankAccountRoute('', report.policyID) : ROUTES.SETTINGS_ADD_BANK_ACCOUNT;
}

/**
* Check if personal detail of accountID is empty or optimistic data
* @param {String} accountID user accountID
* @returns {Boolean}
*/
function isOptimisticPersonalDetail(accountID) {
return _.isEmpty(allPersonalDetails[accountID]) || !!allPersonalDetails[accountID].isOptimisticPersonalDetail;
}

/**
* Check if report is a DM and personal detail of participant is optimistic data
* @param {String} report
* @returns {Boolean}
*/
function shouldDisableDetailPage(report) {
const participants = lodashGet(report, 'participantAccountIDs', []);
const isMultipleParticipant = participants.length > 1;
return !isMultipleParticipant && isOptimisticPersonalDetail(participants[0]) && !report.parentReportID;
}

/**
* Checks if a report is a task report from a policy expense chat.
*
Expand Down Expand Up @@ -2879,6 +2899,8 @@ export {
getAllPolicyReports,
getIOUReportActionMessage,
getDisplayNameForParticipant,
isOptimisticPersonalDetail,
shouldDisableDetailPage,
isChatReport,
isCurrentUserSubmitter,
isExpenseReport,
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
accountID,
avatar: UserUtils.getDefaultAvatarURL(accountID),
displayName: login,
isOptimisticPersonalDetail: true,
};

failurePersonalDetails[accountID] = allPersonalDetails[accountID] || null;
Expand Down
5 changes: 4 additions & 1 deletion src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ const getAllParticipants = (report, personalDetails, translate) => {
};

function ReportParticipantsPage(props) {
const participants = getAllParticipants(props.report, props.personalDetails, props.translate);
const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({
...participant,
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
}));

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function HeaderView(props) {
const icons = ReportUtils.getIcons(reportHeaderData, props.personalDetails);
const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
const shouldShowBorderBottom = !isTaskReport || !props.isSmallScreenWidth;
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);

return (
<View
Expand Down Expand Up @@ -164,7 +165,7 @@ function HeaderView(props) {
<PressableWithoutFeedback
onPress={() => ReportUtils.navigateToDetailsPage(props.report)}
style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}
disabled={isTaskReport && !ReportUtils.isOpenTaskReport(props.report)}
disabled={(isTaskReport && !ReportUtils.isOpenTaskReport(props.report)) || shouldDisableDetailPage}
accessibilityLabel={title}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionItemCreated.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function ReportActionItemCreated(props) {
}

const icons = ReportUtils.getIcons(props.report, props.personalDetails);
const shouldDisableDetailPage = ReportUtils.shouldDisableDetailPage(props.report);

return (
<OfflineWithFeedback
Expand All @@ -77,6 +78,7 @@ function ReportActionItemCreated(props) {
style={[styles.mh5, styles.mb3, styles.alignSelfStart]}
accessibilityLabel={props.translate('common.details')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
disabled={shouldDisableDetailPage}
>
<MultipleAvatars
icons={icons}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodashGet from 'lodash/get';
import React, {useCallback} from 'react';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
Expand Down Expand Up @@ -113,13 +113,19 @@ function ReportActionItemSingle(props) {
}
}, [isWorkspaceActor, props.report.reportID, actorAccountID, props.action.delegateAccountID]);

const shouldDisableDetailPage = useMemo(
() => !isWorkspaceActor && ReportUtils.isOptimisticPersonalDetail(props.action.delegateAccountID ? props.action.delegateAccountID : actorAccountID),
[props.action, isWorkspaceActor, actorAccountID],
);

return (
<View style={props.wrapperStyles}>
<PressableWithoutFeedback
style={[styles.alignSelfStart, styles.mr3]}
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={showActorDetails}
disabled={shouldDisableDetailPage}
accessibilityLabel={actorHint}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
Expand Down Expand Up @@ -158,6 +164,7 @@ function ReportActionItemSingle(props) {
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={showActorDetails}
disabled={shouldDisableDetailPage}
accessibilityLabel={actorHint}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
Expand Down
Loading