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
7 changes: 5 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePaymentOptions from '@hooks/usePaymentOptions';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions';
Expand Down Expand Up @@ -196,6 +197,7 @@ function MoneyReportHeader({
const isDownloadingPDF = download?.isDownloading ?? false;
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const activePolicy = usePolicy(activePolicyID);
const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES, {canBeMissing: true});
const [csvExportLayouts] = useOnyx(ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS, {canBeMissing: true});
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
Expand Down Expand Up @@ -414,10 +416,10 @@ function MoneyReportHeader({
}
} else if (isInvoiceReport) {
startAnimation();
payInvoice(type, chatReport, moneyRequestReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod);
payInvoice(type, chatReport, moneyRequestReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy);
} else {
startAnimation();
payMoneyRequest(type, chatReport, moneyRequestReport, introSelected, undefined, true);
payMoneyRequest(type, chatReport, moneyRequestReport, introSelected, undefined, true, activePolicy);
if (currentSearchQueryJSON) {
search({
searchKey: currentSearchKey,
Expand All @@ -439,6 +441,7 @@ function MoneyReportHeader({
moneyRequestReport,
introSelected,
existingB2BInvoiceReport,
activePolicy,
currentSearchQueryJSON,
currentSearchKey,
isOffline,
Expand Down
5 changes: 4 additions & 1 deletion src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import {approveMoneyRequest, payMoneyRequest} from '@userActions/IOU';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -62,6 +63,8 @@ function ProcessMoneyReportHoldMenu({
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to apply the correct modal type
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const activePolicy = usePolicy(activePolicyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});

const onSubmit = (full: boolean) => {
Expand All @@ -74,7 +77,7 @@ function ProcessMoneyReportHoldMenu({
if (startAnimation) {
startAnimation();
}
payMoneyRequest(paymentType, chatReport, moneyRequestReport, introSelected, undefined, full);
payMoneyRequest(paymentType, chatReport, moneyRequestReport, introSelected, undefined, full, activePolicy);
}
onClose();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -117,6 +118,7 @@ function MoneyRequestReportPreviewContent({
}: MoneyRequestReportPreviewContentProps) {
const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`, {canBeMissing: true, allowStaleData: true});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const activePolicy = usePolicy(activePolicyID);
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
const shouldShowLoading = !chatReportMetadata?.hasOnceLoadedReportActions && transactions.length === 0 && !chatReportMetadata?.isOptimisticReport;
// `hasOnceLoadedReportActions` becomes true before transactions populate fully,
Expand Down Expand Up @@ -232,13 +234,13 @@ function MoneyRequestReportPreviewContent({
} else if (chatReport && iouReport) {
startAnimation();
if (isInvoiceReportUtils(iouReport)) {
payInvoice(type, chatReport, iouReport, introSelected, payAsBusiness, existingB2BInvoiceReport);
payInvoice(type, chatReport, iouReport, introSelected, payAsBusiness, existingB2BInvoiceReport, undefined, undefined, activePolicy);
} else {
payMoneyRequest(type, chatReport, iouReport, introSelected);
payMoneyRequest(type, chatReport, iouReport, introSelected, undefined, true, activePolicy);
}
}
},
[isDelegateAccessRestricted, iouReport, chatReport, showDelegateNoAccessModal, startAnimation, introSelected, existingB2BInvoiceReport],
[isDelegateAccessRestricted, iouReport, chatReport, showDelegateNoAccessModal, startAnimation, introSelected, existingB2BInvoiceReport, activePolicy],
);

const confirmApproval = () => {
Expand Down
72 changes: 49 additions & 23 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {

Check warning on line 692 in src/libs/actions/IOU.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
allPersonalDetails = value ?? {};
},
});
Expand Down Expand Up @@ -730,13 +730,13 @@
let allBetas: OnyxEntry<OnyxTypes.Beta[]>;
Onyx.connect({
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),

Check warning on line 733 in src/libs/actions/IOU.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
});

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,

Check warning on line 739 in src/libs/actions/IOU.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
callback: (value) => {
if (!value) {
allTransactions = {};
Expand All @@ -750,7 +750,7 @@
let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,

Check warning on line 753 in src/libs/actions/IOU.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
callback: (value) => {
allTransactionDrafts = value ?? {};
},
Expand All @@ -759,7 +759,7 @@
let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,

Check warning on line 762 in src/libs/actions/IOU.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
callback: (value) => {
if (!value) {
allTransactionViolations = {};
Expand All @@ -773,7 +773,7 @@
let allDraftSplitTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT,
waitForCollectionCallback: true,

Check warning on line 776 in src/libs/actions/IOU.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
callback: (value) => {
allDraftSplitTransactions = value ?? {};
},
Expand All @@ -782,7 +782,7 @@
let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStep>> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,

Check warning on line 785 in src/libs/actions/IOU.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
callback: (value) => {
allNextSteps = value ?? {};
},
Expand All @@ -791,14 +791,14 @@
let allPolicyCategories: OnyxCollection<OnyxTypes.PolicyCategories> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_CATEGORIES,
waitForCollectionCallback: true,

Check warning on line 794 in src/libs/actions/IOU.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
callback: (val) => (allPolicyCategories = val),
});

const allPolicies: OnyxCollection<OnyxTypes.Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {

Check warning on line 801 in src/libs/actions/IOU.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
if (!key) {
return;
}
Expand Down Expand Up @@ -834,7 +834,7 @@
let allRecentlyUsedTags: OnyxCollection<RecentlyUsedTags> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS,
waitForCollectionCallback: true,

Check warning on line 837 in src/libs/actions/IOU.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
callback: (val) => (allRecentlyUsedTags = val),
});

Expand Down Expand Up @@ -894,12 +894,6 @@
},
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});

let personalDetailsList: OnyxEntry<OnyxTypes.PersonalDetailsList>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
Expand Down Expand Up @@ -9439,23 +9433,35 @@
};
}

function getPayMoneyRequestParams(
initialChatReport: OnyxTypes.Report,
iouReport: OnyxEntry<OnyxTypes.Report>,
recipient: Participant,
paymentMethodType: PaymentMethodType,
full: boolean,
payAsBusiness?: boolean,
bankAccountID?: number,
paymentPolicyID?: string | undefined,
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType,
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>,
): PayMoneyRequestData {
function getPayMoneyRequestParams({
initialChatReport,
iouReport,
recipient,
paymentMethodType,
full,
payAsBusiness,
bankAccountID,
paymentPolicyID,
lastUsedPaymentMethod,
existingB2BInvoiceReport,
activePolicy,
}: {
initialChatReport: OnyxTypes.Report;
iouReport: OnyxEntry<OnyxTypes.Report>;
recipient: Participant;
paymentMethodType: PaymentMethodType;
full: boolean;
payAsBusiness?: boolean;
bankAccountID?: number;
paymentPolicyID?: string | undefined;
lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType;
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>;
activePolicy?: OnyxEntry<OnyxTypes.Policy>;
}): PayMoneyRequestData {
const isInvoiceReport = isInvoiceReportReportUtils(iouReport);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line deprecation/deprecation
const activePolicy = getPolicy(activePolicyID);
let payerPolicyID = activePolicyID;
let payerPolicyID = activePolicy?.id;
let chatReport = initialChatReport;
let policyParams = {};
const optimisticData: OnyxUpdate[] = [];
Expand Down Expand Up @@ -9491,7 +9497,7 @@

optimisticData.push(...policyOptimisticData, {onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, value: payerPolicyID});
successData.push(...policySuccessData);
failureData.push(...policyFailureData, {onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, value: activePolicyID ?? null});
failureData.push(...policyFailureData, {onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, value: activePolicy?.id ?? null});
}

if (isIndividualInvoiceRoom(chatReport) && payAsBusiness && existingB2BInvoiceReport) {
Expand Down Expand Up @@ -10870,6 +10876,7 @@
introSelected: OnyxEntry<OnyxTypes.IntroSelected>,
paymentPolicyID?: string,
full = true,
activePolicy?: OnyxEntry<OnyxTypes.Policy>,
) {
if (chatReport.policyID && shouldRestrictUserBillableActions(chatReport.policyID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
Expand All @@ -10880,7 +10887,15 @@
completePaymentOnboarding(paymentSelected, introSelected);

const recipient = {accountID: iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentType, full, undefined, undefined, paymentPolicyID);
const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams({
initialChatReport: chatReport,
iouReport,
recipient,
paymentMethodType: paymentType,
full,
paymentPolicyID,
activePolicy,
});

// For now, we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with
// Expensify Wallets.
Expand All @@ -10900,6 +10915,7 @@
existingB2BInvoiceReport?: OnyxEntry<OnyxTypes.Report>,
methodID?: number,
paymentMethod?: PaymentMethod,
activePolicy?: OnyxTypes.Policy,
) {
const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID};
const {
Expand All @@ -10918,7 +10934,17 @@
ownerEmail,
policyName,
},
} = getPayMoneyRequestParams(chatReport, invoiceReport, recipient, paymentMethodType, true, payAsBusiness, methodID, undefined, undefined, existingB2BInvoiceReport);
} = getPayMoneyRequestParams({
initialChatReport: chatReport,
iouReport: invoiceReport,
recipient,
paymentMethodType,
full: true,
payAsBusiness,
bankAccountID: methodID,
existingB2BInvoiceReport,
activePolicy,
});

const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA;
completePaymentOnboarding(paymentSelected, introSelected);
Expand Down
Loading