-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: show private domain warning first on book travel #60476
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,25 +50,25 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B | |
| const styles = useThemeStyles(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const {translate} = useLocalize(); | ||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); | ||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false}); | ||
| const isUserValidated = useAccountValidation(); | ||
|
|
||
| const policy = usePolicy(activePolicyID); | ||
| const [errorMessage, setErrorMessage] = useState<string | ReactElement>(''); | ||
| const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS); | ||
| const [primaryLogin] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.primaryLogin}); | ||
| const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email}); | ||
| const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS, {canBeMissing: false}); | ||
| const [primaryLogin] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.primaryLogin, canBeMissing: false}); | ||
| const [sessionEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email, canBeMissing: false}); | ||
| const primaryContactMethod = primaryLogin ?? sessionEmail ?? ''; | ||
| const {setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext); | ||
| const {isBlockedFromSpotnanaTravel} = usePermissions(); | ||
| const [isPreventionModalVisible, setPreventionModalVisibility] = useState(false); | ||
| const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); | ||
| const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); | ||
| 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); | ||
| const [wasNewDotLaunchedJustForTravel] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY, {canBeMissing: false}); | ||
|
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. |
||
|
|
||
| const hidePreventionModal = () => setPreventionModalVisibility(false); | ||
|
|
||
|
|
@@ -97,6 +97,12 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B | |
| return; | ||
| } | ||
|
|
||
| const adminDomains = getAdminsPrivateEmailDomains(policy); | ||
| if (adminDomains.length === 0) { | ||
| Navigation.navigate(ROUTES.TRAVEL_PUBLIC_DOMAIN_ERROR); | ||
| return; | ||
| } | ||
|
|
||
| if (groupPaidPolicies.length < 1) { | ||
| Navigation.navigate(ROUTES.TRAVEL_UPGRADE); | ||
| return; | ||
|
|
@@ -127,25 +133,21 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B | |
| }); | ||
| } else if (isPolicyProvisioned) { | ||
| navigateToAcceptTerms(CONST.TRAVEL.DEFAULT_DOMAIN); | ||
| } else { | ||
| // Determine the domain to associate with the workspace during provisioning in Spotnana. | ||
| // - If all admins share the same private domain, the workspace is tied to it automatically. | ||
| // - If admins have multiple private domains, the user must select one. | ||
| // - Public domains are not allowed; an error page is shown in that case. | ||
| const adminDomains = getAdminsPrivateEmailDomains(policy); | ||
| if (adminDomains.length === 0) { | ||
| Navigation.navigate(ROUTES.TRAVEL_PUBLIC_DOMAIN_ERROR); | ||
| } else if (adminDomains.length === 1) { | ||
| const domain = adminDomains.at(0) ?? CONST.TRAVEL.DEFAULT_DOMAIN; | ||
| if (isEmptyObject(policy?.address)) { | ||
| // Spotnana requires an address anytime an entity is created for a policy | ||
| Navigation.navigate(ROUTES.TRAVEL_WORKSPACE_ADDRESS.getRoute(domain)); | ||
| } else { | ||
| navigateToAcceptTerms(domain, !!isUserValidated); | ||
| } | ||
| } | ||
| // Determine the domain to associate with the workspace during provisioning in Spotnana. | ||
| // - If all admins share the same private domain, the workspace is tied to it automatically. | ||
| // - If admins have multiple private domains, the user must select one. | ||
| // - Public domains are not allowed; an error page is shown in that case. | ||
| else if (adminDomains.length === 1) { | ||
| const domain = adminDomains.at(0) ?? CONST.TRAVEL.DEFAULT_DOMAIN; | ||
| if (isEmptyObject(policy?.address)) { | ||
| // Spotnana requires an address anytime an entity is created for a policy | ||
| Navigation.navigate(ROUTES.TRAVEL_WORKSPACE_ADDRESS.getRoute(domain)); | ||
| } else { | ||
| Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); | ||
| navigateToAcceptTerms(domain, !!isUserValidated); | ||
| } | ||
| } else { | ||
| Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); | ||
| } | ||
| }, [ | ||
| isBlockedFromSpotnanaTravel, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line caused a regression. Showing warning on new accounts.
@daledah Please fix this.