diff --git a/native/navigation/app-navigator.react.js b/native/navigation/app-navigator.react.js --- a/native/navigation/app-navigator.react.js +++ b/native/navigation/app-navigator.react.js @@ -24,6 +24,7 @@ OverlayNavigationProp, OverlayNavigationHelpers, } from './overlay-navigator.react'; +import PolicyAcknowledgmentHandler from './policy-acknowledgment-handler.react'; import type { RootNavigationProp } from './root-navigator.react'; import { TabNavigatorRouteName, @@ -134,6 +135,9 @@ /> {pushHandler} + + + ); } diff --git a/native/navigation/policy-acknowledgment-handler.react.js b/native/navigation/policy-acknowledgment-handler.react.js new file mode 100644 --- /dev/null +++ b/native/navigation/policy-acknowledgment-handler.react.js @@ -0,0 +1,28 @@ +// @flow + +import { useNavigation } from '@react-navigation/native'; +import * as React from 'react'; + +import { policyTypes } from 'lib/facts/policies'; + +import { useSelector } from '../redux/redux-utils'; +import { TermsAndPrivacyRouteName } from './route-names'; + +function PolicyAcknowledgmentHandler(): null { + const userPolicies = useSelector(state => state.userPolicies); + const navigation = useNavigation(); + + React.useEffect(() => { + const tosAndPrivacyState = userPolicies?.[policyTypes.tosAndPrivacyPolicy]; + if (tosAndPrivacyState && !tosAndPrivacyState?.isAcknowledged) { + navigation.navigate<'TermsAndPrivacyModal'>({ + name: TermsAndPrivacyRouteName, + params: { policyType: policyTypes.tosAndPrivacyPolicy }, + }); + } + }, [navigation, userPolicies]); + + return null; +} + +export default PolicyAcknowledgmentHandler;