Skip to content

Commit 577993b

Browse files
Merge pull request #58677 from nkdengineer/fix/58564
fix: Only show the travel modal if the user is enabling travel
2 parents c46c360 + ac572e0 commit 577993b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/components/PopoverMenu.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {useCallback, useLayoutEffect, useMemo, useState} from 'react';
55
import {StyleSheet, View} from 'react-native';
66
import type {GestureResponderEvent, StyleProp, TextStyle, ViewStyle} from 'react-native';
77
import type {ModalProps} from 'react-native-modal';
8+
import type {SvgProps} from 'react-native-svg';
89
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
910
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
1011
import useResponsiveLayout from '@hooks/useResponsiveLayout';
@@ -56,6 +57,8 @@ type PopoverMenuItem = MenuItemProps & {
5657
shouldCloseAllModals?: boolean;
5758

5859
pendingAction?: PendingAction;
60+
61+
rightIcon?: React.FC<SvgProps>;
5962
};
6063

6164
type PopoverModalProps = Pick<ModalProps, 'animationIn' | 'animationOut' | 'animationInTiming' | 'animationOutTiming'> &
@@ -289,6 +292,8 @@ function PopoverMenu({
289292
focused={focusedIndex === menuIndex}
290293
shouldShowSelectedItemCheck={shouldShowSelectedItemCheck}
291294
shouldCheckActionAllowedOnPress={false}
295+
iconRight={item.rightIcon}
296+
shouldShowRightIcon={!!item.rightIcon}
292297
onFocus={() => {
293298
if (!shouldUpdateFocusedIndex) {
294299
return;

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import HybridAppModule from '@expensify/react-native-hybrid-app';
22
import {useIsFocused} from '@react-navigation/native';
3+
import {Str} from 'expensify-common';
34
import type {ImageContentFit} from 'expo-image';
45
import type {ForwardedRef} from 'react';
56
import React, {forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
@@ -24,7 +25,7 @@ import useTheme from '@hooks/useTheme';
2425
import useThemeStyles from '@hooks/useThemeStyles';
2526
import useWindowDimensions from '@hooks/useWindowDimensions';
2627
import {startMoneyRequest} from '@libs/actions/IOU';
27-
import {openExternalLink, openOldDotLink} from '@libs/actions/Link';
28+
import {openExternalLink, openOldDotLink, openTravelDotLink} from '@libs/actions/Link';
2829
import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation';
2930
import {createNewReport, startNewChat} from '@libs/actions/Report';
3031
import {isAnonymousUser} from '@libs/actions/Session';
@@ -199,6 +200,10 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
199200
const isFocused = useIsFocused();
200201
const prevIsFocused = usePrevious(isFocused);
201202
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);
202207

203208
const {canUseSpotnanaTravel, canUseTableReportView} = usePermissions();
204209
const canSendInvoice = useMemo(() => canSendInvoicePolicyUtils(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
@@ -449,6 +454,28 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
449454
const canModifyTask = canModifyTaskUtils(viewTourTaskReport, currentUserPersonalDetails.accountID);
450455
const canActionTask = canActionTaskUtils(viewTourTaskReport, currentUserPersonalDetails.accountID);
451456

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+
452479
const menuItems = [
453480
...expenseMenuItems,
454481
...(canUseTableReportView
@@ -516,7 +543,8 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
516543
{
517544
icon: Expensicons.Suitcase,
518545
text: translate('travel.bookTravel'),
519-
onSelected: () => interceptAnonymousUser(() => Navigation.navigate(ROUTES.TRAVEL_MY_TRIPS)),
546+
rightIcon: isTravelEnabled ? Expensicons.NewWindow : undefined,
547+
onSelected: () => interceptAnonymousUser(() => openTravel()),
520548
},
521549
]
522550
: []),

0 commit comments

Comments
 (0)