-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make onboarding continue from last visited onboarding page #47472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,24 @@ import type {OnyxUpdate} from 'react-native-onyx'; | |
import Onyx from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import {WRITE_COMMANDS} from '@libs/API/types'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import linkingConfig from '@libs/Navigation/linkingConfig'; | ||
import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
import getStateFromPath from '@navigation/getStateFromPath'; | ||
import getAdaptedStateFromPath from '@navigation/linkingConfig/getAdaptedStateFromPath'; | ||
import variables from '@styles/variables'; | ||
import type {OnboardingPurposeType} from '@src/CONST'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {Route} from '@src/ROUTES'; | ||
import type Onboarding from '@src/types/onyx/Onboarding'; | ||
import type TryNewDot from '@src/types/onyx/TryNewDot'; | ||
|
||
type OnboardingData = Onboarding | [] | undefined; | ||
|
||
let isLoadingReportData = true; | ||
let tryNewDotData: TryNewDot | undefined; | ||
let onboardingInitialPath = ''; | ||
let onboarding: OnboardingData; | ||
|
||
type HasCompletedOnboardingFlowProps = { | ||
|
@@ -46,15 +52,18 @@ function onServerDataReady(): Promise<void> { | |
return isServerDataReadyPromise; | ||
} | ||
|
||
let isOnboardingInProgress = false; | ||
function isOnboardingFlowCompleted({onCompleted, onNotCompleted}: HasCompletedOnboardingFlowProps) { | ||
isOnboardingFlowStatusKnownPromise.then(() => { | ||
if (Array.isArray(onboarding) || onboarding?.hasCompletedGuidedSetupFlow === undefined) { | ||
return; | ||
} | ||
|
||
if (onboarding?.hasCompletedGuidedSetupFlow) { | ||
isOnboardingInProgress = false; | ||
onCompleted?.(); | ||
} else { | ||
} else if (!isOnboardingInProgress) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevents multiple onboarding flow running causing navigation issue. |
||
isOnboardingInProgress = true; | ||
onNotCompleted?.(); | ||
} | ||
}); | ||
|
@@ -97,7 +106,7 @@ function handleHybridAppOnboarding() { | |
isOnboardingFlowCompleted({ | ||
onNotCompleted: () => | ||
setTimeout(() => { | ||
Navigation.navigate(ROUTES.ONBOARDING_ROOT.route); | ||
startOnboardingFlow(); | ||
}, variables.explanationModalDelay), | ||
}), | ||
}); | ||
|
@@ -152,6 +161,19 @@ function setOnboardingPolicyID(policyID?: string) { | |
Onyx.set(ONYXKEYS.ONBOARDING_POLICY_ID, policyID ?? null); | ||
} | ||
|
||
function updateOnboardingLastVisitedPath(path: string) { | ||
Onyx.merge(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, path); | ||
} | ||
|
||
function getOnboardingInitialPath(): Route { | ||
const state = getStateFromPath(onboardingInitialPath as Route); | ||
if (state?.routes?.at(-1)?.name !== NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR) { | ||
return ROUTES.ONBOARDING_ROOT.route as Route; | ||
} | ||
|
||
return onboardingInitialPath as Route; | ||
} | ||
|
||
function completeHybridAppOnboarding() { | ||
const optimisticData: OnyxUpdate[] = [ | ||
{ | ||
|
@@ -180,6 +202,11 @@ function completeHybridAppOnboarding() { | |
API.write(WRITE_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING, {}, {optimisticData, failureData}); | ||
} | ||
|
||
function startOnboardingFlow() { | ||
const {adaptedState} = getAdaptedStateFromPath(getOnboardingInitialPath(), linkingConfig.config, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really need to add an optional parameter to The path is being appended to the URL inserted by the user: Incorrect URL path:incorrect-path-d.mp4 |
||
navigationRef.resetRoot(adaptedState); | ||
} | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_ONBOARDING, | ||
callback: (value) => { | ||
|
@@ -188,6 +215,18 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
const onboardingLastVisitedPathConnection = Onyx.connect({ | ||
key: ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, | ||
callback: (value) => { | ||
if (value === undefined) { | ||
return; | ||
} | ||
|
||
onboardingInitialPath = value.substring(1); | ||
Onyx.disconnect(onboardingLastVisitedPathConnection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to disconnect here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we only need the initial value when the user opens the app or URL. I have tested it, the onboarding is triggered from |
||
}, | ||
}); | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||
initWithStoredValues: false, | ||
|
@@ -213,16 +252,21 @@ function resetAllChecks() { | |
resolveOnboardingFlowStatus = resolve; | ||
}); | ||
isLoadingReportData = true; | ||
onboardingInitialPath = ''; | ||
isOnboardingInProgress = false; | ||
} | ||
|
||
export { | ||
onServerDataReady, | ||
isOnboardingFlowCompleted, | ||
setOnboardingPurposeSelected, | ||
getOnboardingInitialPath, | ||
updateOnboardingLastVisitedPath, | ||
resetAllChecks, | ||
setOnboardingAdminsChatReportID, | ||
setOnboardingPolicyID, | ||
completeHybridAppOnboarding, | ||
handleHybridAppOnboarding, | ||
setOnboardingErrorMessage, | ||
startOnboardingFlow, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,9 @@ function BaseOnboardingPersonalDetails({ | |
Welcome.setOnboardingAdminsChatReportID(); | ||
Welcome.setOnboardingPolicyID(); | ||
|
||
Navigation.dismissModal(); | ||
// Navigate to HOME instead of dismissModal, because there is bug in small screen | ||
// where the onboarding puropose page will be disaplayed briefly | ||
Navigation.navigate(ROUTES.HOME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am changing Onboarding purpose disaplyed briefly:home-instead-of-dismiss-d.mp4 |
||
|
||
// Only navigate to concierge chat when central pane is visible | ||
// Otherwise stay on the chats screen. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am adding an optional parameter here, I really need it, more info here.