Skip to content

Commit

Permalink
Merge pull request #54353 from nkdengineer/fix/53476
Browse files Browse the repository at this point in the history
Remove isArray checks for onboarding
  • Loading branch information
carlosmiceli authored Dec 23, 2024
2 parents 614b99a + 8bffac5 commit 7de952d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
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 @@ -736,7 +736,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 @@ -8352,8 +8352,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

0 comments on commit 7de952d

Please sign in to comment.