Skip to content
Merged
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
48 changes: 25 additions & 23 deletions src/components/BookTravelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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});

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.

This line caused a regression. Showing warning on new accounts.

@daledah Please fix this.

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});

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.


const hidePreventionModal = () => setPreventionModalVisibility(false);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down