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

Remove isArray checks for onboarding #54353

Merged
merged 7 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID]: string;
[ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER]: boolean;

// NVP_ONBOARDING is an array for old users.
[ONYXKEYS.NVP_ONBOARDING]: Onboarding | [];
[ONYXKEYS.NVP_ONBOARDING]: Onboarding;

// ONYXKEYS.NVP_TRYNEWDOT is HybridApp onboarding data
[ONYXKEYS.NVP_TRYNEWDOT]: OnyxTypes.TryNewDot;
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ Onyx.connect({
},
});

let onboarding: OnyxEntry<Onboarding | []>;
let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (value) => (onboarding = value),
Expand Down Expand Up @@ -8354,8 +8354,8 @@ function shouldShowMerchantColumn(transactions: Transaction[]) {
* only use the Concierge chat.
*/
function isChatUsedForOnboarding(optionOrReport: OnyxEntry<Report> | OptionData): boolean {
// onboarding can be an array or an empty object for old accounts and accounts created from olddot
if (onboarding && !Array.isArray(onboarding) && !isEmptyObject(onboarding) && onboarding.chatReportID) {
// onboarding can be an empty object for old accounts and accounts created from olddot
if (onboarding && !isEmptyObject(onboarding) && onboarding.chatReportID) {
return onboarding.chatReportID === optionOrReport?.reportID;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Welcome/OnboardingFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Onyx.connect({
if (value === undefined) {
return;
}
onboardingValues = value as Onboarding;
onboardingValues = value;
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Welcome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type TryNewDot from '@src/types/onyx/TryNewDot';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as OnboardingFlow from './OnboardingFlow';

type OnboardingData = Onboarding | [] | undefined;
type OnboardingData = Onboarding | undefined;

let isLoadingReportData = true;
let tryNewDotData: TryNewDot | undefined;
Expand Down Expand Up @@ -44,7 +44,7 @@ function onServerDataReady(): Promise<void> {
let isOnboardingInProgress = false;
function isOnboardingFlowCompleted({onCompleted, onNotCompleted, onCanceled}: HasCompletedOnboardingFlowProps) {
isOnboardingFlowStatusKnownPromise.then(() => {
if (Array.isArray(onboarding) || isEmptyObject(onboarding) || onboarding?.hasCompletedGuidedSetupFlow === undefined) {
if (isEmptyObject(onboarding) || onboarding?.hasCompletedGuidedSetupFlow === undefined) {
onCanceled?.();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/onboardingSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
*/
function hasCompletedGuidedSetupFlowSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): boolean | undefined {
// Onboarding is an empty object for old accounts and accounts migrated from OldDot
if (Array.isArray(onboarding) || isEmptyObject(onboarding)) {
if (isEmptyObject(onboarding)) {
return true;
}

Expand Down Expand Up @@ -49,7 +49,7 @@ function tryNewDotOnyxSelector(tryNewDotData: OnyxValue<typeof ONYXKEYS.NVP_TRYN
* `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)) {
if (isEmptyObject(onboarding)) {
return false;
}

Expand Down
5 changes: 0 additions & 5 deletions tests/unit/OnboardingSelectorsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ describe('onboardingSelectors', () => {
// Not all users have this NVP defined as we did not run a migration to backfill it for existing accounts, hence we need to make sure
// the onboarding flow is only showed to the users with `hasCompletedGuidedSetupFlow` set to false
describe('hasCompletedGuidedSetupFlowSelector', () => {
// It might be the case that backend returns an empty array if the NVP is not defined on this particular account
it('Should return true if onboarding NVP is an array', () => {
const onboarding = [] as OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>;
expect(hasCompletedGuidedSetupFlowSelector(onboarding)).toBe(true);
});
it('Should return true if onboarding NVP is an empty object', () => {
const onboarding = {} as OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>;
expect(hasCompletedGuidedSetupFlowSelector(onboarding)).toBe(true);
Expand Down
Loading