diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 34669cbad130..44fc289f20d7 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -631,6 +631,7 @@ function MoneyReportHeader({ paymentMethod, activePolicy, betas, + isSelfTourViewed, }); } else { startAnimation(); @@ -644,6 +645,7 @@ function MoneyReportHeader({ activePolicy, policy, betas, + isSelfTourViewed, userBillingGraceEndPeriods, }); if (currentSearchQueryJSON && !isOffline) { @@ -679,6 +681,7 @@ function MoneyReportHeader({ shouldCalculateTotals, currentSearchResults?.search?.isLoading, betas, + isSelfTourViewed, userBillingGraceEndPeriods, ], ); diff --git a/src/components/ProcessMoneyReportHoldMenu.tsx b/src/components/ProcessMoneyReportHoldMenu.tsx index ea8f986e5cc6..8c37efcc9273 100644 --- a/src/components/ProcessMoneyReportHoldMenu.tsx +++ b/src/components/ProcessMoneyReportHoldMenu.tsx @@ -1,3 +1,4 @@ +import {hasSeenTourSelector} from '@selectors/Onboarding'; import React, {useMemo} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; @@ -77,6 +78,7 @@ function ProcessMoneyReportHoldMenu({ const policy = usePolicy(moneyRequestReport?.policyID); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [betas] = useOnyx(ONYXKEYS.BETAS); + const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); const [moneyRequestReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`); const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); @@ -123,6 +125,7 @@ function ProcessMoneyReportHoldMenu({ activePolicy, policy, betas, + isSelfTourViewed, userBillingGraceEndPeriods, }); } diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 3bea4232d9d3..9f72a11a862f 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -1,4 +1,5 @@ import {useFocusEffect} from '@react-navigation/native'; +import {hasSeenTourSelector} from '@selectors/Onboarding'; import {FlashList} from '@shopify/flash-list'; import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list'; import React, {useCallback, useDeferredValue, useEffect, useMemo, useRef, useState} from 'react'; @@ -195,6 +196,7 @@ function MoneyRequestReportPreviewContent({ const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const [betas] = useOnyx(ONYXKEYS.BETAS); + const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); const isDEWBetaEnabled = isBetaEnabled(CONST.BETAS.NEW_DOT_DEW); const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail); @@ -290,6 +292,7 @@ function MoneyRequestReportPreviewContent({ paymentMethod, activePolicy, betas, + isSelfTourViewed, }); } else { payMoneyRequest({ @@ -302,6 +305,7 @@ function MoneyRequestReportPreviewContent({ activePolicy, policy, betas, + isSelfTourViewed, userBillingGraceEndPeriods, }); } @@ -321,6 +325,7 @@ function MoneyRequestReportPreviewContent({ activePolicy, policy, betas, + isSelfTourViewed, userBillingGraceEndPeriods, ], ); diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index f6e92b2b6764..b73cff31f133 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -333,6 +333,7 @@ type PayInvoiceArgs = { paymentMethod?: PaymentMethod; activePolicy?: OnyxTypes.Policy; betas: OnyxEntry; + isSelfTourViewed: boolean | undefined; }; type RejectMoneyRequestData = { @@ -904,6 +905,7 @@ type PayMoneyRequestFunctionParams = { activePolicy?: OnyxEntry; policy?: OnyxEntry; betas: OnyxEntry; + isSelfTourViewed: boolean | undefined; }; let allTransactions: NonNullable> = {}; @@ -10059,6 +10061,7 @@ function getPayMoneyRequestParams({ activePolicy, iouReportCurrentNextStepDeprecated, betas, + isSelfTourViewed, }: { initialChatReport: OnyxTypes.Report; iouReport: OnyxEntry; @@ -10077,6 +10080,7 @@ function getPayMoneyRequestParams({ introSelected?: OnyxEntry; iouReportCurrentNextStepDeprecated: OnyxEntry; betas: OnyxEntry; + isSelfTourViewed: boolean | undefined; }): PayMoneyRequestData { const isInvoiceReport = isInvoiceReportReportUtils(iouReport); let payerPolicyID = activePolicy?.id; @@ -10114,6 +10118,7 @@ function getPayMoneyRequestParams({ introSelected, activePolicyID: activePolicy?.id, companySize: introSelected?.companySize as OnboardingCompanySize, + isSelfTourViewed, }); const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params; @@ -12017,6 +12022,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { activePolicy, policy, betas, + isSelfTourViewed, } = params; if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID, userBillingGraceEndPeriods)) { Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID)); @@ -12039,6 +12045,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) { iouReportCurrentNextStepDeprecated, currentUserAccountIDParam: currentUserAccountID, betas, + isSelfTourViewed, }); // For now, we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with @@ -12065,6 +12072,7 @@ function payInvoice({ activePolicy, invoiceReportCurrentNextStepDeprecated, betas, + isSelfTourViewed, }: PayInvoiceArgs) { const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID}; const { @@ -12096,6 +12104,7 @@ function payInvoice({ currentUserEmailParam, introSelected, betas, + isSelfTourViewed, }); const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index b77d7abf57d3..f8fbd2387e04 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -6232,6 +6232,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); } @@ -6436,6 +6437,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID: CARLOS_ACCOUNT_ID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); } @@ -6594,6 +6596,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID: CARLOS_ACCOUNT_ID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); } @@ -6644,6 +6647,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID: CARLOS_ACCOUNT_ID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); @@ -6756,6 +6760,7 @@ describe('actions/IOU', () => { currentUserAccountID: CARLOS_ACCOUNT_ID, full: false, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); return waitForBatchedUpdates(); @@ -6849,6 +6854,7 @@ describe('actions/IOU', () => { full: false, policy, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); await waitForBatchedUpdates(); @@ -6856,6 +6862,98 @@ describe('actions/IOU', () => { expect(newExpenseReport?.stateNum).toBe(CONST.REPORT.STATE_NUM.OPEN); expect(newExpenseReport?.statusNum).toBe(CONST.REPORT.STATUS_NUM.OPEN); }); + + it('should accept isSelfTourViewed as true and apply optimistic data correctly', async () => { + const chatReport = { + ...createRandomReport(0, undefined), + lastReadTime: DateUtils.getDBTime(), + lastVisibleActionCreated: DateUtils.getDBTime(), + }; + const iouReport = { + ...createRandomReport(1, undefined), + chatType: undefined, + type: CONST.REPORT.TYPE.IOU, + total: 10, + }; + mockFetch?.pause?.(); + + jest.advanceTimersByTime(10); + + payMoneyRequest({ + paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + chatReport, + iouReport, + introSelected: undefined, + iouReportCurrentNextStepDeprecated: undefined, + currentUserAccountID: CARLOS_ACCOUNT_ID, + betas: [CONST.BETAS.ALL], + isSelfTourViewed: true, + userBillingGraceEndPeriods: undefined, + }); + + await waitForBatchedUpdates(); + + // The IOU report should be settled with optimistic data regardless of isSelfTourViewed + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + callback: (report) => { + Onyx.disconnect(connection); + expect(report?.hasOutstandingChildRequest).toBe(false); + expect(report?.statusNum).toBe(CONST.REPORT.STATUS_NUM.REIMBURSED); + resolve(); + }, + }); + }); + + mockFetch?.resume?.(); + }); + + it('should accept isSelfTourViewed as false and apply optimistic data correctly', async () => { + const chatReport = { + ...createRandomReport(0, undefined), + lastReadTime: DateUtils.getDBTime(), + lastVisibleActionCreated: DateUtils.getDBTime(), + }; + const iouReport = { + ...createRandomReport(1, undefined), + chatType: undefined, + type: CONST.REPORT.TYPE.IOU, + total: 10, + }; + mockFetch?.pause?.(); + + jest.advanceTimersByTime(10); + + payMoneyRequest({ + paymentType: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, + chatReport, + iouReport, + introSelected: undefined, + iouReportCurrentNextStepDeprecated: undefined, + currentUserAccountID: CARLOS_ACCOUNT_ID, + betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, + userBillingGraceEndPeriods: undefined, + }); + + await waitForBatchedUpdates(); + + // The IOU report should be settled with optimistic data regardless of isSelfTourViewed + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + callback: (report) => { + Onyx.disconnect(connection); + expect(report?.hasOutstandingChildRequest).toBe(false); + expect(report?.statusNum).toBe(CONST.REPORT.STATUS_NUM.REIMBURSED); + resolve(); + }, + }); + }); + + mockFetch?.resume?.(); + }); }); describe('a expense chat with a cancelled payment', () => { @@ -6951,6 +7049,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID: CARLOS_ACCOUNT_ID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); } @@ -11386,6 +11485,7 @@ describe('actions/IOU', () => { iouReportCurrentNextStepDeprecated: undefined, currentUserAccountID: CARLOS_ACCOUNT_ID, betas: [CONST.BETAS.ALL], + isSelfTourViewed: false, userBillingGraceEndPeriods: undefined, }); }