diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 75687a483653..b8865d056d2b 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -502,7 +502,19 @@ function MoneyReportHeader({ } } else if (isInvoiceReport) { startAnimation(); - payInvoice(type, chatReport, moneyRequestReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy); + payInvoice({ + paymentMethodType: type, + chatReport, + invoiceReport: moneyRequestReport, + introSelected, + currentUserAccountIDParam: accountID, + currentUserEmailParam: email ?? '', + payAsBusiness, + existingB2BInvoiceReport, + methodID, + paymentMethod, + activePolicy, + }); } else { startAnimation(); payMoneyRequest(type, chatReport, moneyRequestReport, introSelected, undefined, true, activePolicy); @@ -534,6 +546,8 @@ function MoneyReportHeader({ currentSearchKey, isOffline, currentSearchResults?.search?.isLoading, + accountID, + email, ], ); diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 4885e059a74f..5be6c8ce835e 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -143,6 +143,8 @@ function MoneyRequestReportPreviewContent({ const {isOffline} = useNetwork(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const currentUserDetails = useCurrentUserPersonalDetails(); + const currentUserAccountID = currentUserDetails.accountID; + const currentUserEmail = currentUserDetails.email ?? ''; const expensifyIcons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'BackArrow', 'Location', 'ReceiptPlus']); const {areAllRequestsBeingSmartScanned, hasNonReimbursableTransactions} = useMemo( @@ -168,7 +170,7 @@ function MoneyRequestReportPreviewContent({ const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? ''); + const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail); const getCanIOUBePaid = useCallback( (shouldShowOnlyPayElsewhere = false) => canIOUBePaidIOUActions(iouReport, chatReport, policy, transactions, shouldShowOnlyPayElsewhere), @@ -248,13 +250,36 @@ function MoneyRequestReportPreviewContent({ } else if (chatReport && iouReport) { startAnimation(); if (isInvoiceReportUtils(iouReport)) { - payInvoice(type, chatReport, iouReport, introSelected, payAsBusiness, existingB2BInvoiceReport, methodID, paymentMethod, activePolicy); + payInvoice({ + paymentMethodType: type, + chatReport, + invoiceReport: iouReport, + introSelected, + currentUserAccountIDParam: currentUserAccountID, + currentUserEmailParam: currentUserEmail, + payAsBusiness, + existingB2BInvoiceReport, + methodID, + paymentMethod, + activePolicy, + }); } else { payMoneyRequest(type, chatReport, iouReport, introSelected, undefined, true, activePolicy); } } }, - [isDelegateAccessRestricted, iouReport, chatReport, showDelegateNoAccessModal, startAnimation, introSelected, existingB2BInvoiceReport, activePolicy], + [ + isDelegateAccessRestricted, + iouReport, + chatReport, + showDelegateNoAccessModal, + startAnimation, + introSelected, + existingB2BInvoiceReport, + activePolicy, + currentUserAccountID, + currentUserEmail, + ], ); const confirmApproval = () => { @@ -269,7 +294,7 @@ function MoneyRequestReportPreviewContent({ setIsHoldMenuVisible(true); } else { startApprovedAnimation(); - approveMoneyRequest(iouReport, activePolicy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true); + approveMoneyRequest(iouReport, activePolicy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true); } }; @@ -493,7 +518,7 @@ function MoneyRequestReportPreviewContent({ const reportPreviewAction = useMemo(() => { return getReportPreviewAction( isIouReportArchived || isChatReportArchived, - currentUserDetails.accountID, + currentUserAccountID, iouReport, policy, transactions, @@ -501,7 +526,7 @@ function MoneyRequestReportPreviewContent({ isPaidAnimationRunning, isApprovedAnimationRunning, isSubmittingAnimationRunning, - {currentUserEmail: currentUserDetails.email ?? '', violations: transactionViolations}, + {currentUserEmail, violations: transactionViolations}, ); }, [ isPaidAnimationRunning, @@ -513,8 +538,8 @@ function MoneyRequestReportPreviewContent({ isIouReportArchived, invoiceReceiverPolicy, isChatReportArchived, - currentUserDetails.accountID, - currentUserDetails.email, + currentUserEmail, + currentUserAccountID, transactionViolations, ]); @@ -537,7 +562,7 @@ function MoneyRequestReportPreviewContent({ return; } startSubmittingAnimation(); - submitReport(iouReport, policy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep); + submitReport(iouReport, policy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep); }} isSubmittingAnimationRunning={isSubmittingAnimationRunning} onAnimationFinish={stopAnimation} diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 18691cf3acbc..b7b974784d33 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -319,6 +319,20 @@ type MoneyRequestInformation = { reimbursable?: boolean; }; +type PayInvoiceArgs = { + paymentMethodType: PaymentMethodType; + chatReport: OnyxTypes.Report; + invoiceReport: OnyxEntry; + introSelected: OnyxEntry; + currentUserAccountIDParam: number; + currentUserEmailParam: string; + payAsBusiness?: boolean; + existingB2BInvoiceReport?: OnyxEntry; + methodID?: number; + paymentMethod?: PaymentMethod; + activePolicy?: OnyxTypes.Policy; +}; + type RejectMoneyRequestData = { optimisticData: OnyxUpdate[]; successData: OnyxUpdate[]; @@ -10326,6 +10340,9 @@ function getPayMoneyRequestParams({ full, payAsBusiness, bankAccountID, + currentUserAccountIDParam, + currentUserEmailParam, + introSelectedParam, paymentPolicyID, lastUsedPaymentMethod, existingB2BInvoiceReport, @@ -10342,6 +10359,9 @@ function getPayMoneyRequestParams({ lastUsedPaymentMethod?: OnyxTypes.LastPaymentMethodType; existingB2BInvoiceReport?: OnyxEntry; activePolicy?: OnyxEntry; + currentUserAccountIDParam?: number; + currentUserEmailParam?: string; + introSelectedParam?: OnyxEntry; }): PayMoneyRequestData { const isInvoiceReport = isInvoiceReportReportUtils(iouReport); let payerPolicyID = activePolicy?.id; @@ -10363,6 +10383,10 @@ function getPayMoneyRequestParams({ policyOwnerEmail: currentUserEmail, makeMeAdmin: true, policyID: payerPolicyID, + currentUserAccountIDParam, + currentUserEmailParam, + introSelectedParam, + activePolicyIDParam: activePolicy?.id, }); const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params; @@ -12090,17 +12114,19 @@ function payMoneyRequest( notifyNewAction(!full ? (Navigation.getTopmostReportId() ?? iouReport?.reportID) : iouReport?.reportID, userAccountID); } -function payInvoice( - paymentMethodType: PaymentMethodType, - chatReport: OnyxTypes.Report, - invoiceReport: OnyxEntry, - introSelected: OnyxEntry, +function payInvoice({ + paymentMethodType, + chatReport, + invoiceReport, + introSelected, + currentUserAccountIDParam, + currentUserEmailParam, payAsBusiness = false, - existingB2BInvoiceReport?: OnyxEntry, - methodID?: number, - paymentMethod?: PaymentMethod, - activePolicy?: OnyxTypes.Policy, -) { + existingB2BInvoiceReport, + methodID, + paymentMethod, + activePolicy, +}: PayInvoiceArgs) { const recipient = {accountID: invoiceReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID}; const { optimisticData, @@ -12128,6 +12154,9 @@ function payInvoice( bankAccountID: methodID, existingB2BInvoiceReport, activePolicy, + currentUserAccountIDParam, + currentUserEmailParam, + introSelectedParam: introSelected, }); const paymentSelected = paymentMethodType === CONST.IOU.PAYMENT_TYPE.VBBA ? CONST.IOU.PAYMENT_SELECTED.BBA : CONST.IOU.PAYMENT_SELECTED.PBA;