Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {FallbackAvatar} from '@components/Icon/Expensicons';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {getDelegateAccountIDFromReportAction, getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {
getDefaultWorkspaceAvatar,
getDisplayNameForParticipant,
Expand Down Expand Up @@ -91,7 +91,8 @@ function useReportActionAvatars({
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [policyChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportIDAnnounce || chatReportIDAdmins}`, {canBeMissing: true});

const delegatePersonalDetails = action?.delegateAccountID ? personalDetails?.[action?.delegateAccountID] : undefined;
const delegateAccountID = getDelegateAccountIDFromReportAction(action);
const delegatePersonalDetails = delegateAccountID ? personalDetails?.[delegateAccountID] : undefined;
const actorAccountID = getReportActionActorAccountID(action, iouReport, chatReport, delegatePersonalDetails);

const isAInvoiceReport = isInvoiceReport(iouReport ?? null);
Expand Down Expand Up @@ -315,7 +316,7 @@ function useReportActionAvatars({
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
actorHint: String(shouldUsePrimaryAvatarID ? primaryAvatar.id : login || defaultDisplayName || fallbackDisplayName).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''),
accountID,
delegateAccountID: !isWorkspaceActor && delegatePersonalDetails ? actorAccountID : undefined,
delegateAccountID: !isWorkspaceActor && !!delegateAccountID ? actorAccountID : undefined,
},
source: {
iouReport,
Expand Down
22 changes: 22 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ function getOriginalMessage<T extends ReportActionName>(reportAction: OnyxInputO
return reportAction.originalMessage;
}

function getDelegateAccountIDFromReportAction(reportAction: OnyxInputOrEntry<ReportAction>): number | undefined {
if (!reportAction) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming from #80326 checklist: we're missing a case when using a copilot account, we also need to skip the actor being Concierge.

return undefined;
}

if (reportAction.delegateAccountID) {
return reportAction.delegateAccountID;
}

const originalMessage = getOriginalMessage(reportAction);
if (!originalMessage) {
return undefined;
}

if ('delegateAccountID' in originalMessage) {
return originalMessage.delegateAccountID;
}

return undefined;
}

function isExportIntegrationAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION> {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION;
}
Expand Down Expand Up @@ -3157,6 +3178,7 @@ export {
getVacationer,
getSubmittedTo,
getReceiptScanFailedMessage,
getDelegateAccountIDFromReportAction,
};

export type {LastVisibleMessage};
23 changes: 18 additions & 5 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ReportActionAvatars from '@components/ReportActionAvatars';
import useReportActionAvatars from '@components/ReportActionAvatars/useReportActionAvatars';
import useReportPreviewSenderID from '@components/ReportActionAvatars/useReportPreviewSenderID';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import DateUtils from '@libs/DateUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
import {getManagerOnVacation, getReportActionMessage, getSubmittedTo, getVacationer} from '@libs/ReportActionsUtils';
import {getDelegateAccountIDFromReportAction, getManagerOnVacation, getReportActionMessage, getSubmittedTo, getVacationer} from '@libs/ReportActionsUtils';
import {isOptimisticPersonalDetail} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report, ReportAction} from '@src/types/onyx';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
Expand Down Expand Up @@ -78,14 +81,26 @@ function ReportActionItemSingle({
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
canBeMissing: true,
});

const {avatarType, avatars, details, source} = useReportActionAvatars({report: potentialIOUReport ?? report, action});

const reportID = source.chatReport?.reportID;
const iouReportID = source.iouReport?.reportID;

const [primaryAvatar, secondaryAvatar] = avatars;

const accountOwnerDetails = getPersonalDetailByEmail(details.login ?? '');
const reportPreviewSenderID = useReportPreviewSenderID({
iouReport: potentialIOUReport,
action,
chatReport: source.chatReport,
});
const delegateAccountID = getDelegateAccountIDFromReportAction(action);
const mainAccountID = delegateAccountID ? (reportPreviewSenderID ?? potentialIOUReport?.ownerAccountID ?? action?.childOwnerAccountID) : (details.accountID ?? CONST.DEFAULT_NUMBER_ID);
const mainAccountLogin = mainAccountID ? (personalDetails?.[mainAccountID]?.login ?? details.login) : details.login;
const accountOwnerDetails = getPersonalDetailByEmail(String(mainAccountLogin ?? ''));

// Vacation delegate details for submitted action
const vacationer = getVacationer(action);
Expand Down Expand Up @@ -210,9 +225,7 @@ function ReportActionItemSingle({
<ReportActionItemDate created={action?.created ?? ''} />
</View>
) : null}
{!!action?.delegateAccountID && (
<Text style={[styles.chatDelegateMessage]}>{translate('delegate.onBehalfOfMessage', {delegator: accountOwnerDetails?.displayName ?? ''})}</Text>
)}
{!!delegateAccountID && <Text style={[styles.chatDelegateMessage]}>{translate('delegate.onBehalfOfMessage', {delegator: accountOwnerDetails?.displayName ?? ''})}</Text>}
{!!vacationer && !!submittedTo && (
<Text style={[styles.chatDelegateMessage]}>
{translate('statusPage.toAsVacationDelegate', {
Expand Down