-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Refactor bookATrip function #55852
Refactor bookATrip function #55852
Changes from 3 commits
d18f99b
9ae5e55
1a32608
bc569f5
d16741c
70d8109
358fe95
789a92b
fa0ddbb
22f3617
c6e30de
b633ba0
00d6012
243a09e
46b6485
f9428d6
f10ee2e
cf3e4bd
2331d13
ab8d5db
7dd2c55
f8e248a
14ee3bc
950ee37
75e4342
e43921a
820a0e5
f7f58db
b851e2f
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 |
---|---|---|
|
@@ -21,6 +21,12 @@ type BookTravelButtonProps = { | |
text: string; | ||
}; | ||
|
||
const navigateToAcceptTerms = (domain: string) => { | ||
// Remove the previous provision session infromation if any is cached. | ||
cleanupTravelProvisioningSession(); | ||
Navigation.navigate(ROUTES.TRAVEL_TCS.getRoute(domain)); | ||
}; | ||
|
||
function BookTravelButton({text}: BookTravelButtonProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
|
@@ -36,11 +42,15 @@ function BookTravelButton({text}: BookTravelButtonProps) { | |
const [isSingleNewDotEntry] = useOnyx(ONYXKEYS.IS_SINGLE_NEW_DOT_ENTRY); | ||
cristipaval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const bookATrip = useCallback(() => { | ||
setErrorMessage(''); | ||
|
||
// The primary login of the user is where Spotnana sends the emails with booking confirmations, itinerary etc. It can't be a phone number. | ||
if (!primaryLogin || Str.isSMSLogin(primaryLogin)) { | ||
setErrorMessage(translate('travel.phoneError')); | ||
return; | ||
} | ||
|
||
// An address is required when the Spotnana entity is created for the policy | ||
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. Why is an address required? (answer that in the comment please) |
||
if (isEmptyObject(policy?.address)) { | ||
cristipaval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Navigation.navigate(ROUTES.WORKSPACE_PROFILE_ADDRESS.getRoute(policy?.id, Navigation.getActiveRoute())); | ||
return; | ||
|
@@ -63,26 +73,23 @@ function BookTravelButton({text}: BookTravelButtonProps) { | |
?.catch(() => { | ||
setErrorMessage(translate('travel.errorMessage')); | ||
}); | ||
if (errorMessage) { | ||
setErrorMessage(''); | ||
} | ||
} else if (isPolicyProvisioned) { | ||
cleanupTravelProvisioningSession(); | ||
Navigation.navigate(ROUTES.TRAVEL_TCS.getRoute(CONST.TRAVEL.DEFAULT_DOMAIN)); | ||
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); | ||
cristipaval marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let routeToNavigateTo; | ||
if (adminDomains.length === 0) { | ||
routeToNavigateTo = ROUTES.TRAVEL_PUBLIC_DOMAIN_ERROR; | ||
Navigation.navigate(ROUTES.TRAVEL_PUBLIC_DOMAIN_ERROR); | ||
} else if (adminDomains.length === 1) { | ||
cleanupTravelProvisioningSession(); | ||
routeToNavigateTo = ROUTES.TRAVEL_TCS.getRoute(adminDomains.at(0) ?? CONST.TRAVEL.DEFAULT_DOMAIN); | ||
navigateToAcceptTerms(adminDomains.at(0) ?? CONST.TRAVEL.DEFAULT_DOMAIN); | ||
} else { | ||
routeToNavigateTo = ROUTES.TRAVEL_DOMAIN_SELECTOR; | ||
Navigation.navigate(ROUTES.TRAVEL_DOMAIN_SELECTOR); | ||
} | ||
Navigation.navigate(routeToNavigateTo); | ||
} | ||
}, [policy, isSingleNewDotEntry, travelSettings, translate, errorMessage, primaryLogin]); | ||
}, [policy, isSingleNewDotEntry, travelSettings, translate, primaryLogin]); | ||
|
||
return ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ function EmptySearchView({type, hasResults}: EmptySearchViewProps) { | |
return areAllGroupPoliciesExpenseChatDisabled((allPolicies as OnyxCollection<Policy>) ?? {}); | ||
}, [allPolicies]); | ||
|
||
const contentBody = useMemo(() => { | ||
const contentChildren = useMemo(() => { | ||
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. Maybe we should rename this const since this is a bit confusing because we also have Maybe we should rename it to |
||
return ( | ||
<> | ||
<Text style={[styles.textSupporting, styles.textNormal]}> | ||
|
@@ -120,7 +120,7 @@ function EmptySearchView({type, hasResults}: EmptySearchViewProps) { | |
headerContentStyles: [StyleUtils.getWidthAndHeightStyle(375, 240), StyleUtils.getBackgroundColorStyle(theme.travelBG)], | ||
title: translate('travel.title'), | ||
titleStyles: {...styles.textAlignLeft}, | ||
body: contentBody, | ||
children: contentChildren, | ||
lottieWebViewStyles: {backgroundColor: theme.travelBG, ...styles.emptyStateFolderWebStyles}, | ||
}; | ||
case CONST.SEARCH.DATA_TYPES.EXPENSE: | ||
|
@@ -220,7 +220,7 @@ function EmptySearchView({type, hasResults}: EmptySearchViewProps) { | |
translate, | ||
styles.textAlignLeft, | ||
styles.emptyStateFolderWebStyles, | ||
contentBody, | ||
contentChildren, | ||
hasSeenTour, | ||
navatticURL, | ||
shouldRedirectToExpensifyClassic, | ||
|
@@ -241,11 +241,12 @@ function EmptySearchView({type, hasResults}: EmptySearchViewProps) { | |
title={content.title} | ||
titleStyles={content.titleStyles} | ||
subtitle={content.subtitle} | ||
body={content.body} | ||
buttons={content.buttons} | ||
headerContentStyles={[styles.h100, styles.w100, ...content.headerContentStyles]} | ||
lottieWebViewStyles={content.lottieWebViewStyles} | ||
/> | ||
> | ||
{content.children} | ||
</EmptyStateComponent> | ||
<ConfirmModal | ||
prompt={translate('sidebarScreen.redirectToExpensifyClassicModal.description')} | ||
isVisible={modalVisible} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,6 @@ function WorkspaceCompanyCardsFeedPendingPage() { | |
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const body = ( | ||
<Text> | ||
{translate('workspace.moreFeatures.companyCards.pendingFeedDescription')} | ||
<TextLink onPress={() => navigateToConciergeChat()}> {CONST?.CONCIERGE_CHAT_NAME}</TextLink>. | ||
</Text> | ||
); | ||
|
||
return ( | ||
<EmptyStateComponent | ||
SkeletonComponent={CardRowSkeleton} | ||
|
@@ -30,8 +23,12 @@ function WorkspaceCompanyCardsFeedPendingPage() { | |
headerStyles={[styles.emptyStateCardIllustrationContainer, {backgroundColor: colors.ice800}]} | ||
headerContentStyles={styles.pendingStateCardIllustration} | ||
title={translate('workspace.moreFeatures.companyCards.pendingFeedTitle')} | ||
body={body} | ||
/> | ||
> | ||
<Text> | ||
{translate('workspace.moreFeatures.companyCards.pendingFeedDescription')} | ||
<TextLink onPress={() => navigateToConciergeChat()}> {CONST?.CONCIERGE_CHAT_NAME}</TextLink>. | ||
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. I think 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. +1 |
||
</Text> | ||
</EmptyStateComponent> | ||
); | ||
} | ||
|
||
|
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.
Minor comment
But similar case as here
We usually don't move such functions out of the component 😅
#55852 (comment)
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.
In this case, we want it outside of the component since it has no dependency on the component, no?
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.
Yes, you're right
As I mentioned, it's just a minor comment
Also, keeping the function outside a component prevents it from being recreated on every render
What I meant is that we usually keep wrapper functions inside the component
But I don't mind leaving it as is !
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.
I agree that it's OK where it's at, and I also agree that I kinda wish more pure functions like this were moved outside of the component entirely. It's not seen very often in the app, but should be OK here.