11import mapValues from 'lodash/mapValues' ;
22import React , { useCallback , useMemo , useState } from 'react' ;
33import { View } from 'react-native' ;
4- import type { OnyxEntry } from 'react-native-onyx' ;
4+ import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
55import ConfirmModal from '@components/ConfirmModal' ;
66import * as Expensicons from '@components/Icon/Expensicons' ;
77import MenuItem from '@components/MenuItem' ;
88import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription' ;
99import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
10+ import { usePolicyCategories , usePolicyTags } from '@components/OnyxProvider' ;
1011import ReceiptAudit , { ReceiptAuditMessages } from '@components/ReceiptAudit' ;
1112import ReceiptEmptyState from '@components/ReceiptEmptyState' ;
1213import Switch from '@components/Switch' ;
@@ -81,9 +82,15 @@ import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction';
8182import ReportActionItemImage from './ReportActionItemImage' ;
8283
8384type MoneyRequestViewProps = {
85+ /** All the data of the report collection */
86+ allReports : OnyxCollection < OnyxTypes . Report > ;
87+
8488 /** The report currently being looked at */
8589 report : OnyxEntry < OnyxTypes . Report > ;
8690
91+ /** Policy that the report belongs to */
92+ policy : OnyxEntry < OnyxTypes . Policy > ;
93+
8794 /** Whether we should display the animated banner above the component */
8895 shouldShowAnimatedBackground : boolean ;
8996
@@ -108,24 +115,22 @@ const receiptImageViolationNames: OnyxTypes.ViolationName[] = [
108115
109116const receiptFieldViolationNames : OnyxTypes . ViolationName [ ] = [ CONST . VIOLATIONS . MODIFIED_AMOUNT , CONST . VIOLATIONS . MODIFIED_DATE ] ;
110117
111- function MoneyRequestView ( { report, shouldShowAnimatedBackground, readonly = false , updatedTransaction, isFromReviewDuplicates = false } : MoneyRequestViewProps ) {
118+ function MoneyRequestView ( { allReports , report, policy , shouldShowAnimatedBackground, readonly = false , updatedTransaction, isFromReviewDuplicates = false } : MoneyRequestViewProps ) {
112119 const styles = useThemeStyles ( ) ;
113120 const { isOffline} = useNetwork ( ) ;
114121 const { translate, toLocaleDigit} = useLocalize ( ) ;
115122 const { shouldUseNarrowLayout} = useResponsiveLayout ( ) ;
116123 const { getReportRHPActiveRoute} = useActiveRoute ( ) ;
117124 const parentReportID = report ?. parentReportID ;
118125 const policyID = report ?. policyID ;
119- const [ parentReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportID } ` , { canBeMissing : true } ) ;
120- const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReport ?. parentReportID } ` , {
121- selector : ( chatReportValue ) => chatReportValue && { reportID : chatReportValue . reportID , errorFields : chatReportValue . errorFields } ,
122- canBeMissing : true ,
123- } ) ;
124- const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , { canBeMissing : true } ) ;
125- const [ policyCategories ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ policyID } ` , { canBeMissing : true } ) ;
126- const [ transactionReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ updatedTransaction ?. reportID } ` , { canBeMissing : true } ) ;
126+ const parentReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportID } ` ] ;
127+ const chatReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReport ?. parentReportID } ` ] ;
128+ const allPolicyCategories = usePolicyCategories ( ) ;
129+ const policyCategories = allPolicyCategories ?. [ `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ policyID } ` ] ;
130+ const transactionReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ updatedTransaction ?. reportID } ` ] ;
127131 const targetPolicyID = updatedTransaction ?. reportID ? transactionReport ?. policyID : policyID ;
128- const [ policyTagList ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_TAGS } ${ targetPolicyID } ` , { canBeMissing : true } ) ;
132+ const allPolicyTags = usePolicyTags ( ) ;
133+ const policyTagList = allPolicyTags ?. [ `${ ONYXKEYS . COLLECTION . POLICY_TAGS } ${ targetPolicyID } ` ] ;
129134 const [ cardList ] = useOnyx ( ONYXKEYS . CARD_LIST , { canBeMissing : true } ) ;
130135 const [ parentReportActions ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportID } ` , {
131136 canEvict : false ,
0 commit comments