|
| 1 | +import {useRoute} from '@react-navigation/native'; |
1 | 2 | import React from 'react'; |
2 | 3 | import {View} from 'react-native'; |
3 | 4 | import useIsAuthenticated from '@hooks/useIsAuthenticated'; |
4 | 5 | import useLocalize from '@hooks/useLocalize'; |
5 | 6 | import useOnyx from '@hooks/useOnyx'; |
6 | 7 | import useThemeStyles from '@hooks/useThemeStyles'; |
7 | 8 | import useWindowDimensions from '@hooks/useWindowDimensions'; |
| 9 | +import navigateAfterInteraction from '@libs/Navigation/navigateAfterInteraction'; |
| 10 | +import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; |
8 | 11 | import Navigation from '@navigation/Navigation'; |
| 12 | +import type {TestToolsModalModalNavigatorParamList} from '@navigation/types'; |
| 13 | +import toggleTestToolsModal from '@userActions/TestTool'; |
9 | 14 | import ONYXKEYS from '@src/ONYXKEYS'; |
10 | 15 | import ROUTES from '@src/ROUTES'; |
| 16 | +import type SCREENS from '@src/SCREENS'; |
11 | 17 | import Button from './Button'; |
| 18 | +import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback'; |
12 | 19 | import RecordTroubleshootDataToolMenu from './RecordTroubleshootDataToolMenu'; |
13 | 20 | import SafeAreaConsumer from './SafeAreaConsumer'; |
14 | 21 | import ScrollView from './ScrollView'; |
15 | 22 | import TestToolMenu from './TestToolMenu'; |
16 | 23 | import TestToolRow from './TestToolRow'; |
17 | 24 | import Text from './Text'; |
18 | 25 |
|
19 | | -function getRouteBasedOnAuthStatus(isAuthenticated: boolean, activeRoute: string) { |
| 26 | +function getRouteBasedOnAuthStatus(isAuthenticated: boolean, activeRoute?: string) { |
20 | 27 | return isAuthenticated ? ROUTES.SETTINGS_CONSOLE.getRoute(activeRoute) : ROUTES.PUBLIC_CONSOLE_DEBUG.getRoute(activeRoute); |
21 | 28 | } |
22 | 29 |
|
23 | 30 | function TestToolsModalPage() { |
24 | 31 | const {windowHeight} = useWindowDimensions(); |
25 | 32 | const styles = useThemeStyles(); |
26 | 33 | const {translate} = useLocalize(); |
27 | | - const activeRoute = Navigation.getActiveRoute(); |
| 34 | + const route = useRoute<PlatformStackRouteProp<TestToolsModalModalNavigatorParamList, typeof SCREENS.TEST_TOOLS_MODAL.ROOT>>(); |
| 35 | + const backTo = route.params?.backTo; |
28 | 36 | const [shouldStoreLogs = false] = useOnyx(ONYXKEYS.SHOULD_STORE_LOGS, {canBeMissing: true}); |
29 | 37 | const isAuthenticated = useIsAuthenticated(); |
30 | | - const route = getRouteBasedOnAuthStatus(isAuthenticated, activeRoute); |
| 38 | + |
| 39 | + // If no backTo param is provided (direct access to /test-tools), |
| 40 | + // use home route as a default backTo param for console navigation |
| 41 | + const effectiveBackTo = backTo ?? ROUTES.HOME; |
| 42 | + const consoleRoute = getRouteBasedOnAuthStatus(isAuthenticated, effectiveBackTo); |
31 | 43 |
|
32 | 44 | const maxHeight = windowHeight; |
33 | 45 |
|
34 | 46 | return ( |
35 | 47 | <SafeAreaConsumer> |
36 | 48 | {({safeAreaPaddingBottomStyle}) => ( |
37 | 49 | <View style={[{maxHeight}, styles.h100, styles.defaultModalContainer, safeAreaPaddingBottomStyle]}> |
38 | | - <ScrollView style={[styles.flex1, styles.flexGrow1, styles.ph5]}> |
39 | | - <Text |
40 | | - style={[styles.textLabelSupporting, styles.mt5, styles.mb3]} |
41 | | - numberOfLines={1} |
| 50 | + <ScrollView |
| 51 | + style={[styles.flex1, styles.ph5]} |
| 52 | + contentContainerStyle={styles.flexGrow1} |
| 53 | + > |
| 54 | + <PressableWithoutFeedback |
| 55 | + accessible={false} |
| 56 | + style={[styles.cursorDefault]} |
42 | 57 | > |
43 | | - {translate('initialSettingsPage.troubleshoot.releaseOptions')} |
44 | | - </Text> |
45 | | - <RecordTroubleshootDataToolMenu /> |
46 | | - {!!shouldStoreLogs && ( |
47 | | - <TestToolRow title={translate('initialSettingsPage.troubleshoot.debugConsole')}> |
48 | | - <Button |
49 | | - small |
50 | | - text={translate('initialSettingsPage.debugConsole.viewConsole')} |
51 | | - onPress={() => { |
52 | | - Navigation.navigate(route); |
53 | | - }} |
54 | | - /> |
55 | | - </TestToolRow> |
56 | | - )} |
57 | | - <TestToolMenu /> |
| 58 | + <Text |
| 59 | + style={[styles.textLabelSupporting, styles.mt5, styles.mb3]} |
| 60 | + numberOfLines={1} |
| 61 | + > |
| 62 | + {translate('initialSettingsPage.troubleshoot.releaseOptions')} |
| 63 | + </Text> |
| 64 | + <RecordTroubleshootDataToolMenu /> |
| 65 | + {!!shouldStoreLogs && ( |
| 66 | + <TestToolRow title={translate('initialSettingsPage.troubleshoot.debugConsole')}> |
| 67 | + <Button |
| 68 | + small |
| 69 | + text={translate('initialSettingsPage.debugConsole.viewConsole')} |
| 70 | + onPress={() => { |
| 71 | + // Close the test tools modal first, then navigate to console page |
| 72 | + toggleTestToolsModal(); |
| 73 | + navigateAfterInteraction(() => { |
| 74 | + Navigation.navigate(consoleRoute); |
| 75 | + }); |
| 76 | + }} |
| 77 | + /> |
| 78 | + </TestToolRow> |
| 79 | + )} |
| 80 | + <TestToolMenu /> |
| 81 | + </PressableWithoutFeedback> |
58 | 82 | </ScrollView> |
59 | 83 | </View> |
60 | 84 | )} |
|
0 commit comments