diff --git a/src/pages/workspace/travel/GetStartedTravel.tsx b/src/pages/workspace/travel/GetStartedTravel.tsx index 1cc042f8ef244..be9e8ff7d4219 100644 --- a/src/pages/workspace/travel/GetStartedTravel.tsx +++ b/src/pages/workspace/travel/GetStartedTravel.tsx @@ -3,26 +3,75 @@ import BookTravelButton from '@components/BookTravelButton'; import FeatureList from '@components/FeatureList'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; +import useOnyx from '@hooks/useOnyx'; +import usePermissions from '@hooks/usePermissions'; import useThemeStyles from '@hooks/useThemeStyles'; +import {getEligibleBankAccountsForCard} from '@libs/CardUtils'; +import Navigation from '@libs/Navigation/Navigation'; +import {hasInProgressUSDVBBA, REIMBURSEMENT_ACCOUNT_ROUTE_NAMES} from '@libs/ReimbursementAccountUtils'; import colors from '@styles/theme/colors'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; type GetStartedTravelProps = { policyID: string; }; function GetStartedTravel({policyID}: GetStartedTravelProps) { - const handleCtaPress = () => {}; - const {translate} = useLocalize(); const styles = useThemeStyles(); const illustrations = useMemoizedLazyIllustrations(['PendingTravel'] as const); + // TODO: Remove this when Travel Invoicing feature is fully implemented + const {isBetaEnabled} = usePermissions(); + + const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: false}); + const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: false}); + + const isTravelInvoicingEnabled = isBetaEnabled(CONST.BETAS.TRAVEL_INVOICING); + const isSetupUnfinished = hasInProgressUSDVBBA(reimbursementAccount?.achData); + const eligibleBankAccounts = getEligibleBankAccountsForCard(bankAccountList); + + const handleCtaPress = () => { + // Do nothing if beta is not enabled (existing noop behavior) + if (!isTravelInvoicingEnabled) { + return; + } + + // If no bank accounts or setup is unfinished, start the add bank account flow + if (!eligibleBankAccounts.length || isSetupUnfinished) { + Navigation.navigate(ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute(policyID, REIMBURSEMENT_ACCOUNT_ROUTE_NAMES.NEW, ROUTES.WORKSPACE_TRAVEL.getRoute(policyID))); + return; + } + + // If bank accounts exist, navigate to settlement account selection + Navigation.navigate(ROUTES.WORKSPACE_TRAVEL_SETTINGS_ACCOUNT.getRoute(policyID)); + }; + + // If Travel Invoicing beta is enabled, show a simple button that starts the setup flow + if (isTravelInvoicingEnabled) { + return ( + + ); + } + // TODO-END return ( { openPolicyTravelPage(policyID, workspaceAccountID); }, [policyID, workspaceAccountID]); @@ -72,11 +77,15 @@ function WorkspaceTravelPage({ const step = getTravelStep(policy, travelSettings, isBetaEnabled(CONST.BETAS.IS_TRAVEL_VERIFIED), policies, currentUserLogin); const mainContent = (() => { + // TODO: Remove this conditional when Travel Invoicing feature is fully implemented + if (isTravelInvoicingEnabled) { + if (!hasSettlementAccount) { + return ; + } + return ; + } switch (step) { case CONST.TRAVEL.STEPS.BOOK_OR_MANAGE_YOUR_TRIP: - if (isTravelInvoicingEnabled) { - return ; - } return ; case CONST.TRAVEL.STEPS.REVIEWING_REQUEST: return ; diff --git a/src/pages/workspace/travel/WorkspaceTravelInvoicingSection.tsx b/src/pages/workspace/travel/WorkspaceTravelInvoicingSection.tsx index 5aa6eed4db2a0..9b0780b1a62f5 100644 --- a/src/pages/workspace/travel/WorkspaceTravelInvoicingSection.tsx +++ b/src/pages/workspace/travel/WorkspaceTravelInvoicingSection.tsx @@ -185,9 +185,8 @@ function WorkspaceTravelInvoicingSection({policyID}: WorkspaceTravelInvoicingSec ); - // If Travel Invoicing is not enabled or no settlement account is configured - // show the BookOrManageYourTrip component as fallback - if (!isTravelInvoicingEnabled || !hasSettlementAccount) { + // If Travel Invoicing beta is not enabled, show the BookOrManageYourTrip component as fallback (before Travel Invoicing feature) + if (!isTravelInvoicingEnabled) { return ; } @@ -196,6 +195,7 @@ function WorkspaceTravelInvoicingSection({policyID}: WorkspaceTravelInvoicingSec