Skip to content

Commit

Permalink
add hasCompletedGuidedSetupFlowSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgrzybowski committed Jul 9, 2024
1 parent ed75b69 commit 7316347
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useDisableModalDismissOnEscape from '@hooks/useDisableModalDismissOnEscap
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import hasCompletedGuidedSetupFlowSelector from '@libs/hasCompletedGuidedSetupFlowSelector';
import OnboardingModalNavigatorScreenOptions from '@libs/Navigation/AppNavigator/OnboardingModalNavigatorScreenOptions';
import Navigation from '@libs/Navigation/Navigation';
import type {OnboardingModalNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -27,13 +28,7 @@ function OnboardingModalNavigator() {
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: (onboarding) => {
// onboarding is an array for old accounts and accounts created from olddot
if (Array.isArray(onboarding)) {
return true;
}
return onboarding?.hasCompletedGuidedSetupFlow;
},
selector: hasCompletedGuidedSetupFlowSelector,
});

useDisableModalDismissOnEscape();
Expand Down
9 changes: 2 additions & 7 deletions src/libs/Navigation/NavigationRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useCurrentReportID from '@hooks/useCurrentReportID';
import useTheme from '@hooks/useTheme';
import useWindowDimensions from '@hooks/useWindowDimensions';
import {FSPage} from '@libs/Fullstory';
import hasCompletedGuidedSetupFlowSelector from '@libs/hasCompletedGuidedSetupFlowSelector';
import Log from '@libs/Log';
import {getPathFromURL} from '@libs/Url';
import {updateLastVisitedPath} from '@userActions/App';
Expand Down Expand Up @@ -81,13 +82,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
const {setActiveWorkspaceID} = useActiveWorkspace();

const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: (onboarding) => {
// onboarding is an array for old accounts and accounts created from olddot
if (Array.isArray(onboarding)) {
return true;
}
return onboarding?.hasCompletedGuidedSetupFlow;
},
selector: hasCompletedGuidedSetupFlowSelector,
});

const initialState = useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {prepareDraftComment} from '@libs/DraftCommentUtils';
import * as EmojiUtils from '@libs/EmojiUtils';
import * as Environment from '@libs/Environment/Environment';
import * as ErrorUtils from '@libs/ErrorUtils';
import hasCompletedGuidedSetupFlowSelector from '@libs/hasCompletedGuidedSetupFlowSelector';
import isPublicScreenRoute from '@libs/isPublicScreenRoute';
import * as Localize from '@libs/Localize';
import Log from '@libs/Log';
Expand Down Expand Up @@ -2573,7 +2574,7 @@ function openReportFromDeepLink(url: string) {

const state = navigationRef.getRootState();
const currentFocusedRoute = findFocusedRoute(state);
const hasCompletedGuidedSetupFlow = Array.isArray(onboarding) || onboarding?.hasCompletedGuidedSetupFlow;
const hasCompletedGuidedSetupFlow = hasCompletedGuidedSetupFlowSelector(onboarding);

// We need skip deeplinking if the user hasn't completed the guided setup flow.
if (!hasCompletedGuidedSetupFlow) {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/hasCompletedGuidedSetupFlowSelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type {OnyxValue} from 'react-native-onyx';
import type ONYXKEYS from '@src/ONYXKEYS';

function hasCompletedGuidedSetupFlowSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): boolean {
// onboarding is an array for old accounts and accounts created from olddot
if (Array.isArray(onboarding)) {
return true;
}
return onboarding?.hasCompletedGuidedSetupFlow ?? false;
}

export default hasCompletedGuidedSetupFlowSelector;

0 comments on commit 7316347

Please sign in to comment.