11import { hasSeenTourSelector } from '@selectors/Onboarding' ;
22import mapValues from 'lodash/mapValues' ;
3- import React , { useEffect , useMemo , useRef , useState } from 'react' ;
3+ import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
44import { View } from 'react-native' ;
55import type { StyleProp , ViewStyle } from 'react-native' ;
66import type { OnyxEntry } from 'react-native-onyx' ;
@@ -9,7 +9,6 @@ import AttachmentPicker from '@components/AttachmentPicker';
99import Icon from '@components/Icon' ;
1010import { ModalActions } from '@components/Modal/Global/ModalContext' ;
1111import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
12- import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
1312import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback' ;
1413import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus' ;
1514import ReceiptAudit , { ReceiptAuditMessages } from '@components/ReceiptAudit' ;
@@ -71,6 +70,7 @@ import CONST from '@src/CONST';
7170import ONYXKEYS from '@src/ONYXKEYS' ;
7271import ROUTES from '@src/ROUTES' ;
7372import type * as OnyxTypes from '@src/types/onyx' ;
73+ import type PersonalDetails from '@src/types/onyx/PersonalDetails' ;
7474import type { TransactionPendingFieldsKey } from '@src/types/onyx/Transaction' ;
7575import type { FileObject } from '@src/types/utils/Attachment' ;
7676import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
@@ -112,6 +112,13 @@ const receiptImageViolationNames = new Set<OnyxTypes.ViolationName>([
112112
113113const receiptFieldViolationNames = new Set < OnyxTypes . ViolationName > ( [ CONST . VIOLATIONS . MODIFIED_AMOUNT , CONST . VIOLATIONS . MODIFIED_DATE ] ) ;
114114
115+ const findConciergePersonalDetail = ( list : OnyxEntry < OnyxTypes . PersonalDetailsList > ) : OnyxEntry < PersonalDetails > => {
116+ if ( ! list ) {
117+ return undefined ;
118+ }
119+ return Object . values ( list ) . find ( ( detail ) : detail is PersonalDetails => detail ?. login === CONST . EMAIL . CONCIERGE ) ;
120+ } ;
121+
115122function MoneyRequestReceiptView ( {
116123 report,
117124 readonly = false ,
@@ -134,7 +141,17 @@ function MoneyRequestReceiptView({
134141 const [ introSelected ] = useOnyx ( ONYXKEYS . NVP_INTRO_SELECTED ) ;
135142 const [ isSelfTourViewed ] = useOnyx ( ONYXKEYS . NVP_ONBOARDING , { selector : hasSeenTourSelector } ) ;
136143 const [ betas ] = useOnyx ( ONYXKEYS . BETAS ) ;
137- const personalDetails = usePersonalDetails ( ) ;
144+ const [ conciergePersonalDetail ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , { selector : findConciergePersonalDetail } ) ;
145+ const reportOwnerSelector = useCallback (
146+ ( list : OnyxEntry < OnyxTypes . PersonalDetailsList > ) : OnyxEntry < PersonalDetails > => ( report ?. ownerAccountID ? ( list ?. [ report . ownerAccountID ] ?? undefined ) : undefined ) ,
147+ [ report ?. ownerAccountID ] ,
148+ ) ;
149+ const [ reportOwnerPersonalDetail ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , { selector : reportOwnerSelector } , [ reportOwnerSelector ] ) ;
150+ const chatReportOwnerSelector = useCallback (
151+ ( list : OnyxEntry < OnyxTypes . PersonalDetailsList > ) : OnyxEntry < PersonalDetails > => ( chatReport ?. ownerAccountID ? ( list ?. [ chatReport . ownerAccountID ] ?? undefined ) : undefined ) ,
152+ [ chatReport ?. ownerAccountID ] ,
153+ ) ;
154+ const [ chatReportOwnerPersonalDetail ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , { selector : chatReportOwnerSelector } , [ chatReportOwnerSelector ] ) ;
138155 const delegateAccountID = useDelegateAccountID ( ) ;
139156
140157 const [ isLoading , setIsLoading ] = useState ( true ) ;
@@ -163,7 +180,8 @@ function MoneyRequestReceiptView({
163180 const didReceiptScanSucceed = hasReceipt && didReceiptScanSucceedTransactionUtils ( transaction ) ;
164181 const isInvoice = isInvoiceReport ( moneyRequestReport ) ;
165182 const isChatReportArchived = useReportIsArchived ( moneyRequestReport ?. chatReportID ) ;
166- const { login : currentUserLogin , accountID : currentUserAccountID , timezone : currentUserTimezone } = useCurrentUserPersonalDetails ( ) ;
183+ const currentUserPersonalDetail = useCurrentUserPersonalDetails ( ) ;
184+ const { login : currentUserLogin , accountID : currentUserAccountID , timezone : currentUserTimezone } = currentUserPersonalDetail ;
167185 const theme = useTheme ( ) ;
168186 const ancestors = useAncestors ( report ) ;
169187 const { hovered, bind : hoverBind } = useHover ( ) ;
@@ -368,7 +386,19 @@ function MoneyRequestReceiptView({
368386 }
369387 if ( transaction ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD ) {
370388 if ( chatReport ?. reportID && getCreationReportErrors ( chatReport ) ) {
371- navigateToConciergeChatAndDeleteReport ( chatReport . reportID , conciergeReportID , currentUserAccountID , introSelected , isSelfTourViewed , betas , personalDetails , true , true ) ;
389+ navigateToConciergeChatAndDeleteReport (
390+ chatReport . reportID ,
391+ conciergeReportID ,
392+ currentUserAccountID ,
393+ introSelected ,
394+ isSelfTourViewed ,
395+ betas ,
396+ chatReportOwnerPersonalDetail ,
397+ currentUserPersonalDetail ,
398+ conciergePersonalDetail ,
399+ true ,
400+ true ,
401+ ) ;
372402 return ;
373403 }
374404 if ( parentReportAction ) {
@@ -405,7 +435,19 @@ function MoneyRequestReceiptView({
405435 if ( isInNarrowPaneModal ) {
406436 Navigation . goBack ( ) ;
407437 }
408- navigateToConciergeChatAndDeleteReport ( report . reportID , conciergeReportID , currentUserAccountID , introSelected , isSelfTourViewed , betas , personalDetails , true , true ) ;
438+ navigateToConciergeChatAndDeleteReport (
439+ report . reportID ,
440+ conciergeReportID ,
441+ currentUserAccountID ,
442+ introSelected ,
443+ isSelfTourViewed ,
444+ betas ,
445+ reportOwnerPersonalDetail ,
446+ currentUserPersonalDetail ,
447+ conciergePersonalDetail ,
448+ true ,
449+ true ,
450+ ) ;
409451 }
410452 } ;
411453
0 commit comments