Skip to content
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: 3 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
paymentMethod,
activePolicy,
betas,
isSelfTourViewed,
});
} else {
startAnimation();
Expand All @@ -644,6 +645,7 @@
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
});
if (currentSearchQueryJSON && !isOffline) {
Expand Down Expand Up @@ -679,6 +681,7 @@
shouldCalculateTotals,
currentSearchResults?.search?.isLoading,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
],
);
Expand Down Expand Up @@ -725,7 +728,7 @@
}, [iouTransactionID, requestParentReportAction, transactionThreadReport?.reportID, transactionViolations]);

const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const targetPolicyTags = defaultExpensePolicy ? (allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${defaultExpensePolicy.id}`] ?? {}) : {};

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 770) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

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

View workflow job for this annotation

GitHub Actions / ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 770) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

const duplicateExpenseTransaction = useCallback(
(transactionList: OnyxTypes.Transaction[]) => {
Expand Down Expand Up @@ -1859,7 +1862,7 @@
}
return option;
});
}, [originalSelectedTransactionsOptions, showDeleteModal, dismissedRejectUseExplanation]);

Check warning on line 1865 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

Check warning on line 1865 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

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 @@ -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);
Expand Down Expand Up @@ -123,6 +125,7 @@ function ProcessMoneyReportHoldMenu({
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
});
}
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 @@ -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);

Expand Down Expand Up @@ -290,6 +292,7 @@ function MoneyRequestReportPreviewContent({
paymentMethod,
activePolicy,
betas,
isSelfTourViewed,
});
} else {
payMoneyRequest({
Expand All @@ -302,6 +305,7 @@ function MoneyRequestReportPreviewContent({
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
});
}
Expand All @@ -321,6 +325,7 @@ function MoneyRequestReportPreviewContent({
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
],
);
Expand Down
9 changes: 9 additions & 0 deletions 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 | undefined;
};

type RejectMoneyRequestData = {
Expand Down Expand Up @@ -811,7 +812,7 @@
};

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

Check warning on line 815 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 @@ -904,10 +905,11 @@
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
policy?: OnyxEntry<OnyxTypes.Policy>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean | undefined;
};

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

Check warning on line 912 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 @@ -921,7 +923,7 @@
});

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

Check warning on line 926 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 @@ -930,7 +932,7 @@
});

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

Check warning on line 935 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 @@ -944,7 +946,7 @@
});

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

Check warning on line 949 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 @@ -957,7 +959,7 @@
});

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

Check warning on line 962 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 @@ -966,7 +968,7 @@
});

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

Check warning on line 971 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 @@ -976,7 +978,7 @@

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

Check warning on line 981 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 Down Expand Up @@ -10059,6 +10061,7 @@
activePolicy,
iouReportCurrentNextStepDeprecated,
betas,
isSelfTourViewed,
}: {
initialChatReport: OnyxTypes.Report;
iouReport: OnyxEntry<OnyxTypes.Report>;
Expand All @@ -10077,6 +10080,7 @@
introSelected?: OnyxEntry<OnyxTypes.IntroSelected>;
iouReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
isSelfTourViewed: boolean | undefined;
}): PayMoneyRequestData {
const isInvoiceReport = isInvoiceReportReportUtils(iouReport);
let payerPolicyID = activePolicy?.id;
Expand Down Expand Up @@ -10114,6 +10118,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 @@ -12017,6 +12022,7 @@
activePolicy,
policy,
betas,
isSelfTourViewed,
} = params;
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID, userBillingGraceEndPeriods)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
Expand All @@ -12039,6 +12045,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 @@ -12065,6 +12072,7 @@
activePolicy,
invoiceReportCurrentNextStepDeprecated,
betas,
isSelfTourViewed,
}: PayInvoiceArgs) {
const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
const {
Expand Down Expand Up @@ -12096,6 +12104,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
100 changes: 100 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6232,6 +6232,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
}
Expand Down Expand Up @@ -6436,6 +6437,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
}
Expand Down Expand Up @@ -6594,6 +6596,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
}
Expand Down Expand Up @@ -6644,6 +6647,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});

Expand Down Expand Up @@ -6756,6 +6760,7 @@ describe('actions/IOU', () => {
currentUserAccountID: CARLOS_ACCOUNT_ID,
full: false,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
return waitForBatchedUpdates();
Expand Down Expand Up @@ -6849,13 +6854,106 @@ describe('actions/IOU', () => {
full: false,
policy,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
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,
userBillingGraceEndPeriods: undefined,
});

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,
userBillingGraceEndPeriods: undefined,
});

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 @@ -6951,6 +7049,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
}
Expand Down Expand Up @@ -11386,6 +11485,7 @@ describe('actions/IOU', () => {
iouReportCurrentNextStepDeprecated: undefined,
currentUserAccountID: CARLOS_ACCOUNT_ID,
betas: [CONST.BETAS.ALL],
isSelfTourViewed: false,
userBillingGraceEndPeriods: undefined,
});
}
Expand Down
Loading