Skip to content

Commit

Permalink
Merge pull request #47097 from nkdengineer/fix/47054-regression
Browse files Browse the repository at this point in the history
fix onboarding promise
  • Loading branch information
srikarparsi authored Aug 9, 2024
2 parents 043e62b + de82f55 commit ad59bf3
Showing 1 changed file with 18 additions and 11 deletions.
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;

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

0 comments on commit ad59bf3

Please sign in to comment.