1- import React , { useCallback , useEffect } from 'react' ;
1+ import React , { useCallback , useEffect , useState } from 'react' ;
22import { View } from 'react-native' ;
33import Button from '@components/Button' ;
4+ import ConnectToGustoFlow from '@components/ConnectToGustoFlow' ;
45import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
56import MenuItem from '@components/MenuItem' ;
67import ScreenWrapper from '@components/ScreenWrapper' ;
@@ -11,13 +12,15 @@ import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hook
1112import useLocalize from '@hooks/useLocalize' ;
1213import useNetwork from '@hooks/useNetwork' ;
1314import usePermissions from '@hooks/usePermissions' ;
15+ import usePolicy from '@hooks/usePolicy' ;
1416import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
1517import useThemeStyles from '@hooks/useThemeStyles' ;
1618import useWorkspaceDocumentTitle from '@hooks/useWorkspaceDocumentTitle' ;
1719import { openPolicyHRPage } from '@libs/actions/PolicyConnections' ;
1820import Navigation from '@libs/Navigation/Navigation' ;
1921import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
2022import type { WorkspaceSplitNavigatorParamList } from '@libs/Navigation/types' ;
23+ import { isGustoConnected } from '@libs/PolicyUtils' ;
2124import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper' ;
2225import CONST from '@src/CONST' ;
2326import type SCREENS from '@src/SCREENS' ;
@@ -33,8 +36,11 @@ function WorkspaceHRPage({
3336 const { isBetaEnabled} = usePermissions ( ) ;
3437 const styles = useThemeStyles ( ) ;
3538 const { shouldUseNarrowLayout} = useResponsiveLayout ( ) ;
39+ const policy = usePolicy ( policyID ) ;
40+ const [ activeGustoFlowKey , setActiveGustoFlowKey ] = useState < number > ( ) ;
3641 const icons = useMemoizedLazyExpensifyIcons ( [ 'GustoSquare' ] ) ;
3742 const illustrations = useMemoizedLazyIllustrations ( [ 'NewUser' ] ) ;
43+ const isConnected = isGustoConnected ( policy ) ;
3844
3945 useWorkspaceDocumentTitle ( undefined , 'workspace.common.hr' ) ;
4046
@@ -62,6 +68,12 @@ function WorkspaceHRPage({
6268 shouldShowOfflineIndicatorInWideScreen
6369 offlineIndicatorStyle = { styles . mtAuto }
6470 >
71+ { ! ! activeGustoFlowKey && (
72+ < ConnectToGustoFlow
73+ key = { activeGustoFlowKey }
74+ policyID = { policyID }
75+ />
76+ ) }
6577 < HeaderWithBackButton
6678 icon = { illustrations . NewUser }
6779 title = { translate ( 'workspace.common.hr' ) }
@@ -82,13 +94,15 @@ function WorkspaceHRPage({
8294 iconType = { CONST . ICON_TYPE_AVATAR }
8395 wrapperStyle = { [ styles . ph0 , styles . pv2 , styles . mt4 ] }
8496 interactive = { false }
85- shouldShowRightComponent
97+ shouldShowRightComponent = { ! isConnected }
8698 rightComponent = {
87- < Button
88- small
89- text = { translate ( 'workspace.hr.gusto.connect' ) }
90- onPress = { ( ) => { } }
91- />
99+ ! isConnected ? (
100+ < Button
101+ small
102+ text = { translate ( 'workspace.hr.gusto.connect' ) }
103+ onPress = { ( ) => setActiveGustoFlowKey ( Math . random ( ) ) }
104+ />
105+ ) : undefined
92106 }
93107 />
94108 </ Section >
0 commit comments