Repository navigation
Show an error when the default workspace does not have travel enabled #98484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c9164a2
b7c222f
95e57ad
da0025e
2ed73f0
c764f76
c931a41
2fb4dee
904c0c0
17ed1ec
b05188e
1406502
b74345d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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'; | ||
|
|
||
|
|
@@ -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(); | ||
|
|
@@ -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); | ||
| }, [travelEnabledPolicy, isBlockedFromSpotnanaTravel, primaryContactMethod, travelSettings]); | ||
|
|
||
| const handleCreateWorkspaceReport = useCallback( | ||
| (shouldDismissEmptyReportsConfirmation?: boolean) => { | ||
|
|
@@ -204,12 +204,15 @@ function QuickCreationActionsBar() { | |
| () => | ||
| interceptAnonymousUser(() => { | ||
| if (isTravelReady) { | ||
| if (blockIfDefaultWorkspaceLacksTravel()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The guard |
||
| return; | ||
| } | ||
| openTravelDotLink(travelEnabledPolicy?.id); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.TRAVEL_MY_TRIPS.getRoute(travelEnabledPolicy?.id)); | ||
| }), | ||
| [travelEnabledPolicy?.id, isTravelReady], | ||
| [travelEnabledPolicy?.id, isTravelReady, blockIfDefaultWorkspaceLacksTravel], | ||
| ); | ||
|
|
||
| return ( | ||
|
|
||
| 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; | ||
| } | ||
|
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; | ||
Uh oh!
There was an error while loading. Please reload this page.