1
1
import HybridAppModule from '@expensify/react-native-hybrid-app' ;
2
2
import { useIsFocused } from '@react-navigation/native' ;
3
+ import { Str } from 'expensify-common' ;
3
4
import type { ImageContentFit } from 'expo-image' ;
4
5
import type { ForwardedRef } from 'react' ;
5
6
import React , { forwardRef , useCallback , useContext , useEffect , useImperativeHandle , useMemo , useRef , useState } from 'react' ;
@@ -24,7 +25,7 @@ import useTheme from '@hooks/useTheme';
24
25
import useThemeStyles from '@hooks/useThemeStyles' ;
25
26
import useWindowDimensions from '@hooks/useWindowDimensions' ;
26
27
import { startMoneyRequest } from '@libs/actions/IOU' ;
27
- import { openExternalLink , openOldDotLink } from '@libs/actions/Link' ;
28
+ import { openExternalLink , openOldDotLink , openTravelDotLink } from '@libs/actions/Link' ;
28
29
import { navigateToQuickAction } from '@libs/actions/QuickActionNavigation' ;
29
30
import { createNewReport , startNewChat } from '@libs/actions/Report' ;
30
31
import { isAnonymousUser } from '@libs/actions/Session' ;
@@ -199,6 +200,10 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
199
200
const isFocused = useIsFocused ( ) ;
200
201
const prevIsFocused = usePrevious ( isFocused ) ;
201
202
const { isOffline} = useNetwork ( ) ;
203
+ const { isBlockedFromSpotnanaTravel} = usePermissions ( ) ;
204
+ const [ primaryLogin ] = useOnyx ( ONYXKEYS . ACCOUNT , { selector : ( account ) => account ?. primaryLogin } ) ;
205
+ const primaryContactMethod = primaryLogin ?? session ?. email ?? '' ;
206
+ const [ travelSettings ] = useOnyx ( ONYXKEYS . NVP_TRAVEL_SETTINGS ) ;
202
207
203
208
const { canUseSpotnanaTravel, canUseTableReportView} = usePermissions ( ) ;
204
209
const canSendInvoice = useMemo ( ( ) => canSendInvoicePolicyUtils ( allPolicies as OnyxCollection < OnyxTypes . Policy > , session ?. email ) , [ allPolicies , session ?. email ] ) ;
@@ -449,6 +454,28 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
449
454
const canModifyTask = canModifyTaskUtils ( viewTourTaskReport , currentUserPersonalDetails . accountID ) ;
450
455
const canActionTask = canActionTaskUtils ( viewTourTaskReport , currentUserPersonalDetails . accountID ) ;
451
456
457
+ const isTravelEnabled = useMemo ( ( ) => {
458
+ if ( ! ! isBlockedFromSpotnanaTravel || ! primaryContactMethod || Str . isSMSLogin ( primaryContactMethod ) || ! isPaidGroupPolicy ( activePolicy ) ) {
459
+ return false ;
460
+ }
461
+
462
+ const isPolicyProvisioned = activePolicy ?. travelSettings ?. spotnanaCompanyID ?? activePolicy ?. travelSettings ?. associatedTravelDomainAccountID ;
463
+
464
+ return activePolicy ?. travelSettings ?. hasAcceptedTerms ?? ( travelSettings ?. hasAcceptedTerms && isPolicyProvisioned ) ;
465
+ } , [ activePolicy , isBlockedFromSpotnanaTravel , primaryContactMethod , travelSettings ?. hasAcceptedTerms ] ) ;
466
+
467
+ const openTravel = useCallback ( ( ) => {
468
+ if ( isTravelEnabled ) {
469
+ openTravelDotLink ( activePolicy ?. id )
470
+ ?. then ( ( ) => { } )
471
+ ?. catch ( ( ) => {
472
+ Navigation . navigate ( ROUTES . TRAVEL_MY_TRIPS ) ;
473
+ } ) ;
474
+ } else {
475
+ Navigation . navigate ( ROUTES . TRAVEL_MY_TRIPS ) ;
476
+ }
477
+ } , [ activePolicy , isTravelEnabled ] ) ;
478
+
452
479
const menuItems = [
453
480
...expenseMenuItems ,
454
481
...( canUseTableReportView
@@ -516,7 +543,8 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
516
543
{
517
544
icon : Expensicons . Suitcase ,
518
545
text : translate ( 'travel.bookTravel' ) ,
519
- onSelected : ( ) => interceptAnonymousUser ( ( ) => Navigation . navigate ( ROUTES . TRAVEL_MY_TRIPS ) ) ,
546
+ rightIcon : isTravelEnabled ? Expensicons . NewWindow : undefined ,
547
+ onSelected : ( ) => interceptAnonymousUser ( ( ) => openTravel ( ) ) ,
520
548
} ,
521
549
]
522
550
: [ ] ) ,
0 commit comments