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
14 changes: 10 additions & 4 deletions src/components/BookTravelButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useConfirmModal from '@hooks/useConfirmModal';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDefaultWorkspaceTravelGuard from '@hooks/useDefaultWorkspaceTravelGuard';
import useEnvironment from '@hooks/useEnvironment';
import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -15,7 +16,7 @@ import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/crea
import Navigation from '@libs/Navigation/Navigation';
import {openTravelDotLink} from '@libs/openTravelDotLink';
import {areTravelPersonalDetailsMissing} from '@libs/PersonalDetailsUtils';
import {getActivePolicies, getAdminsPrivateEmailDomains, isPaidGroupPolicy, isWorkspaceProvisionedForTravel} from '@libs/PolicyUtils';
import {getActivePolicies, getAdminsPrivateEmailDomains, hasAcceptedTravelTerms, isPaidGroupPolicy, isWorkspaceProvisionedForTravel} from '@libs/PolicyUtils';
import {getSearchParamFromPath} from '@libs/Url';

import colors from '@styles/theme/colors';
Expand Down Expand Up @@ -72,6 +73,7 @@ function BookTravelButton({
const primaryLogin = account?.primaryLogin ?? '';

const policy = usePolicy(activePolicyID);
const blockIfDefaultWorkspaceLacksTravel = useDefaultWorkspaceTravelGuard();
const [errorMessage, setErrorMessage] = useState<string | ReactElement>('');
const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS);
const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector});
Expand Down Expand Up @@ -131,8 +133,8 @@ function BookTravelButton({
}

const isPolicyProvisioned = isWorkspaceProvisionedForTravel(policy?.travelSettings);
const hasAcceptedTravelTerms = policy?.travelSettings?.hasAcceptedTerms ?? (travelSettings?.hasAcceptedTerms && isPolicyProvisioned);
const willUseEnablementStepper = !hasAcceptedTravelTerms && (isPolicyProvisioned || isBetaEnabled(CONST.BETAS.IS_TRAVEL_VERIFIED));
const hasPolicyAcceptedTravelTerms = hasAcceptedTravelTerms(policy, travelSettings);
const willUseEnablementStepper = !hasPolicyAcceptedTravelTerms && (isPolicyProvisioned || isBetaEnabled(CONST.BETAS.IS_TRAVEL_VERIFIED));

// The enablement stepper collects a missing legal name as one of its own steps, so this pre-check (and its
// resume-after-filling behavior) only still applies to the outcomes that never reach the stepper: opening
Expand All @@ -159,7 +161,11 @@ function BookTravelButton({
return;
}

if (hasAcceptedTravelTerms) {
if (hasPolicyAcceptedTravelTerms) {
if (blockIfDefaultWorkspaceLacksTravel()) {
return;
}

openTravelDotLink(policy?.id);
return;
}
Expand Down
15 changes: 9 additions & 6 deletions src/components/Navigation/QuickCreationActionsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Button from '@components/ButtonComposed';
import useCreateEmptyReportConfirmation from '@hooks/useCreateEmptyReportConfirmation';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDefaultWorkspaceTravelGuard from '@hooks/useDefaultWorkspaceTravelGuard';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -19,7 +20,7 @@ import getCreateReportRoute, {getReportsRootRoute, navigateToCreateReportWorkspa
import Navigation from '@libs/Navigation/Navigation';
import {openTravelDotLink} from '@libs/openTravelDotLink';
import Permissions from '@libs/Permissions';
import {getDefaultChatEnabledPolicy, getGroupPoliciesWhereReportCanBeCreated, isPaidGroupPolicy, isWorkspaceProvisionedForTravel} from '@libs/PolicyUtils';
import {getDefaultChatEnabledPolicy, getGroupPoliciesWhereReportCanBeCreated, hasAcceptedTravelTerms, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {generateReportID, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';

Expand Down Expand Up @@ -61,6 +62,7 @@ function QuickCreationActionsBar() {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {getCurrencyDecimals} = useCurrencyListActions();
const {isBetaEnabled} = usePermissions();
const blockIfDefaultWorkspaceLacksTravel = useDefaultWorkspaceTravelGuard();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
const {shouldNavigateToUpgradePath} = usePolicyForMovingExpenses();
Expand Down Expand Up @@ -88,10 +90,8 @@ function QuickCreationActionsBar() {
return false;
}

const isPolicyProvisioned = isWorkspaceProvisionedForTravel(travelEnabledPolicy?.travelSettings);

return travelEnabledPolicy?.travelSettings?.hasAcceptedTerms ?? (travelSettings?.hasAcceptedTerms && isPolicyProvisioned);
}, [travelEnabledPolicy, isBlockedFromSpotnanaTravel, primaryContactMethod, travelSettings?.hasAcceptedTerms]);
return hasAcceptedTravelTerms(travelEnabledPolicy, travelSettings);
Comment thread
blimpich marked this conversation as resolved.
Resolved
}, [travelEnabledPolicy, isBlockedFromSpotnanaTravel, primaryContactMethod, travelSettings]);

const handleCreateWorkspaceReport = useCallback(
(shouldDismissEmptyReportsConfirmation?: boolean) => {
Expand Down Expand Up @@ -204,12 +204,15 @@ function QuickCreationActionsBar() {
() =>
interceptAnonymousUser(() => {
if (isTravelReady) {
if (blockIfDefaultWorkspaceLacksTravel()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard blockIfDefaultWorkspaceLacksTravel() is only called inside if (isTravelReady), so when setup isn't complete the handler falls through to Navigation.navigate(ROUTES.TRAVEL_MY_TRIPS...) without it and no modal shows (#99041).

return;
}
openTravelDotLink(travelEnabledPolicy?.id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard asserts the default workspace has travel, but the ID handed to openTravelDotLink is travelEnabledPolicy?.id, computed as line 82 as Object.values(allPolicies).find(p => p.isTravelEnabled) (insertion order, not the default).
So, with two travel-enabled workspaces, the guard passes and the user is still handed off to a non-default workspace.
This is not something introduced by this PR so out of scope.

return;
}
Navigation.navigate(ROUTES.TRAVEL_MY_TRIPS.getRoute(travelEnabledPolicy?.id));
}),
[travelEnabledPolicy?.id, isTravelReady],
[travelEnabledPolicy?.id, isTravelReady, blockIfDefaultWorkspaceLacksTravel],
);

return (
Expand Down
52 changes: 52 additions & 0 deletions src/hooks/useDefaultWorkspaceTravelGuard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {hasAcceptedTravelTerms} from '@libs/PolicyUtils';

import colors from '@styles/theme/colors';

import ONYXKEYS from '@src/ONYXKEYS';

import useConfirmModal from './useConfirmModal';
import {useMemoizedLazyIllustrations} from './useLazyAsset';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
import usePolicy from './usePolicy';
import useStyleUtils from './useStyleUtils';
import useThemeStyles from './useThemeStyles';

/**
* A traveler is provisioned against their default workspace, so booking from any other workspace opens a session they
* have no travel profile for. Returns a function that shows the blocking modal and reports whether it blocked.
*/
function useDefaultWorkspaceTravelGuard() {
const {translate} = useLocalize();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const illustrations = useMemoizedLazyIllustrations(['RocketDude']);
const {showConfirmModal} = useConfirmModal();
const [defaultPolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const defaultPolicy = usePolicy(defaultPolicyID);
const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS);

const blockIfDefaultWorkspaceLacksTravel = () => {
if (!defaultPolicy || (defaultPolicy.isTravelEnabled && hasAcceptedTravelTerms(defaultPolicy, travelSettings))) {
return false;
}
Comment thread
blimpich marked this conversation as resolved.
Resolved

showConfirmModal({
title: translate('travel.defaultWorkspaceTravelDisabled.title'),
titleStyles: styles.textHeadlineH1,
titleContainerStyles: styles.mb2,
prompt: translate('travel.defaultWorkspaceTravelDisabled.message'),
promptStyles: styles.mb2,
confirmText: translate('common.buttonConfirm'),
shouldShowCancelButton: false,
image: illustrations.RocketDude,
imageStyles: StyleUtils.getBackgroundColorStyle(colors.ice600),
});

return true;
};

return blockIfDefaultWorkspaceLacksTravel;
}

export default useDefaultWorkspaceTravelGuard;
4 changes: 4 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4513,6 +4513,10 @@ ${amount} für ${merchant} – ${date}`,
railCard:
'Wussten Sie, dass Sie Zugfahrten direkt in Expensify buchen und verwalten können? Und dass Belege dabei automatisch für Sie hochgeladen werden? Buchen Sie das nächste Mal einfach über <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Reisen ist nicht aktiviert',
message: 'Um zu buchen, aktivieren Sie bitte Reisen in Ihrem Standard-Arbeitsbereich oder wechseln Sie Ihren Standard-Arbeitsbereich zu einem, in dem Reisen aktiviert ist.',
},
},
workspace: {
common: {
Expand Down
5 changes: 5 additions & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,11 @@ ${amount} για ${merchant} - ${date}`,
railCard:
'Γνωρίζατε ότι μπορείτε να κλείνετε και να διαχειρίζεστε ταξίδια με τρένο απευθείας στο Expensify; Και ότι ανεβάζει αυτόματα τις αποδείξεις για εσάς; Την επόμενη φορά απλώς κάντε κράτηση μέσω του <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Η ταξιδιωτική λειτουργία δεν είναι ενεργοποιημένη',
message:
'Για να κάνετε κράτηση, ενεργοποιήστε τα ταξίδια στον προεπιλεγμένο χώρο εργασίας σας ή αλλάξτε τον προεπιλεγμένο χώρο εργασίας σε κάποιον όπου τα ταξίδια είναι ενεργοποιημένα.',
},
},
proactiveAppReview: {
title: 'Σας αρέσει το νέο Expensify;',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4553,6 +4553,10 @@ const translations = {
title: 'Expensify Travel has been disabled',
message: `Your admin has turned off Expensify Travel. Please follow your company's booking policy for travel arrangements.`,
},
defaultWorkspaceTravelDisabled: {
title: 'Travel is not enabled',
message: 'To book, please enable travel on your default workspace or switch your default workspace to one that is travel-enabled.',
},
verifyCompany: {
title: "We're reviewing your request...",
message: `We're running a few checks on our end to verify your account is ready for Expensify Travel. We'll be in touch shortly!`,
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4417,6 +4417,10 @@ ${amount} para ${merchant} - ${date}`,
railCard:
'¿Sabías que puedes reservar y gestionar viajes en tren directamente en Expensify? ¿Y que además sube los recibos automáticamente por ti? La próxima vez, simplemente reserva a través de <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Los viajes no están habilitados',
message: 'Para reservar, habilita los viajes en tu espacio de trabajo predeterminado o cambia tu espacio de trabajo predeterminado a uno que tenga los viajes habilitados.',
},
},
proactiveAppReview: {
title: '¿Te gusta New Expensify?',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4522,6 +4522,10 @@ ${amount} pour ${merchant} - ${date}`,
railCard:
'Saviez-vous que vous pouvez réserver et gérer vos trajets en train directement dans Expensify ? Et que les reçus sont automatiquement téléchargés pour vous ? La prochaine fois, réservez simplement via <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Voyage n’est pas activé',
message: 'Pour réserver, veuillez activer les voyages sur votre espace de travail par défaut ou définir par défaut un espace de travail sur lequel les voyages sont activés.',
},
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4489,6 +4489,10 @@ ${amount} per ${merchant} - ${date}`,
railCard:
'Sapevi che puoi prenotare e gestire i viaggi in treno direttamente in Expensify? E che le ricevute vengono caricate automaticamente per te? La prossima volta prenota semplicemente tramite <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Viaggi non abilitato',
message: 'Per prenotare, abilita i viaggi sul tuo spazio di lavoro predefinito oppure imposta come predefinito uno spazio di lavoro con viaggi abilitati.',
},
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4453,6 +4453,10 @@ ${integrationName === CONST.ONBOARDING_ACCOUNTING_MAPPING.other ? 'あなたの'
railCard:
'Expensify で電車の予約や管理ができることをご存じでしたか?しかも領収書も自動でアップロードされます。次回からは、ぜひ <a href="https://travel.expensify.com">Expensify Travel</a> から予約してください 🚂',
},
defaultWorkspaceTravelDisabled: {
title: '出張機能は有効になっていません',
message: '予約するには、デフォルトのワークスペースで出張機能を有効にするか、出張機能が有効になっているワークスペースをデフォルトとして設定してください。',
},
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4487,6 +4487,10 @@ ${amount} voor ${merchant} - ${date}`,
railCard:
'Wist je dat je treinreizen rechtstreeks in Expensify kunt boeken en beheren? En dat bonnen automatisch voor je worden geüpload? Boek de volgende keer gewoon via <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Reizen is niet ingeschakeld',
message: 'Om te boeken, schakel reizen in op je standaardwerkruimte of stel een standaardwerkruimte in die reizen ondersteunt.',
},
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4472,6 +4472,10 @@ ${amount} dla ${merchant} - ${date}`,
railCard:
'Wiesz, że możesz rezerwować i zarządzać przejazdami pociągiem bezpośrednio w Expensify? I że paragony są automatycznie przesyłane za Ciebie? Następnym razem po prostu zarezerwuj przez <a href="https://travel.expensify.com">Expensify Travel</a>',
},
defaultWorkspaceTravelDisabled: {
title: 'Podróże są wyłączone',
message: 'Aby dokonać rezerwacji, włącz podróże w swojej domyślnej przestrzeni roboczej lub ustaw jako domyślną inną przestrzeń roboczą, w której podróże są włączone.',
},
},
workspace: {
common: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4481,6 +4481,10 @@ ${amount} para ${merchant} - ${date}`,
railCard:
'Você sabia que dá para reservar e gerenciar viagens de trem direto no Expensify? E que os recibos são enviados automaticamente para você? Da próxima vez, é só reservar pelo <a href="https://travel.expensify.com">Expensify Travel</a> 🚂',
},
defaultWorkspaceTravelDisabled: {
title: 'Viagem não está ativada',
message: 'Para fazer uma reserva, ative viagens no seu espaço de trabalho padrão ou altere seu espaço de trabalho padrão para um que tenha viagens ativadas.',
},
},
workspace: {
common: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,7 @@ ${amount},商户:${merchant} - 日期:${date}`,
railManual: '你知道吗?你可以直接在 Expensify 中预订和管理火车行程!下次无需再手动创建报销,只需通过 <a href="https://travel.expensify.com">Expensify Travel</a> 预订即可 🚂',
railCard: '你知道吗?你可以直接在 Expensify 中预订和管理火车行程,而且还会自动为你上传收据。下次只需通过 <a href="https://travel.expensify.com">Expensify Travel</a> 预订即可 🚂',
},
defaultWorkspaceTravelDisabled: {title: '差旅功能未启用', message: '如需预订,请在您的默认工作区中启用差旅功能,或将默认工作区切换为已启用差旅功能的工作区。'},
},
workspace: {
common: {
Expand Down
6 changes: 6 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,11 @@ function isWorkspaceProvisionedForTravel(travelSettings?: WorkspaceTravelSetting
return !!(travelSettings?.spotnanaCompanyID ?? travelSettings?.associatedTravelDomainAccountID);
}

/** Whether travel is enabled on a workspace, meaning it can be used to book a trip. */
function hasAcceptedTravelTerms(policy: OnyxEntry<Policy>, accountTravelSettings: TravelSettings | undefined): boolean {
return !!(policy?.travelSettings?.hasAcceptedTerms ?? (accountTravelSettings?.hasAcceptedTerms && isWorkspaceProvisionedForTravel(policy?.travelSettings)));
Comment thread
blimpich marked this conversation as resolved.
Resolved
}

function isNonUSDPolicy(policy: OnyxEntry<Policy>): boolean {
return !!policy?.outputCurrency && policy.outputCurrency !== CONST.CURRENCY.USD;
}
Expand Down Expand Up @@ -3223,6 +3228,7 @@ export {
isPerDiemEnabled,
getTravelStep,
isWorkspaceProvisionedForTravel,
hasAcceptedTravelTerms,
isNonUSDPolicy,
isDefaultTagName,
isTimeTrackingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import Navigation from '@libs/Navigation/Navigation';
import {openTravelDotLink, shouldOpenTravelDotLinkWeb} from '@libs/openTravelDotLink';
import Permissions from '@libs/Permissions';
import {isPaidGroupPolicy, isWorkspaceProvisionedForTravel} from '@libs/PolicyUtils';
import {hasAcceptedTravelTerms, isPaidGroupPolicy} from '@libs/PolicyUtils';

import FABFocusableMenuItem from '@pages/inbox/sidebar/FABPopoverContent/FABFocusableMenuItem';

Expand Down Expand Up @@ -34,13 +34,12 @@ function TravelMenuItem() {
const primaryContactMethod = primaryLogin ?? sessionEmail ?? '';
const isVisible = !!activePolicy?.isTravelEnabled;

const isPolicyProvisioned = isWorkspaceProvisionedForTravel(activePolicy?.travelSettings);
const isTravelEnabled =
!isBlockedFromSpotnanaTravel &&
!!primaryContactMethod &&
!Str.isSMSLogin(primaryContactMethod) &&
isPaidGroupPolicy(activePolicy) &&
(activePolicy?.travelSettings?.hasAcceptedTerms ?? (travelSettings?.hasAcceptedTerms && isPolicyProvisioned));
hasAcceptedTravelTerms(activePolicy, travelSettings);

const openTravel = () => {
if (isTravelEnabled) {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/workspace/travel/BookOrManageYourTrip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import MenuItem from '@components/MenuItem';
import Section from '@components/Section';

import useConfirmModal from '@hooks/useConfirmModal';
import useDefaultWorkspaceTravelGuard from '@hooks/useDefaultWorkspaceTravelGuard';
import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
Expand Down Expand Up @@ -37,6 +38,7 @@ function GetStartedTravel({policyID}: GetStartedTravelProps) {
const illustrations = useMemoizedLazyIllustrations(['RocketDude']);
const {isBetaEnabled} = usePermissions();
const {showConfirmModal} = useConfirmModal();
const blockIfDefaultWorkspaceLacksTravel = useDefaultWorkspaceTravelGuard();
const isPreventSpotnanaTravelEnabled = isBetaEnabled(CONST.BETAS.PREVENT_SPOTNANA_TRAVEL);

const autoAddTripName = policy?.travelSettings?.autoAddTripName !== false;
Expand All @@ -61,6 +63,10 @@ function GetStartedTravel({policyID}: GetStartedTravelProps) {
return;
}

if (blockIfDefaultWorkspaceLacksTravel()) {
return;
}

openTravelDotLink(policyID);
};

Expand Down
Loading
Loading