@@ -8,6 +8,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
88import { useProductTrainingContext } from '@components/ProductTrainingContext' ;
99import ScreenWrapper from '@components/ScreenWrapper' ;
1010import TabSelector from '@components/TabSelector/TabSelector' ;
11+ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
1112import useLocalize from '@hooks/useLocalize' ;
1213import useOnyx from '@hooks/useOnyx' ;
1314import usePermissions from '@hooks/usePermissions' ;
@@ -22,7 +23,7 @@ import Navigation from '@libs/Navigation/Navigation';
2223import OnyxTabNavigator , { TabScreenWithFocusTrapWrapper , TopTab } from '@libs/Navigation/OnyxTabNavigator' ;
2324import { getIsUserSubmittedExpenseOrScannedReceipt } from '@libs/OptionsListUtils' ;
2425import Performance from '@libs/Performance' ;
25- import { getPerDiemCustomUnit , getPerDiemCustomUnits } from '@libs/PolicyUtils' ;
26+ import { getActivePoliciesWithExpenseChatAndPerDiemEnabled } from '@libs/PolicyUtils' ;
2627import { getPayeeName } from '@libs/ReportUtils' ;
2728import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper' ;
2829import type { IOURequestType } from '@userActions/IOU' ;
@@ -61,7 +62,6 @@ function IOURequestStartPage({
6162 const [ parentReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ report ?. parentReportID } ` , { canBeMissing : true } ) ;
6263 const policy = usePolicy ( report ?. policyID ) ;
6364 const [ selectedTab , selectedTabResult ] = useOnyx ( `${ ONYXKEYS . COLLECTION . SELECTED_TAB } ${ CONST . TAB . IOU_REQUEST_TYPE } ` , { canBeMissing : true } ) ;
64- const [ session ] = useOnyx ( ONYXKEYS . SESSION , { canBeMissing : false } ) ;
6565 const isLoadingSelectedTab = shouldUseTab ? isLoadingOnyxValue ( selectedTabResult ) : false ;
6666 const [ transaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ getNonEmptyStringOnyxID ( route ?. params . transactionID ) } ` , { canBeMissing : true } ) ;
6767 const [ allPolicies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { canBeMissing : false } ) ;
@@ -85,14 +85,14 @@ function IOURequestStartPage({
8585 [ CONST . IOU . TYPE . CREATE ] : translate ( 'iou.createExpense' ) ,
8686 } ;
8787
88- const isFromGlobalCreate = isEmptyObject ( report ) ;
89- const perDiemCustomUnits = getPerDiemCustomUnits ( allPolicies , session ?. email ) ;
90- const doesPerDiemPolicyExist = perDiemCustomUnits . length > 0 ;
91- const moreThanOnePerDiemExist = perDiemCustomUnits . length > 1 ;
92- const currentPolicyPerDiemUnit = getPerDiemCustomUnit ( policy ) ;
93- const doesCurrentPolicyPerDiemExist = ! isEmptyObject ( currentPolicyPerDiemUnit ) && ! ! currentPolicyPerDiemUnit . enabled ;
88+ const isFromGlobalCreate = isEmptyObject ( report ?. reportID ) ;
89+ const { login : currentUserLogin } = useCurrentUserPersonalDetails ( ) ;
90+ const policiesWithPerDiemEnabled = useMemo ( ( ) => getActivePoliciesWithExpenseChatAndPerDiemEnabled ( allPolicies , currentUserLogin ) , [ allPolicies , currentUserLogin ] ) ;
91+ const doesPerDiemPolicyExist = policiesWithPerDiemEnabled . length > 0 ;
92+ const moreThanOnePerDiemExist = policiesWithPerDiemEnabled . length > 1 ;
93+ const hasCurrentPolicyPerDiemEnabled = ! ! policy ?. arePerDiemRatesEnabled ;
9494 const shouldShowPerDiemOption =
95- iouType !== CONST . IOU . TYPE . SPLIT && iouType !== CONST . IOU . TYPE . TRACK && ( ( ! isFromGlobalCreate && doesCurrentPolicyPerDiemExist ) || ( isFromGlobalCreate && doesPerDiemPolicyExist ) ) ;
95+ iouType !== CONST . IOU . TYPE . SPLIT && iouType !== CONST . IOU . TYPE . TRACK && ( ( ! isFromGlobalCreate && hasCurrentPolicyPerDiemEnabled ) || ( isFromGlobalCreate && doesPerDiemPolicyExist ) ) ;
9696
9797 const transactionRequestType = useMemo ( ( ) => {
9898 if ( ! transaction ?. iouRequestType ) {
@@ -283,15 +283,15 @@ function IOURequestStartPage({
283283 < TopTab . Screen name = { CONST . TAB_REQUEST . PER_DIEM } >
284284 { ( ) => (
285285 < TabScreenWithFocusTrapWrapper >
286- { moreThanOnePerDiemExist && ! doesCurrentPolicyPerDiemExist ? (
286+ { moreThanOnePerDiemExist && ! hasCurrentPolicyPerDiemEnabled ? (
287287 < IOURequestStepPerDiemWorkspace
288288 route = { route }
289289 navigation = { navigation }
290290 />
291291 ) : (
292292 < IOURequestStepDestination
293293 openedFromStartPage
294- explicitPolicyID = { moreThanOnePerDiemExist ? undefined : perDiemCustomUnits . at ( 0 ) ?. policyID }
294+ explicitPolicyID = { moreThanOnePerDiemExist ? undefined : policiesWithPerDiemEnabled . at ( 0 ) ?. id }
295295 route = { route }
296296 navigation = { navigation }
297297 />
0 commit comments