Skip to content
Open
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: 3 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@
paymentMethod,
activePolicy,
betas,
isSelfTourViewed,
});
} else {
startAnimation();
Expand All @@ -623,6 +624,7 @@
activePolicy,
policy,
betas,
isSelfTourViewed,
});
if (currentSearchQueryJSON && !isOffline) {
search({
Expand Down Expand Up @@ -657,6 +659,7 @@
shouldCalculateTotals,
currentSearchResults?.search?.isLoading,
betas,
isSelfTourViewed,
],
);

Expand Down Expand Up @@ -1776,7 +1779,7 @@
}
return option;
});
}, [originalSelectedTransactionsOptions, showDeleteModal, dismissedRejectUseExplanation]);

Check warning on line 1782 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

Check warning on line 1782 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

const shouldShowSelectedTransactionsButton = !!selectedTransactionsOptions.length && !transactionThreadReportID;

Expand Down
3 changes: 3 additions & 0 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -76,6 +77,7 @@ function ProcessMoneyReportHoldMenu({
const policy = usePolicy(moneyRequestReport?.policyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [isSelfTourViewed = false] = 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);
Expand Down Expand Up @@ -121,6 +123,7 @@ function ProcessMoneyReportHoldMenu({
activePolicy,
policy,
betas,
isSelfTourViewed,
});
}
onClose();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -185,6 +186,7 @@ function MoneyRequestReportPreviewContent({
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const isDEWBetaEnabled = isBetaEnabled(CONST.BETAS.NEW_DOT_DEW);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail);

Expand Down Expand Up @@ -275,6 +277,7 @@ function MoneyRequestReportPreviewContent({
paymentMethod,
activePolicy,
betas,
isSelfTourViewed,
});
} else {
payMoneyRequest({
Expand All @@ -287,6 +290,7 @@ function MoneyRequestReportPreviewContent({
activePolicy,
policy,
betas,
isSelfTourViewed,
});
}
}
Expand All @@ -305,6 +309,7 @@ function MoneyRequestReportPreviewContent({
activePolicy,
policy,
betas,
isSelfTourViewed,
],
);

Expand Down
23 changes: 22 additions & 1 deletion src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
paymentMethod?: PaymentMethod;
activePolicy?: OnyxTypes.Policy;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean;
};

type RejectMoneyRequestData = {
Expand Down Expand Up @@ -808,7 +809,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 812 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -898,10 +899,11 @@
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
policy?: OnyxEntry<OnyxTypes.Policy>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean;
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 906 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -915,7 +917,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 920 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -924,7 +926,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 929 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -938,7 +940,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 943 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -951,7 +953,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 956 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -960,7 +962,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 965 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -970,7 +972,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 975 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -979,7 +981,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 984 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -10029,6 +10031,7 @@
activePolicy,
iouReportCurrentNextStepDeprecated,
betas,
isSelfTourViewed,
}: {
initialChatReport: OnyxTypes.Report;
iouReport: OnyxEntry<OnyxTypes.Report>;
Expand All @@ -10047,6 +10050,7 @@
introSelected?: OnyxEntry<OnyxTypes.IntroSelected>;
iouReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean;
}): PayMoneyRequestData {
const isInvoiceReport = isInvoiceReportReportUtils(iouReport);
let payerPolicyID = activePolicy?.id;
Expand Down Expand Up @@ -10084,6 +10088,7 @@
introSelected,
activePolicyID: activePolicy?.id,
companySize: introSelected?.companySize as OnboardingCompanySize,
isSelfTourViewed,
});
const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params;

Expand Down Expand Up @@ -11970,7 +11975,20 @@
}

function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
const {paymentType, chatReport, iouReport, introSelected, iouReportCurrentNextStepDeprecated, currentUserAccountID, paymentPolicyID, full = true, activePolicy, policy, betas} = params;
const {
paymentType,
chatReport,
iouReport,
introSelected,
iouReportCurrentNextStepDeprecated,
currentUserAccountID,
paymentPolicyID,
full = true,
activePolicy,
policy,
betas,
isSelfTourViewed,
} = params;
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
return;
Expand All @@ -11992,6 +12010,7 @@
iouReportCurrentNextStepDeprecated,
currentUserAccountIDParam: currentUserAccountID,
betas,
isSelfTourViewed,
});

// For now, we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with
Expand All @@ -12018,6 +12037,7 @@
activePolicy,
invoiceReportCurrentNextStepDeprecated,
betas,
isSelfTourViewed,
}: PayInvoiceArgs) {
const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
const {
Expand Down Expand Up @@ -12049,6 +12069,7 @@
currentUserEmailParam,
introSelected,
betas,
isSelfTourViewed,
});

const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA;
Expand Down
98 changes: 98 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6230,6 +6230,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
}
return waitForBatchedUpdates();
Expand Down Expand Up @@ -6433,6 +6434,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
}
return waitForBatchedUpdates();
Expand Down Expand Up @@ -6590,6 +6592,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
}
return waitForBatchedUpdates();
Expand Down Expand Up @@ -6639,6 +6642,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});

await waitForBatchedUpdates();
Expand Down Expand Up @@ -6750,6 +6754,7 @@ describe('actions/IOU', () => {
currentUserAccountID: CARLOS_ACCOUNT_ID,
full: false,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
return waitForBatchedUpdates();
})
Expand Down Expand Up @@ -6842,12 +6847,103 @@ describe('actions/IOU', () => {
full: false,
policy,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
await waitForBatchedUpdates();
const newExpenseReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${newExpenseReportID}`);
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,
});

await waitForBatchedUpdates();

// The IOU report should be settled with optimistic data regardless of isSelfTourViewed
await new Promise<void>((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,
});

await waitForBatchedUpdates();

// The IOU report should be settled with optimistic data regardless of isSelfTourViewed
await new Promise<void>((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', () => {
Expand Down Expand Up @@ -6943,6 +7039,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
}
return waitForBatchedUpdates();
Expand Down Expand Up @@ -11311,6 +11408,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
});
}
await waitForBatchedUpdates();
Expand Down
Loading