From 697b6830c7042ed173c6129e74b10a168632ff1b Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:02:56 +0200 Subject: [PATCH 01/19] Refactor useNonReimbursablePaymentModal to be fully imperative --- .../MoneyRequestReportPreviewContent.tsx | 3 +- .../ListItem/ActionCell/PayActionCell.tsx | 3 +- ....tsx => useNonReimbursablePaymentModal.ts} | 31 ++++++------------- 3 files changed, 11 insertions(+), 26 deletions(-) rename src/hooks/{useNonReimbursablePaymentModal.tsx => useNonReimbursablePaymentModal.ts} (50%) diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 86535e539fd6..fd93bcbfc214 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -152,7 +152,7 @@ function MoneyRequestReportPreviewContent({ const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); const [requestType, setRequestType] = useState(); - const {showNonReimbursablePaymentErrorModal, nonReimbursablePaymentErrorDecisionModal} = useNonReimbursablePaymentModal(iouReport, transactions); + const {showNonReimbursablePaymentErrorModal} = useNonReimbursablePaymentModal(iouReport, transactions); const [paymentType, setPaymentType] = useState(); const [shouldShowPayButton, setShouldShowPayButton] = useState(false); const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(iouReport?.reportID); @@ -748,7 +748,6 @@ function MoneyRequestReportPreviewContent({ ); })()} - {nonReimbursablePaymentErrorDecisionModal} ); } diff --git a/src/components/Search/SearchList/ListItem/ActionCell/PayActionCell.tsx b/src/components/Search/SearchList/ListItem/ActionCell/PayActionCell.tsx index a62048c9b78b..6aa6c38790ea 100644 --- a/src/components/Search/SearchList/ListItem/ActionCell/PayActionCell.tsx +++ b/src/components/Search/SearchList/ListItem/ActionCell/PayActionCell.tsx @@ -34,7 +34,7 @@ function PayActionCell({isLoading, policyID, reportID, hash, amount, extraSmall, const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); const [iouReport, transactions] = useReportWithTransactionsAndViolations(reportID); - const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment, nonReimbursablePaymentErrorDecisionModal} = useNonReimbursablePaymentModal(iouReport, transactions); + const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(iouReport, transactions); const policy = usePolicy(policyID); const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`); @@ -97,7 +97,6 @@ function PayActionCell({isLoading, policyID, reportID, hash, amount, extraSmall, onlyShowPayElsewhere={shouldOnlyShowElsewhere} sentryLabel={CONST.SENTRY_LABEL.SEARCH.ACTION_CELL_PAY} /> - {nonReimbursablePaymentErrorDecisionModal} ); } diff --git a/src/hooks/useNonReimbursablePaymentModal.tsx b/src/hooks/useNonReimbursablePaymentModal.ts similarity index 50% rename from src/hooks/useNonReimbursablePaymentModal.tsx rename to src/hooks/useNonReimbursablePaymentModal.ts index 121a55b60ffb..d37e7bccbbb2 100644 --- a/src/hooks/useNonReimbursablePaymentModal.tsx +++ b/src/hooks/useNonReimbursablePaymentModal.ts @@ -1,48 +1,35 @@ -import React, {useState} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; -import DecisionModal from '@components/DecisionModal'; import {hasOnlyNonReimbursableTransactions, isInvoiceReport} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import type {Report, Transaction} from '@src/types/onyx'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import useDecisionModal from './useDecisionModal'; import useLocalize from './useLocalize'; -import useResponsiveLayout from './useResponsiveLayout'; type UseNonReimbursablePaymentModalReturn = { showNonReimbursablePaymentErrorModal: () => void; shouldBlockDirectPayment: (paymentType: PaymentMethodType) => boolean; - nonReimbursablePaymentErrorDecisionModal: React.ReactNode; }; /** Blocks direct payment and shows the error modal when the report contains only non-reimbursable expenses. */ function useNonReimbursablePaymentModal(iouReport: OnyxEntry, transactions?: Transaction[]): UseNonReimbursablePaymentModalReturn { - const [isModalVisible, setIsModalVisible] = useState(false); const {translate} = useLocalize(); - // We need to use isSmallScreenWidth here because the DecisionModal breaks in RHP with shouldUseNarrowLayout. - // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth - const {isSmallScreenWidth} = useResponsiveLayout(); + const {showDecisionModal} = useDecisionModal(); - const showNonReimbursablePaymentErrorModal = () => setIsModalVisible(true); + const showNonReimbursablePaymentErrorModal = () => { + showDecisionModal({ + title: translate('iou.error.nonReimbursablePayment'), + prompt: translate('iou.error.nonReimbursablePaymentDescription', false), + secondOptionText: translate('common.buttonConfirm'), + }); + }; const shouldBlockDirectPayment = (paymentType: PaymentMethodType): boolean => !isInvoiceReport(iouReport) && hasOnlyNonReimbursableTransactions(iouReport?.reportID, transactions) && paymentType !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE; - const nonReimbursablePaymentErrorDecisionModal = ( - setIsModalVisible(false)} - secondOptionText={translate('common.buttonConfirm')} - isVisible={isModalVisible} - onClose={() => setIsModalVisible(false)} - /> - ); - return { showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment, - nonReimbursablePaymentErrorDecisionModal, }; } From 5caacde9d305278bc071b0d14c0da96116feeb4f Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:12:04 +0200 Subject: [PATCH 02/19] Refactor ProcessMoneyReportHoldMenu to use onConfirm callback pattern --- src/components/MoneyReportHeader.tsx | 6 ++--- src/components/ProcessMoneyReportHoldMenu.tsx | 26 ++++++++++--------- .../MoneyRequestReportPreviewContent.tsx | 3 +-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 28b2e43d3114..f85b93e3e9cf 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -513,7 +513,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa const shouldDisplayNarrowMoreButton = !shouldDisplayNarrowVersion || isWideRHPDisplayedOnWideLayout || isSuperWideRHPDisplayedOnWideLayout; - const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment, nonReimbursablePaymentErrorDecisionModal} = useNonReimbursablePaymentModal(moneyRequestReport, transactions); + const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(moneyRequestReport, transactions); const showExportProgressModal = useCallback(() => { return showConfirmModal({ @@ -2224,7 +2224,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa chatReport={chatReport} moneyRequestReport={moneyRequestReport} hasNonHeldExpenses={!hasOnlyHeldExpenses} - startAnimation={() => { + onConfirm={() => { if (isSelectionModePaymentRef.current) { clearSelectedTransactions(true); return; @@ -2237,7 +2237,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa }} transactionCount={transactionIDs?.length ?? 0} transactions={transactions} - onNonReimbursablePaymentError={showNonReimbursablePaymentErrorModal} /> )} setIsHoldEducationalModalVisible(false)} onRejectModalDismissed={() => setRejectModalAction(null)} /> - {nonReimbursablePaymentErrorDecisionModal} void; + /** Callback invoked after the user confirms pay/approve, receives whether the full amount was chosen */ + onConfirm?: (full: boolean) => void; /** Whether the report has non held expenses */ hasNonHeldExpenses?: boolean; - /** Callback when user attempts to pay via ACH but report has only non-reimbursable expenses */ - onNonReimbursablePaymentError?: () => void; - /** Transactions associated with report */ transactions?: OnyxTypes.Transaction[]; }; @@ -74,9 +72,8 @@ function ProcessMoneyReportHoldMenu({ chatReport, moneyRequestReport, transactionCount, - startAnimation, + onConfirm, hasNonHeldExpenses, - onNonReimbursablePaymentError, transactions, }: ProcessMoneyReportHoldMenuProps) { const {translate} = useLocalize(); @@ -102,17 +99,22 @@ function ProcessMoneyReportHoldMenu({ const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); + const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(moneyRequestReport, transactions); + const onSubmit = (full: boolean) => { if (isDelegateAccessRestricted) { showDelegateNoAccessModal(); return; } - if (!isApprove && chatReport && hasOnlyNonReimbursableTransactions(moneyRequestReport?.reportID, transactions) && paymentType && paymentType !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + if (!isApprove && paymentType && shouldBlockDirectPayment(paymentType)) { onClose(); - onNonReimbursablePaymentError?.(); + showNonReimbursablePaymentErrorModal(); return; } + + const animationCallback = () => onConfirm?.(full); + if (isApprove) { approveMoneyRequest({ expenseReport: moneyRequestReport, @@ -127,7 +129,7 @@ function ProcessMoneyReportHoldMenu({ amountOwed, ownerBillingGracePeriodEnd, full, - onApproved: startAnimation, + onApproved: animationCallback, }); } else if (chatReport && paymentType) { payMoneyRequest({ @@ -146,7 +148,7 @@ function ProcessMoneyReportHoldMenu({ amountOwed, ownerBillingGracePeriodEnd, methodID, - onPaid: startAnimation, + onPaid: animationCallback, }); } onClose(); diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index fd93bcbfc214..e334959ef39e 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -736,14 +736,13 @@ function MoneyRequestReportPreviewContent({ transactionCount={numberOfRequests} transactions={transactions} hasNonHeldExpenses={!hasOnlyHeldExpenses} - startAnimation={() => { + onConfirm={() => { if (requestType === CONST.IOU.REPORT_ACTION_TYPE.APPROVE) { startApprovedAnimation(); } else { startAnimation(); } }} - onNonReimbursablePaymentError={showNonReimbursablePaymentErrorModal} /> ); })()} From 0815e3bfe1ba48975dabbacbd3cbd5edbb623d54 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:17:44 +0200 Subject: [PATCH 03/19] Add MoneyReportHeaderModalsContext --- .../MoneyReportHeaderModalsContext.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/components/MoneyReportHeaderModalsContext.tsx diff --git a/src/components/MoneyReportHeaderModalsContext.tsx b/src/components/MoneyReportHeaderModalsContext.tsx new file mode 100644 index 000000000000..9ffec0ac5033 --- /dev/null +++ b/src/components/MoneyReportHeaderModalsContext.tsx @@ -0,0 +1,37 @@ +import React, {createContext, useContext} from 'react'; +import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import type {RejectModalAction} from './MoneyReportHeaderEducationalModals'; +import type {ActionHandledType} from './ProcessMoneyReportHoldMenu'; + +type HoldMenuParams = { + requestType: ActionHandledType; + paymentType?: PaymentMethodType; + methodID?: number; + onConfirm?: (full: boolean) => void; +}; + +type MoneyReportHeaderModalsContextValue = { + openHoldMenu: (params: HoldMenuParams) => void; + closeHoldMenu: () => void; + openPDFDownload: () => void; + openHoldEducational: () => void; + openRejectModal: (action: RejectModalAction) => void; +}; + +const defaultValue: MoneyReportHeaderModalsContextValue = { + openHoldMenu: () => {}, + closeHoldMenu: () => {}, + openPDFDownload: () => {}, + openHoldEducational: () => {}, + openRejectModal: () => {}, +}; + +const MoneyReportHeaderModalsContext = createContext(defaultValue); + +function useMoneyReportHeaderModals() { + return useContext(MoneyReportHeaderModalsContext); +} + +export default MoneyReportHeaderModalsContext; +export {useMoneyReportHeaderModals}; +export type {HoldMenuParams}; From c4656c9504b0751a866f3ea3ca8fa1bfea813581 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:23:48 +0200 Subject: [PATCH 04/19] Add MoneyReportHeaderModals provider component --- src/components/MoneyReportHeaderModals.tsx | 153 +++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/components/MoneyReportHeaderModals.tsx diff --git a/src/components/MoneyReportHeaderModals.tsx b/src/components/MoneyReportHeaderModals.tsx new file mode 100644 index 000000000000..a387bb36e87c --- /dev/null +++ b/src/components/MoneyReportHeaderModals.tsx @@ -0,0 +1,153 @@ +import React, {useRef, useState} from 'react'; +import type {ReactNode} from 'react'; +import {InteractionManager} from 'react-native'; +import useNetwork from '@hooks/useNetwork'; +import useOnyx from '@hooks/useOnyx'; +import usePaginatedReportActions from '@hooks/usePaginatedReportActions'; +import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport'; +import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; +import getPlatform from '@libs/getPlatform'; +import {getAllNonDeletedTransactions} from '@libs/MoneyRequestReportUtils'; +import {getFilteredReportActionsForReportView, getOneTransactionThreadReportID, getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils'; +import {getNonHeldAndFullAmount, hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils} from '@libs/ReportUtils'; +import {canIOUBePaid as canIOUBePaidAction} from '@userActions/IOU'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxTypes from '@src/types/onyx'; +import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import MoneyReportHeaderEducationalModals from './MoneyReportHeaderEducationalModals'; +import type {RejectModalAction} from './MoneyReportHeaderEducationalModals'; +import MoneyReportHeaderModalsContext from './MoneyReportHeaderModalsContext'; +import type {HoldMenuParams} from './MoneyReportHeaderModalsContext'; +import type {ActionHandledType} from './ProcessMoneyReportHoldMenu'; +import ProcessMoneyReportHoldMenu from './ProcessMoneyReportHoldMenu'; +import ReportPDFDownloadModal from './ReportPDFDownloadModal'; + +type MoneyReportHeaderModalsProps = { + reportID: string | undefined; + children: ReactNode; +}; + +function MoneyReportHeaderModals({reportID, children}: MoneyReportHeaderModalsProps) { + // Hold menu state + const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); + const [paymentType, setPaymentType] = useState(); + const [requestType, setRequestType] = useState(); + const [selectedVBBA, setSelectedVBBA] = useState(); + const holdMenuOnConfirmRef = useRef<((full: boolean) => void) | undefined>(); + + // Educational modals state + const [isHoldEducationalModalVisible, setIsHoldEducationalModalVisible] = useState(false); + const [rejectModalAction, setRejectModalAction] = useState(null); + + // PDF modal state + const [isPDFModalVisible, setIsPDFModalVisible] = useState(false); + + // Fetch data from IDs + const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`); + const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`); + const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); + const {isOffline} = useNetwork(); + + const {reportActions: unfilteredReportActions} = usePaginatedReportActions(moneyRequestReport?.reportID); + const reportActions = getFilteredReportActionsForReportView(unfilteredReportActions); + + const {transactions: reportTransactions} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID); + const transactions = Object.values(reportTransactions); + + // Derive data for hold menu + const canIOUBePaid = canIOUBePaidAction(moneyRequestReport, chatReport, policy, bankAccountList); + const shouldShowPayButton = canIOUBePaid; + const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton); + const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID); + const transactionIDs = transactions.map((t) => t.transactionID); + + // Derive data for educational modals + const nonDeletedTransactions = getAllNonDeletedTransactions(transactions, reportActions, isOffline, true); + const visibleTransactionsForThreadID = nonDeletedTransactions?.filter((t) => isOffline || t.pendingAction !== 'delete'); + const reportTransactionIDs = visibleTransactionsForThreadID?.map((t) => t.transactionID); + const transactionThreadReportID = getOneTransactionThreadReportID(moneyRequestReport, chatReport, reportActions ?? [], isOffline, reportTransactionIDs); + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`); + + const requestParentReportAction = (() => { + if (!reportActions || !transactionThreadReport?.parentReportActionID) { + return null; + } + return reportActions.find((action): action is OnyxTypes.ReportAction => action.reportActionID === transactionThreadReport.parentReportActionID); + })(); + + const iouTransactionID = isMoneyRequestAction(requestParentReportAction) ? getOriginalMessage(requestParentReportAction)?.IOUTransactionID : undefined; + const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(iouTransactionID)}`); + + // Context API + const openHoldMenu = ({requestType: type, paymentType: pType, methodID, onConfirm}: HoldMenuParams) => { + setRequestType(type); + setPaymentType(pType); + setSelectedVBBA(pType === CONST.IOU.PAYMENT_TYPE.VBBA ? methodID : undefined); + holdMenuOnConfirmRef.current = onConfirm; + if (getPlatform() === CONST.PLATFORM.IOS) { + // InteractionManager delays modal until current interaction completes, preventing visual glitches on iOS + // eslint-disable-next-line @typescript-eslint/no-deprecated + InteractionManager.runAfterInteractions(() => setIsHoldMenuVisible(true)); + } else { + setIsHoldMenuVisible(true); + } + }; + + const closeHoldMenu = () => { + setSelectedVBBA(undefined); + setIsHoldMenuVisible(false); + holdMenuOnConfirmRef.current = undefined; + }; + + const contextValue = { + openHoldMenu, + closeHoldMenu, + openPDFDownload: () => setIsPDFModalVisible(true), + openHoldEducational: () => setIsHoldEducationalModalVisible(true), + openRejectModal: (action: RejectModalAction) => setRejectModalAction(action), + }; + + return ( + + {children} + + {isHoldMenuVisible && requestType !== undefined && ( + holdMenuOnConfirmRef.current?.(full)} + transactionCount={transactionIDs.length} + transactions={transactions} + /> + )} + + setIsHoldEducationalModalVisible(false)} + onRejectModalDismissed={() => setRejectModalAction(null)} + /> + + setIsPDFModalVisible(false)} + /> + + ); +} + +export default MoneyReportHeaderModals; From 25ec7ca45e0171928c05ea3b990676687f83845c Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:29:34 +0200 Subject: [PATCH 05/19] Wire MoneyReportHeader to use MoneyReportHeaderModals provider --- src/components/MoneyReportHeader.tsx | 275 +++++++++++---------------- 1 file changed, 108 insertions(+), 167 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index f85b93e3e9cf..770fbd41f433 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -4,7 +4,7 @@ import {hasSeenTourSelector, isTrackIntentUserSelector} from '@selectors/Onboard import passthroughPolicyTagListSelector from '@selectors/PolicyTagList'; import {validTransactionDraftsSelector} from '@selectors/TransactionDraft'; import truncate from 'lodash/truncate'; -import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; +import React, {useCallback, useContext, useEffect, useMemo, useRef} from 'react'; import type {StyleProp, ViewStyle} from 'react-native'; import {InteractionManager, View} from 'react-native'; import type {ValueOf} from 'type-fest'; @@ -54,7 +54,6 @@ import {deleteAppReport, exportReportToCSV, exportReportToPDF, exportToIntegrati import {getExportTemplates, queueExportSearchWithTemplate, search} from '@libs/actions/Search'; import initSplitExpense from '@libs/actions/SplitExpenses'; import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; -import getPlatform from '@libs/getPlatform'; import {getExistingTransactionID} from '@libs/IOUUtils'; import Log from '@libs/Log'; import {getAllNonDeletedTransactions, getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils'; @@ -93,11 +92,9 @@ import { getIntegrationIcon, getIntegrationNameFromExportMessage as getIntegrationNameFromExportMessageUtils, getNextApproverAccountID, - getNonHeldAndFullAmount, getPolicyExpenseChat, getReasonAndReportActionThatRequiresAttention, hasHeldExpenses as hasHeldExpensesReportUtils, - hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils, hasOnlyNonReimbursableTransactions, hasUpdatedTotal, hasViolations as hasViolationsReportUtils, @@ -159,9 +156,9 @@ import HeaderWithBackButton from './HeaderWithBackButton'; import {KYCWallContext} from './KYCWall/KYCWallContext'; import {useLockedAccountActions, useLockedAccountState} from './LockedAccountModalProvider'; import {ModalActions} from './Modal/Global/ModalContext'; -import MoneyReportHeaderEducationalModals from './MoneyReportHeaderEducationalModals'; -import type {RejectModalAction} from './MoneyReportHeaderEducationalModals'; import MoneyReportHeaderKYCDropdown from './MoneyReportHeaderKYCDropdown'; +import MoneyReportHeaderModals from './MoneyReportHeaderModals'; +import {useMoneyReportHeaderModals} from './MoneyReportHeaderModalsContext'; import MoneyReportHeaderPrimaryAction from './MoneyReportHeaderPrimaryAction'; import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar'; import MoneyReportHeaderStatusBarSection from './MoneyReportHeaderStatusBarSection'; @@ -169,9 +166,6 @@ import MoneyReportHeaderStatusBarSkeleton from './MoneyReportHeaderStatusBarSkel import MoneyRequestReportNavigation from './MoneyRequestReportView/MoneyRequestReportNavigation'; import {usePersonalDetails} from './OnyxListItemProvider'; import type {PopoverMenuItem} from './PopoverMenu'; -import type {ActionHandledType} from './ProcessMoneyReportHoldMenu'; -import ProcessMoneyReportHoldMenu from './ProcessMoneyReportHoldMenu'; -import ReportPDFDownloadModal from './ReportPDFDownloadModal'; import {useSearchActionsContext, useSearchStateContext} from './Search/SearchContext'; import type {PaymentActionParams} from './SettlementButton/types'; import Text from './Text'; @@ -350,7 +344,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa }, [isExported, reportActions]); const transactionViolations = useTransactionViolations(transaction?.transactionID); - const [isPDFModalVisible, setIsPDFModalVisible] = useState(false); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector}); const shouldUseMarkAsDoneCopy = isTrackIntentUser && isSubmitAndClose(policy); @@ -422,10 +415,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa dropdownMenuRef.current?.setIsMenuVisible(false); }, [isDuplicateReportActive]); - const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false); - const [paymentType, setPaymentType] = useState(); - const [requestType, setRequestType] = useState(); - const [selectedVBBAToPayFromHoldMenu, setSelectedVBBAToPayFromHoldMenu] = useState(undefined); const canAllowSettlement = hasUpdatedTotal(moneyRequestReport, policy); const policyType = policy?.type; const connectedIntegration = getValidConnectedIntegration(policy); @@ -446,7 +435,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa [transactions, allTransactionViolations, email, accountID, moneyRequestReport, policy], ); - const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID); const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID); const isChatReportArchived = useReportIsArchived(chatReport?.reportID); @@ -502,9 +490,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa const [isDuplicateActive, temporarilyDisableDuplicateAction] = useThrottledButtonState(handleDuplicateReset); - const [isHoldEducationalModalVisible, setIsHoldEducationalModalVisible] = useState(false); - const [rejectModalAction, setRejectModalAction] = useState(null); - const {selectedTransactionIDs, currentSearchQueryJSON, currentSearchKey, currentSearchHash, currentSearchResults} = useSearchStateContext(); const {removeTransaction, clearSelectedTransactions} = useSearchActionsContext(); const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, currentSearchQueryJSON?.hash, true); @@ -514,6 +499,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa const shouldDisplayNarrowMoreButton = !shouldDisplayNarrowVersion || isWideRHPDisplayedOnWideLayout || isSuperWideRHPDisplayedOnWideLayout; const {showNonReimbursablePaymentErrorModal, shouldBlockDirectPayment} = useNonReimbursablePaymentModal(moneyRequestReport, transactions); + const {openHoldMenu, openPDFDownload, openHoldEducational, openRejectModal} = useMoneyReportHeaderModals(); const showExportProgressModal = useCallback(() => { return showConfirmModal({ @@ -631,7 +617,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa } const shouldShowNextStep = isFromPaidPolicy && !isInvoiceReport && !shouldShowStatusBar; - const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton); const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID); const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); @@ -657,20 +642,22 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa showNonReimbursablePaymentErrorModal(); return; } - setPaymentType(type); - setRequestType(CONST.IOU.REPORT_ACTION_TYPE.PAY); const isFromSelectionMode = isSelectionModePaymentRef.current; if (isDelegateAccessRestricted) { showDelegateNoAccessModal(); } else if (isAnyTransactionOnHold) { - setSelectedVBBAToPayFromHoldMenu(type === CONST.IOU.PAYMENT_TYPE.VBBA ? methodID : undefined); - if (getPlatform() === CONST.PLATFORM.IOS) { - // InteractionManager delays modal until current interaction completes, preventing visual glitches on iOS - // eslint-disable-next-line @typescript-eslint/no-deprecated - InteractionManager.runAfterInteractions(() => setIsHoldMenuVisible(true)); - } else { - setIsHoldMenuVisible(true); - } + openHoldMenu({ + requestType: CONST.IOU.REPORT_ACTION_TYPE.PAY, + paymentType: type, + methodID, + onConfirm: () => { + if (isFromSelectionMode) { + clearSelectedTransactions(true); + return; + } + startAnimation(); + }, + }); } else if (isInvoiceReport) { if (!isFromSelectionMode) { startAnimation(); @@ -775,11 +762,19 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa const confirmApproval = useCallback( (skipAnimation = false) => { - setRequestType(CONST.IOU.REPORT_ACTION_TYPE.APPROVE); if (isDelegateAccessRestricted) { showDelegateNoAccessModal(); } else if (isAnyTransactionOnHold) { - setIsHoldMenuVisible(true); + openHoldMenu({ + requestType: CONST.IOU.REPORT_ACTION_TYPE.APPROVE, + onConfirm: () => { + if (skipAnimation) { + clearSelectedTransactions(true); + return; + } + startApprovedAnimation(); + }, + }); } else { if (!skipAnimation) { startApprovedAnimation(); @@ -814,6 +809,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa isDelegateAccessRestricted, showDelegateNoAccessModal, isAnyTransactionOnHold, + openHoldMenu, startApprovedAnimation, moneyRequestReport, accountID, @@ -1200,18 +1196,6 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa startAnimation={startAnimation} startApprovedAnimation={startApprovedAnimation} startSubmittingAnimation={startSubmittingAnimation} - onHoldMenuOpen={(type, payType, methodID) => { - setRequestType(type as ActionHandledType); - setPaymentType(payType); - setSelectedVBBAToPayFromHoldMenu(payType === CONST.IOU.PAYMENT_TYPE.VBBA ? methodID : undefined); - if (getPlatform() === CONST.PLATFORM.IOS) { - // InteractionManager delays modal until current interaction completes, preventing visual glitches on iOS - // eslint-disable-next-line @typescript-eslint/no-deprecated - InteractionManager.runAfterInteractions(() => setIsHoldMenuVisible(true)); - } else { - setIsHoldMenuVisible(true); - } - }} onExportModalOpen={() => triggerExportOrConfirm(CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION)} /> ); @@ -1406,7 +1390,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa if (!moneyRequestReport?.reportID) { return; } - setIsPDFModalVisible(true); + openPDFDownload(); exportReportToPDF({reportID: moneyRequestReport.reportID}); }, }, @@ -1525,9 +1509,9 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa if (isDismissed || isChatReportDM) { changeMoneyRequestHoldStatus(requestParentReportAction, transaction, isOffline); } else if (isReportSubmitter) { - setIsHoldEducationalModalVisible(true); + openHoldEducational(); } else { - setRejectModalAction(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD); + openRejectModal(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD); } }, }, @@ -1973,7 +1957,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa if (dismissedRejectUseExplanation) { option.onSelected?.(); } else { - setRejectModalAction(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT_BULK); + openRejectModal(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT_BULK); } }, }; @@ -2130,130 +2114,87 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa }; return ( - - - {shouldDisplayNarrowMoreButton && ( - - {!shouldShowSelectedTransactionsButton && primaryActionComponent} - {!!applicableSecondaryActions.length && !shouldShowSelectedTransactionsButton && ( - confirmPayment({paymentType: type})} - primaryAction={primaryAction} - applicableSecondaryActions={applicableSecondaryActions} - dropdownMenuRef={dropdownMenuRef} - onOptionsMenuHide={handleOptionsMenuHide} - ref={kycWallRef} + + + + {shouldDisplayNarrowMoreButton && ( + + {!shouldShowSelectedTransactionsButton && primaryActionComponent} + {!!applicableSecondaryActions.length && !shouldShowSelectedTransactionsButton && ( + confirmPayment({paymentType: type})} + primaryAction={primaryAction} + applicableSecondaryActions={applicableSecondaryActions} + dropdownMenuRef={dropdownMenuRef} + onOptionsMenuHide={handleOptionsMenuHide} + ref={kycWallRef} + /> + )} + {shouldShowSelectedTransactionsButton && {renderSelectionModeDropdown()}} + + )} + + {!shouldDisplayNarrowMoreButton && + (shouldShowSelectedTransactionsButton ? ( + {renderSelectionModeDropdown(styles.w100)} + ) : ( + + {!!primaryAction && {primaryActionComponent}} + {!!applicableSecondaryActions.length && ( + confirmPayment({paymentType: type})} + primaryAction={primaryAction} + applicableSecondaryActions={applicableSecondaryActions} + dropdownMenuRef={dropdownMenuRef} + onOptionsMenuHide={handleOptionsMenuHide} + ref={kycWallRef} + /> + )} + + ))} + + {shouldShowMoreContent && ( + + + {showNextStepBar && } + {showNextStepSkeleton && } + - )} - {shouldShowSelectedTransactionsButton && {renderSelectionModeDropdown()}} - - )} - - {!shouldDisplayNarrowMoreButton && - (shouldShowSelectedTransactionsButton ? ( - {renderSelectionModeDropdown(styles.w100)} - ) : ( - - {!!primaryAction && {primaryActionComponent}} - {!!applicableSecondaryActions.length && ( - confirmPayment({paymentType: type})} - primaryAction={primaryAction} - applicableSecondaryActions={applicableSecondaryActions} - dropdownMenuRef={dropdownMenuRef} - onOptionsMenuHide={handleOptionsMenuHide} - ref={kycWallRef} + + {isReportInSearch && ( + )} - ))} - - {shouldShowMoreContent && ( - - - {showNextStepBar && } - {showNextStepSkeleton && } - - - {isReportInSearch && ( - - )} - - )} - - - {isHoldMenuVisible && requestType !== undefined && ( - { - setSelectedVBBAToPayFromHoldMenu(undefined); - setIsHoldMenuVisible(false); - isSelectionModePaymentRef.current = false; - }} - isVisible={isHoldMenuVisible} - paymentType={paymentType} - methodID={paymentType === CONST.IOU.PAYMENT_TYPE.VBBA ? selectedVBBAToPayFromHoldMenu : undefined} - chatReport={chatReport} - moneyRequestReport={moneyRequestReport} - hasNonHeldExpenses={!hasOnlyHeldExpenses} - onConfirm={() => { - if (isSelectionModePaymentRef.current) { - clearSelectedTransactions(true); - return; - } - if (requestType === CONST.IOU.REPORT_ACTION_TYPE.APPROVE) { - startApprovedAnimation(); - } else { - startAnimation(); - } - }} - transactionCount={transactionIDs?.length ?? 0} - transactions={transactions} - /> - )} - setIsHoldEducationalModalVisible(false)} - onRejectModalDismissed={() => setRejectModalAction(null)} - /> - setIsPDFModalVisible(false)} - /> - + )} + + + + ); } From add9996744bd057f222506ec15fd287a2ec25de7 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 3 Apr 2026 09:32:42 +0200 Subject: [PATCH 06/19] Update MoneyReportHeaderPrimaryAction to consume modals context directly --- .../ApprovePrimaryAction.tsx | 6 ++--- .../PayPrimaryAction.tsx | 25 ++++++++----------- .../MoneyReportHeaderPrimaryAction/index.tsx | 3 --- .../MoneyReportHeaderPrimaryAction/types.ts | 2 -- .../useConfirmApproval.ts | 10 +++++--- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/components/MoneyReportHeaderPrimaryAction/ApprovePrimaryAction.tsx b/src/components/MoneyReportHeaderPrimaryAction/ApprovePrimaryAction.tsx index fb0c7cf43352..4767c8c35a1d 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/ApprovePrimaryAction.tsx +++ b/src/components/MoneyReportHeaderPrimaryAction/ApprovePrimaryAction.tsx @@ -7,16 +7,14 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; import {isSubmitAndClose} from '@libs/PolicyUtils'; import {getNextApproverAccountID, isReportOwner} from '@libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import useConfirmApproval from './useConfirmApproval'; type ApprovePrimaryActionProps = { reportID: string | undefined; startApprovedAnimation: () => void; - onHoldMenuOpen: (requestType: string, paymentType?: PaymentMethodType) => void; }; -function ApprovePrimaryAction({reportID, startApprovedAnimation, onHoldMenuOpen}: ApprovePrimaryActionProps) { +function ApprovePrimaryAction({reportID, startApprovedAnimation}: ApprovePrimaryActionProps) { const {translate} = useLocalize(); const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); @@ -29,7 +27,7 @@ function ApprovePrimaryAction({reportID, startApprovedAnimation, onHoldMenuOpen} isReportOwner(moneyRequestReport) && (nextApproverAccountID === moneyRequestReport?.ownerAccountID || moneyRequestReport?.managerID === moneyRequestReport?.ownerAccountID); const isBlockSubmitDueToPreventSelfApproval = isSubmitterSameAsNextApprover && policy?.preventSelfApproval; - const confirmApproval = useConfirmApproval(reportID, startApprovedAnimation, onHoldMenuOpen); + const confirmApproval = useConfirmApproval(reportID, startApprovedAnimation); return (