11import HybridAppModule from '@expensify/react-native-hybrid-app' ;
22import { Str } from 'expensify-common' ;
33import type { ReactElement } from 'react' ;
4- import React , { useCallback , useContext , useState } from 'react' ;
4+ import React , { useCallback , useContext , useEffect , useState } from 'react' ;
55import { useOnyx } from 'react-native-onyx' ;
66import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
77import useLocalize from '@hooks/useLocalize' ;
@@ -33,6 +33,9 @@ type BookTravelButtonProps = {
3333
3434 /** Whether to render the error message below the button */
3535 shouldRenderErrorMessageBelowButton ?: boolean ;
36+
37+ /** Function to set the shouldScrollToBottom state */
38+ setShouldScrollToBottom ?: ( shouldScrollToBottom : boolean ) => void ;
3639} ;
3740
3841const navigateToAcceptTerms = ( domain : string , isUserValidated ?: boolean ) => {
@@ -45,7 +48,7 @@ const navigateToAcceptTerms = (domain: string, isUserValidated?: boolean) => {
4548 Navigation . navigate ( ROUTES . SETTINGS_CONTACT_METHOD_VERIFY_ACCOUNT . getRoute ( Navigation . getActiveRoute ( ) , ROUTES . TRAVEL_TCS . getRoute ( domain ) ) ) ;
4649} ;
4750
48- function BookTravelButton ( { text, shouldRenderErrorMessageBelowButton = false } : BookTravelButtonProps ) {
51+ function BookTravelButton ( { text, shouldRenderErrorMessageBelowButton = false , setShouldScrollToBottom } : BookTravelButtonProps ) {
4952 const styles = useThemeStyles ( ) ;
5053 const StyleUtils = useStyleUtils ( ) ;
5154 const { translate} = useLocalize ( ) ;
@@ -74,6 +77,13 @@ function BookTravelButton({text, shouldRenderErrorMessageBelowButton = false}: B
7477 const hidePreventionModal = ( ) => setPreventionModalVisibility ( false ) ;
7578 const hideVerificationModal = ( ) => setVerificationModalVisibility ( false ) ;
7679
80+ useEffect ( ( ) => {
81+ if ( ! errorMessage ) {
82+ return ;
83+ }
84+ setShouldScrollToBottom ?.( true ) ;
85+ } , [ errorMessage , setShouldScrollToBottom ] ) ;
86+
7787 const bookATrip = useCallback ( ( ) => {
7888 setErrorMessage ( '' ) ;
7989
0 commit comments