Skip to content
Closed
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
6 changes: 6 additions & 0 deletions src/libs/actions/IOU/TrackExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ type GetTrackExpenseInformationParams = {
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean;
// TODO: Make it required once we complete refactoring the getTrackExpenseInformation function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;
defaultWorkspaceName?: string;
optimisticChatReportID?: string;
currentUserLocalCurrency: string | undefined;
Expand Down Expand Up @@ -831,6 +833,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
defaultWorkspaceName,
optimisticChatReportID,
delegateAccountID,
hasCompletedGuidedSetupFlow,
currentUserLocalCurrency,
} = params;
const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams;
Expand Down Expand Up @@ -979,6 +982,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
hasActiveAdminPolicies: undefined,
betas,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
});
createdWorkspaceParams = workspaceData.params;
onyxData.optimisticData?.push(...(workspaceData.optimisticData ?? []));
Expand Down Expand Up @@ -2322,6 +2326,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
recentWaypoints = [],
betas,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
defaultWorkspaceName,
previousOdometerDraft,
delegateAccountID,
Expand Down Expand Up @@ -2483,6 +2488,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
quickAction,
betas,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
defaultWorkspaceName,
optimisticChatReportID,
delegateAccountID,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/IOU/types/CreateTrackExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type CreateTrackExpenseParams = {
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean;
// TODO: Make it required once we complete refactoring the trackExpense function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;
defaultWorkspaceName?: string;
currentUserLocalCurrency: string | undefined;
previousOdometerDraft?: OnyxEntry<OnyxTypes.OdometerDraft>;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ type BuildPolicyDataOptions = {
type?: typeof CONST.POLICY.TYPE.TEAM | typeof CONST.POLICY.TYPE.CORPORATE | typeof CONST.POLICY.TYPE.SUBMIT;
// TODO: Make it required once we complete refactoring the buildPolicyData function to use isSelfTourViewed. Refactor issue: https://github.com/Expensify/App/issues/66424
isSelfTourViewed?: boolean;
// TODO: Make it required once we complete refactoring the buildPolicyData function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424
hasCompletedGuidedSetupFlow?: boolean;
hasActiveAdminPolicies: boolean | undefined;
betas?: OnyxEntry<Beta[]>;
personalTrackGoal?: string;
Expand Down Expand Up @@ -2563,6 +2565,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
shouldCreateControlPolicy = false,
type,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
hasActiveAdminPolicies,
personalTrackGoal,
} = options;
Expand Down Expand Up @@ -3043,6 +3046,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
onboardingPurposeSelected,
companySize: companySize ?? (introSelected?.companySize as OnboardingCompanySize),
isSelfTourViewed,
hasCompletedGuidedSetupFlow,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@daledah Could we always pass hasCompletedGuidedSetupFlow as false in the failure data?

    if (!wasInvited) {
        failureData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: ONYXKEYS.NVP_ONBOARDING,
            value: {hasCompletedGuidedSetupFlow: hasCompletedGuidedSetupFlow ?? onboarding?.hasCompletedGuidedSetupFlow ?? null},
        });
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After a thorough check, i think we can pass hasCompletedGuidedSetupFlow as false in the failure data. I'll close this PR and will open the new PR soon

});
if (!onboardingData) {
return {successData, optimisticData, failureData, params};
Expand Down
9 changes: 5 additions & 4 deletions src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {StackScreenProps} from '@react-navigation/stack';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {guidedSetupAndTourStatusSelector} from '@selectors/Onboarding';
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
Expand Down Expand Up @@ -104,7 +104,7 @@ function SubmitDetailsPage({
const isLinkedTrackedExpenseReportArchived = useReportIsArchived(transaction?.linkedTrackedExpenseReportID);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [guidedSetupAndTourStatus] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: guidedSetupAndTourStatusSelector});
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [transactionDrafts] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftsSelector});
const draftTransactionIDs = Object.keys(transactionDrafts ?? {});
Expand Down Expand Up @@ -262,7 +262,8 @@ function SubmitDetailsPage({
recentWaypoints,
betas,
draftTransactionIDs,
isSelfTourViewed,
isSelfTourViewed: !!guidedSetupAndTourStatus?.isSelfTourViewed,
hasCompletedGuidedSetupFlow: guidedSetupAndTourStatus?.hasCompletedGuidedSetupFlow,
optimisticTransactionID,
currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD,
});
Expand Down Expand Up @@ -305,7 +306,7 @@ function SubmitDetailsPage({
existingTransactionDraft,
existingTransaction: storedTransaction ?? transaction,
draftTransactionIDs,
isSelfTourViewed,
isSelfTourViewed: !!guidedSetupAndTourStatus?.isSelfTourViewed,
betas,
personalDetails,
optimisticTransactionID,
Expand Down
7 changes: 5 additions & 2 deletions src/pages/iou/request/step/IOURequestStepAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useFocusEffect} from '@react-navigation/native';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {guidedSetupAndTourStatusSelector} from '@selectors/Onboarding';
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {Keyboard} from 'react-native';
Expand Down Expand Up @@ -133,7 +133,9 @@ function IOURequestStepAmount({
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [guidedSetupAndTourStatus] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: guidedSetupAndTourStatusSelector});
const isSelfTourViewed = !!guidedSetupAndTourStatus?.isSelfTourViewed;
const hasCompletedGuidedSetupFlow = guidedSetupAndTourStatus?.hasCompletedGuidedSetupFlow;
const betas = useContext(BetasContext);
const defaultExpensePolicy = useDefaultExpensePolicy();
const personalPolicy = usePersonalPolicy();
Expand Down Expand Up @@ -347,6 +349,7 @@ function IOURequestStepAmount({
betas,
draftTransactionIDs,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
optimisticChatReportID,
optimisticTransactionID,
currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {delegateEmailSelector} from '@selectors/Account';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {guidedSetupAndTourStatusSelector} from '@selectors/Onboarding';
import {useEffect, useRef, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import useActivePolicy from '@hooks/useActivePolicy';
Expand Down Expand Up @@ -254,7 +254,9 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
// Global Onyx values
const [userLocation] = useOnyx(ONYXKEYS.USER_LOCATION);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [guidedSetupAndTourStatus] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: guidedSetupAndTourStatusSelector});
const isSelfTourViewed = !!guidedSetupAndTourStatus?.isSelfTourViewed;
const hasCompletedGuidedSetupFlow = guidedSetupAndTourStatus?.hasCompletedGuidedSetupFlow;
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS);
Expand Down Expand Up @@ -680,6 +682,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
betas,
draftTransactionIDs,
isSelfTourViewed,
hasCompletedGuidedSetupFlow,
defaultWorkspaceName: generateDefaultWorkspaceName(email, lastWorkspaceNumber, translate),
previousOdometerDraft: odometerDraft,
reportActionsList: policyExpenseChatReportActions,
Expand Down
96 changes: 96 additions & 0 deletions tests/actions/IOUTest/TrackExpenseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,102 @@ describe('actions/IOU/TrackExpense', () => {
expect(resultWithoutTourViewed.chatReport).toBeDefined();
expect(resultWithoutTourViewed.transaction).toBeDefined();
});

it('should pass hasCompletedGuidedSetupFlow: true to trackExpense and create transaction successfully', async () => {
// Given a selfDM report
const selfDMReport: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM),
reportID: 'selfDM-guided-setup-1',
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport);

// When trackExpense is called with hasCompletedGuidedSetupFlow: true
trackExpense({
...getDefaultTrackExpenseParams(selfDMReport, {amount: 11000, merchant: 'Guided Setup Complete Merchant'}),
hasCompletedGuidedSetupFlow: true,
});
await waitForBatchedUpdates();

// Then the transaction should be created with correct values
let transactions: OnyxCollection<Transaction>;
await getOnyxData({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (val) => {
transactions = val;
},
});

const createdTransaction = Object.values(transactions ?? {}).at(0);
expect(createdTransaction).toBeTruthy();
expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(11000);
expect(createdTransaction?.merchant).toBe('Guided Setup Complete Merchant');
});

it('should pass hasCompletedGuidedSetupFlow: false to trackExpense and create transaction successfully', async () => {
// Given a selfDM report
const selfDMReport: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM),
reportID: 'selfDM-guided-setup-2',
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport);

// When trackExpense is called with hasCompletedGuidedSetupFlow: false
trackExpense({
...getDefaultTrackExpenseParams(selfDMReport, {amount: 8000, merchant: 'Guided Setup Incomplete Merchant'}),
hasCompletedGuidedSetupFlow: false,
});
await waitForBatchedUpdates();

// Then the transaction should be created with correct values
let transactions: OnyxCollection<Transaction>;
await getOnyxData({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (val) => {
transactions = val;
},
});

const createdTransaction = Object.values(transactions ?? {}).at(0);
expect(createdTransaction).toBeTruthy();
expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(8000);
expect(createdTransaction?.merchant).toBe('Guided Setup Incomplete Merchant');
});

it('should pass hasCompletedGuidedSetupFlow: undefined to trackExpense and create transaction successfully', async () => {
// Given a selfDM report
const selfDMReport: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM),
reportID: 'selfDM-guided-setup-3',
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport);

// When trackExpense is called without hasCompletedGuidedSetupFlow (undefined)
trackExpense({
...getDefaultTrackExpenseParams(selfDMReport, {amount: 6000, merchant: 'Guided Setup Undefined Merchant'}),
hasCompletedGuidedSetupFlow: undefined,
});
await waitForBatchedUpdates();

// Then the transaction should be created with correct values
let transactions: OnyxCollection<Transaction>;
await getOnyxData({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (val) => {
transactions = val;
},
});

const createdTransaction = Object.values(transactions ?? {}).at(0);
expect(createdTransaction).toBeTruthy();
expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(6000);
expect(createdTransaction?.merchant).toBe('Guided Setup Undefined Merchant');
});
});

describe('requestMoney', () => {
Expand Down
Loading