1- import { activePolicySelector } from '@selectors/Policy' ;
21import { Str } from 'expensify-common' ;
32import React , { useCallback , useContext , useEffect , useMemo , useState } from 'react' ;
43import { View } from 'react-native' ;
@@ -70,7 +69,6 @@ import {
7069 hasRoute as hasRouteTransactionUtils ,
7170 isCardTransaction as isCardTransactionTransactionUtils ,
7271 isDistanceRequest as isDistanceRequestTransactionUtils ,
73- isExpenseUnreported as isExpenseUnreportedTransactionUtils ,
7472 isManualDistanceRequest as isManualDistanceRequestTransactionUtils ,
7573 isPerDiemRequest as isPerDiemRequestTransactionUtils ,
7674 isScanning ,
@@ -131,6 +129,7 @@ function MoneyRequestView({
131129 const { isBetaEnabled} = usePermissions ( ) ;
132130 const { translate, toLocaleDigit} = useLocalize ( ) ;
133131 const { getReportRHPActiveRoute} = useActiveRoute ( ) ;
132+ const [ lastVisitedPath ] = useOnyx ( ONYXKEYS . LAST_VISITED_PATH , { canBeMissing : true } ) ;
134133
135134 const parentReportID = report ?. parentReportID ;
136135 const parentReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportID } ` ] ;
@@ -148,16 +147,10 @@ function MoneyRequestView({
148147 return originalMessage ?. IOUTransactionID ;
149148 } , [ parentReportAction ] ) ;
150149 const [ transaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ getNonEmptyStringOnyxID ( linkedTransactionID ) } ` , { canBeMissing : true } ) ;
151- const isExpenseUnreported = isExpenseUnreportedTransactionUtils ( updatedTransaction ?? transaction ) ;
152150
153- const [ activePolicyID ] = useOnyx ( ONYXKEYS . NVP_ACTIVE_POLICY_ID , { canBeMissing : true } ) ;
154- const [ activePolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ activePolicyID } ` , {
155- canBeMissing : true ,
156- selector : activePolicySelector ,
157- } ) ;
158151 // If the expense is unreported the policy should be the user's default policy, otherwise it should be the policy the expense was made for
159- const policy = isExpenseUnreported ? activePolicy : expensePolicy ;
160- const policyID = isExpenseUnreported ? activePolicy ?. id : report ?. policyID ;
152+ const policy = expensePolicy ;
153+ const policyID = report ?. policyID ;
161154
162155 const allPolicyCategories = usePolicyCategories ( ) ;
163156 const policyCategories = allPolicyCategories ?. [ `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ policyID } ` ] ;
@@ -250,9 +243,6 @@ function MoneyRequestView({
250243 // A flag for verifying that the current report is a sub-report of a expense chat
251244 // if the policy of the report is either Collect or Control, then this report must be tied to expense chat
252245 const isPolicyExpenseChat = isReportInGroupPolicy ( report ) ;
253-
254- const shouldShowPolicySpecificFields = isPolicyExpenseChat || isExpenseUnreported ;
255-
256246 const policyTagLists = useMemo ( ( ) => getTagLists ( policyTagList ) , [ policyTagList ] ) ;
257247
258248 const iouType = useMemo ( ( ) => {
@@ -272,19 +262,19 @@ function MoneyRequestView({
272262 // Flags for showing categories and tags
273263 // transactionCategory can be an empty string
274264 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
275- const shouldShowCategory = ( isPolicyExpenseChat && ( categoryForDisplay || hasEnabledOptions ( policyCategories ?? { } ) ) ) || isExpenseUnreported ;
265+ const shouldShowCategory = isPolicyExpenseChat && ( categoryForDisplay || hasEnabledOptions ( policyCategories ?? { } ) ) ;
276266 // transactionTag can be an empty string
277267 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
278- const shouldShowTag = shouldShowPolicySpecificFields && ( transactionTag || hasEnabledTags ( policyTagLists ) ) ;
279- const shouldShowBillable = shouldShowPolicySpecificFields && ( ! ! transactionBillable || ! ( policy ?. disabledFields ?. defaultBillable ?? true ) || ! ! updatedTransaction ?. billable ) ;
268+ const shouldShowTag = isPolicyExpenseChat && ( transactionTag || hasEnabledTags ( policyTagLists ) ) ;
269+ const shouldShowBillable = isPolicyExpenseChat && ( ! ! transactionBillable || ! ( policy ?. disabledFields ?. defaultBillable ?? true ) || ! ! updatedTransaction ?. billable ) ;
280270 const isCurrentTransactionReimbursableDifferentFromPolicyDefault =
281271 policy ?. defaultReimbursable !== undefined && ! ! ( updatedTransaction ?. reimbursable ?? transactionReimbursable ) !== policy . defaultReimbursable ;
282272 const shouldShowReimbursable =
283273 isPolicyExpenseChat && ( ! policy ?. disabledFields ?. reimbursable || isCurrentTransactionReimbursableDifferentFromPolicyDefault ) && ! isCardTransaction && ! isInvoice ;
284274 const canEditReimbursable = isEditable && canEditFieldOfMoneyRequest ( parentReportAction , CONST . EDIT_REQUEST_FIELD . REIMBURSABLE , undefined , isChatReportArchived ) ;
285275 const shouldShowAttendees = useMemo ( ( ) => shouldShowAttendeesTransactionUtils ( iouType , policy ) , [ iouType , policy ] ) ;
286276
287- const shouldShowTax = isTaxTrackingEnabled ( shouldShowPolicySpecificFields , policy , isDistanceRequest , isPerDiemRequest ) ;
277+ const shouldShowTax = isTaxTrackingEnabled ( isPolicyExpenseChat , policy , isDistanceRequest , isPerDiemRequest ) ;
288278 const tripID = getTripIDFromTransactionParentReportID ( parentReport ?. parentReportID ) ;
289279 const shouldShowViewTripDetails = hasReservationList ( transaction ) && ! ! tripID ;
290280
@@ -857,7 +847,13 @@ function MoneyRequestView({
857847 return ;
858848 }
859849 Navigation . navigate (
860- ROUTES . MONEY_REQUEST_STEP_REPORT . getRoute ( CONST . IOU . ACTION . EDIT , iouType , transaction ?. transactionID , report . reportID , getReportRHPActiveRoute ( ) ) ,
850+ ROUTES . MONEY_REQUEST_STEP_REPORT . getRoute (
851+ CONST . IOU . ACTION . EDIT ,
852+ iouType ,
853+ transaction ?. transactionID ,
854+ report . reportID ,
855+ getReportRHPActiveRoute ( ) || lastVisitedPath ,
856+ ) ,
861857 ) ;
862858 } }
863859 interactive = { canEditReport }
0 commit comments