Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/components/BookTravelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Str} from 'expensify-common';
import type {ReactElement} from 'react';
import React, {useCallback, useContext, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
Expand All @@ -12,7 +13,7 @@ import {openTravelDotLink} from '@libs/actions/Link';
import {cleanupTravelProvisioningSession} from '@libs/actions/Travel';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import {getAdminsPrivateEmailDomains, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getActivePolicies, getAdminsPrivateEmailDomains, isPaidGroupPolicy} from '@libs/PolicyUtils';
import colors from '@styles/theme/colors';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
Expand All @@ -29,6 +30,9 @@ import TextLink from './TextLink';

type BookTravelButtonProps = {
text: string;

/** Whether to render the error message below the button */
shouldRenderErrorMessageBelowButton?: boolean;
};

const navigateToAcceptTerms = (domain: string, isUserValidated?: boolean) => {
Expand All @@ -41,7 +45,7 @@ const navigateToAcceptTerms = (domain: string, isUserValidated?: boolean) => {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT.getRoute(Navigation.getActiveRoute(), ROUTES.TRAVEL_TCS.getRoute(domain)));
};

function BookTravelButton({text}: BookTravelButtonProps) {
function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: BookTravelButtonProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
Expand All @@ -56,7 +60,10 @@ function BookTravelButton({text}: BookTravelButtonProps) {
const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext);
const {isBlockedFromSpotnanaTravel} = usePermissions();
const [isPreventionModalVisible, setPreventionModalVisibility] = useState(false);

const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const {login: currentUserLogin} = useCurrentUserPersonalDetails();
const activePolicies = getActivePolicies(policies, currentUserLogin);
const groupPaidPolicies = activePolicies.filter((activePolicy) => activePolicy.type !== CONST.POLICY.TYPE.PERSONAL && isPaidGroupPolicy(activePolicy));
// Flag indicating whether NewDot was launched exclusively for Travel,
// e.g., when the user selects "Trips" from the Expensify Classic menu in HybridApp.
const [wasNewDotLaunchedJustForTravel] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY);
Expand Down Expand Up @@ -88,11 +95,16 @@ function BookTravelButton({text}: BookTravelButtonProps) {
return;
}

if (!isPaidGroupPolicy(policy)) {
if (groupPaidPolicies.length < 1) {
Navigation.navigate(ROUTES.TRAVEL_UPGRADE);
return;
}
Comment thread
twilight2294 marked this conversation as resolved.

if (!isPaidGroupPolicy(policy)) {
setErrorMessage(translate('travel.termsAndConditions.defaultWorkspaceError'));
return;
}

const isPolicyProvisioned = policy?.travelSettings?.spotnanaCompanyID ?? policy?.travelSettings?.associatedTravelDomainAccountID;
if (policy?.travelSettings?.hasAcceptedTerms ?? (travelSettings?.hasAcceptedTerms && isPolicyProvisioned)) {
openTravelDotLink(policy?.id)
Expand Down Expand Up @@ -145,11 +157,12 @@ function BookTravelButton({text}: BookTravelButtonProps) {
wasNewDotLaunchedJustForTravel,
setRootStatusBarEnabled,
isUserValidated,
groupPaidPolicies.length,
]);

return (
<>
{!!errorMessage && (
{!shouldRenderErrorMessageBelowButton && !!errorMessage && (
<DotIndicatorMessage
style={styles.mb1}
messages={{error: errorMessage}}
Expand All @@ -164,6 +177,13 @@ function BookTravelButton({text}: BookTravelButtonProps) {
success
large
/>
{shouldRenderErrorMessageBelowButton && !!errorMessage && (
<DotIndicatorMessage
style={[styles.mb1, styles.pt3]}
messages={{error: errorMessage}}
type="error"
/>
)}
<ConfirmModal
title={translate('travel.blockedFeatureModal.title')}
titleStyles={styles.textHeadlineH1}
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,8 @@ const translations = {
travelTermsAndConditions: 'terms & conditions',
agree: 'I agree to the ',
error: 'You must agree to the Expensify Travel terms & conditions to continue',
defaultWorkspaceError:
'You need to set a default workspace to enable Expensify Travel. Go to Settings > Workspaces > click the three vertical dots next to a workspace > Set as default workspace, then try again!',
},
flight: 'Flight',
flightDetails: {
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,8 @@ const translations = {
travelTermsAndConditions: 'términos y condiciones',
agree: 'Acepto los ',
error: 'Debes aceptar los términos y condiciones de Expensify Travel para continuar',
defaultWorkspaceError:
'Debes establecer un espacio de trabajo predeterminado para habilitar Expensify Travel. Ve a Configuración > Espacios de trabajo > haz clic en los tres puntos verticales junto a un espacio de trabajo > Establecer como espacio de trabajo predeterminado y luego inténtalo de nuevo.',
},
flight: 'Vuelo',
flightDetails: {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Travel/ManageTrips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ function ManageTrips() {
style={[styles.w100, styles.mb3]}
large
/>
<BookTravelButton text={translate('travel.bookTravel')} />
<BookTravelButton
text={translate('travel.bookTravel')}
shouldRenderErrorMessageBelowButton
/>
</>
}
/>
Expand Down