-
Notifications
You must be signed in to change notification settings - Fork 3k
/
onboardingSelectors.ts
58 lines (49 loc) · 2.26 KB
/
onboardingSelectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type {OnyxValue} from 'react-native-onyx';
import type ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
/**
* Selector to get the value of hasCompletedGuidedSetupFlow from the Onyx store
*
* `undefined` means the value is not loaded yet
* `true` means the user has completed the NewDot onboarding flow
* `false` means the user has not completed the NewDot onboarding flow
*/
function hasCompletedGuidedSetupFlowSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): boolean | undefined {
// Onboarding is an array or an empty object for old accounts and accounts created from OldDot
if (Array.isArray(onboarding) || isEmptyObject(onboarding)) {
return true;
}
if (!isEmptyObject(onboarding) && onboarding?.hasCompletedGuidedSetupFlow === undefined) {
return true;
}
return onboarding?.hasCompletedGuidedSetupFlow;
}
/**
* Selector to get the value of completedHybridAppOnboarding from the Onyx store
*
* `undefined` means the value is not loaded yet
* `true` means the user has completed the hybrid app onboarding flow
* `false` means the user has not completed the hybrid app onboarding flow
*/
function hasCompletedHybridAppOnboardingFlowSelector(tryNewDotData: OnyxValue<typeof ONYXKEYS.NVP_TRYNEWDOT>): boolean | undefined {
let completedHybridAppOnboarding = tryNewDotData?.classicRedirect?.completedHybridAppOnboarding;
// Backend might return strings instead of booleans
if (typeof completedHybridAppOnboarding === 'string') {
completedHybridAppOnboarding = completedHybridAppOnboarding === 'true';
}
return completedHybridAppOnboarding;
}
/**
* Selector to get the value of selfTourViewed from the Onyx store
*
* `undefined` means the value is not loaded yet
* `true` means the user has completed the NewDot onboarding flow
* `false` means the user has not completed the NewDot onboarding flow
*/
function hasSeenTourSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): boolean | undefined {
if (Array.isArray(onboarding) || isEmptyObject(onboarding)) {
return false;
}
return !!onboarding?.selfTourViewed;
}
export {hasCompletedGuidedSetupFlowSelector, hasCompletedHybridAppOnboardingFlowSelector, hasSeenTourSelector};