@@ -6,19 +6,22 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
66import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback' ;
77import ReportActionAvatars from '@components/ReportActionAvatars' ;
88import useReportActionAvatars from '@components/ReportActionAvatars/useReportActionAvatars' ;
9+ import useReportPreviewSenderID from '@components/ReportActionAvatars/useReportPreviewSenderID' ;
910import Text from '@components/Text' ;
1011import Tooltip from '@components/Tooltip' ;
1112import useLocalize from '@hooks/useLocalize' ;
13+ import useOnyx from '@hooks/useOnyx' ;
1214import useStyleUtils from '@hooks/useStyleUtils' ;
1315import useTheme from '@hooks/useTheme' ;
1416import useThemeStyles from '@hooks/useThemeStyles' ;
1517import ControlSelection from '@libs/ControlSelection' ;
1618import DateUtils from '@libs/DateUtils' ;
1719import Navigation from '@libs/Navigation/Navigation' ;
1820import { getPersonalDetailByEmail } from '@libs/PersonalDetailsUtils' ;
19- import { getManagerOnVacation , getReportActionMessage , getSubmittedTo , getVacationer } from '@libs/ReportActionsUtils' ;
21+ import { getDelegateAccountIDFromReportAction , getManagerOnVacation , getReportActionMessage , getSubmittedTo , getVacationer } from '@libs/ReportActionsUtils' ;
2022import { isOptimisticPersonalDetail } from '@libs/ReportUtils' ;
2123import CONST from '@src/CONST' ;
24+ import ONYXKEYS from '@src/ONYXKEYS' ;
2225import ROUTES from '@src/ROUTES' ;
2326import type { Report , ReportAction } from '@src/types/onyx' ;
2427import type ChildrenProps from '@src/types/utils/ChildrenProps' ;
@@ -78,14 +81,26 @@ function ReportActionItemSingle({
7881 const StyleUtils = useStyleUtils ( ) ;
7982 const { translate} = useLocalize ( ) ;
8083
84+ const [ personalDetails ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
85+ canBeMissing : true ,
86+ } ) ;
87+
8188 const { avatarType, avatars, details, source} = useReportActionAvatars ( { report : potentialIOUReport ?? report , action} ) ;
8289
8390 const reportID = source . chatReport ?. reportID ;
8491 const iouReportID = source . iouReport ?. reportID ;
8592
8693 const [ primaryAvatar , secondaryAvatar ] = avatars ;
8794
88- const accountOwnerDetails = getPersonalDetailByEmail ( details . login ?? '' ) ;
95+ const reportPreviewSenderID = useReportPreviewSenderID ( {
96+ iouReport : potentialIOUReport ,
97+ action,
98+ chatReport : source . chatReport ,
99+ } ) ;
100+ const delegateAccountID = getDelegateAccountIDFromReportAction ( action ) ;
101+ const mainAccountID = delegateAccountID ? ( reportPreviewSenderID ?? potentialIOUReport ?. ownerAccountID ?? action ?. childOwnerAccountID ) : ( details . accountID ?? CONST . DEFAULT_NUMBER_ID ) ;
102+ const mainAccountLogin = mainAccountID ? ( personalDetails ?. [ mainAccountID ] ?. login ?? details . login ) : details . login ;
103+ const accountOwnerDetails = getPersonalDetailByEmail ( String ( mainAccountLogin ?? '' ) ) ;
89104
90105 // Vacation delegate details for submitted action
91106 const vacationer = getVacationer ( action ) ;
@@ -210,9 +225,7 @@ function ReportActionItemSingle({
210225 < ReportActionItemDate created = { action ?. created ?? '' } />
211226 </ View >
212227 ) : null }
213- { ! ! action ?. delegateAccountID && (
214- < Text style = { [ styles . chatDelegateMessage ] } > { translate ( 'delegate.onBehalfOfMessage' , { delegator : accountOwnerDetails ?. displayName ?? '' } ) } </ Text >
215- ) }
228+ { ! ! delegateAccountID && < Text style = { [ styles . chatDelegateMessage ] } > { translate ( 'delegate.onBehalfOfMessage' , { delegator : accountOwnerDetails ?. displayName ?? '' } ) } </ Text > }
216229 { ! ! vacationer && ! ! submittedTo && (
217230 < Text style = { [ styles . chatDelegateMessage ] } >
218231 { translate ( 'statusPage.toAsVacationDelegate' , {
0 commit comments