Skip to content
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

fix onboarding promise #47097

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/libs/actions/Welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type OnboardingData = Onboarding | [] | undefined;

let isLoadingReportData = true;
let tryNewDotData: TryNewDot | undefined;
let onboarding: OnboardingData | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add my reviewing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated.


type HasCompletedOnboardingFlowProps = {
onCompleted?: () => void;
Expand All @@ -31,8 +32,8 @@ let isServerDataReadyPromise = new Promise<void>((resolve) => {
resolveIsReadyPromise = resolve;
});

let resolveOnboardingFlowStatus: (value?: OnboardingData) => void;
let isOnboardingFlowStatusKnownPromise = new Promise<OnboardingData>((resolve) => {
let resolveOnboardingFlowStatus: () => void;
let isOnboardingFlowStatusKnownPromise = new Promise<void>((resolve) => {
resolveOnboardingFlowStatus = resolve;
});

Expand All @@ -46,7 +47,7 @@ function onServerDataReady(): Promise<void> {
}

function isOnboardingFlowCompleted({onCompleted, onNotCompleted}: HasCompletedOnboardingFlowProps) {
isOnboardingFlowStatusKnownPromise.then((onboarding) => {
isOnboardingFlowStatusKnownPromise.then(() => {
if (Array.isArray(onboarding) || onboarding?.hasCompletedGuidedSetupFlow === undefined) {
return;
}
Expand Down Expand Up @@ -124,6 +125,17 @@ function checkTryNewDotDataReady() {
resolveTryNewDotStatus?.();
}

/**
* Check if the onboarding data is loaded
*/
function checkOnboardingDataReady() {
if (onboarding === undefined) {
return;
}

resolveOnboardingFlowStatus();
}

function setOnboardingPurposeSelected(value: OnboardingPurposeType) {
Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, value ?? null);
}
Expand Down Expand Up @@ -171,13 +183,8 @@ function completeHybridAppOnboarding() {
Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (value) => {
if (value === undefined) {
return;
}
resolveOnboardingFlowStatus(value);
isOnboardingFlowStatusKnownPromise = new Promise<OnboardingData>((resolve) => {
resolveOnboardingFlowStatus = resolve;
});
onboarding = value;
checkOnboardingDataReady();
},
});

Expand All @@ -202,7 +209,7 @@ function resetAllChecks() {
isServerDataReadyPromise = new Promise((resolve) => {
resolveIsReadyPromise = resolve;
});
isOnboardingFlowStatusKnownPromise = new Promise<OnboardingData>((resolve) => {
isOnboardingFlowStatusKnownPromise = new Promise<void>((resolve) => {
resolveOnboardingFlowStatus = resolve;
});
isLoadingReportData = true;
Expand Down
Loading