From c4b686c7804dd224ee965d35f0894c38560ac8a0 Mon Sep 17 00:00:00 2001 From: samarroy84 Date: Mon, 12 Jan 2026 20:10:33 +0600 Subject: [PATCH] Refactor putOnhold to use the useAncestors hook --- src/libs/actions/IOU/index.ts | 18 ++++++------------ src/pages/Search/SearchHoldReasonPage.tsx | 7 +++++-- src/pages/iou/HoldReasonPage.tsx | 4 +++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index ef80a4dc98951..ec3694644b115 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -112,7 +112,7 @@ import { isMoneyRequestAction, isReportPreviewAction, } from '@libs/ReportActionsUtils'; -import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils'; +import type {Ancestor, OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils'; import { buildOptimisticActionableTrackExpenseWhisper, buildOptimisticAddCommentReportAction, @@ -154,7 +154,7 @@ import { getDisplayedReportID, getMoneyRequestSpendBreakdown, getNextApproverAccountID, - getOptimisticDataForParentReportAction, + getOptimisticDataForAncestors, getOutstandingChildRequest, getParsedComment, getPersonalDetailsForAccountID, @@ -11813,7 +11813,7 @@ function adjustRemainingSplitShares(transaction: NonNullable @@ -12094,10 +12088,10 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri Navigation.setNavigationActionToMicrotaskQueue(() => notifyNewAction(currentReportID, userAccountID)); } -function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string) { +function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string, ancestors: Ancestor[] = []) { for (const transactionID of transactionsID) { const {childReportID} = getIOUActionForReportID(reportID, transactionID) ?? {}; - putOnHold(transactionID, comment, childReportID); + putOnHold(transactionID, comment, childReportID, ancestors); } } diff --git a/src/pages/Search/SearchHoldReasonPage.tsx b/src/pages/Search/SearchHoldReasonPage.tsx index af50375a33152..3c426d80871e4 100644 --- a/src/pages/Search/SearchHoldReasonPage.tsx +++ b/src/pages/Search/SearchHoldReasonPage.tsx @@ -1,6 +1,7 @@ import React, {useCallback, useEffect} from 'react'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import {useSearchContext} from '@components/Search/SearchContext'; +import useAncestors from '@hooks/useAncestors'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import {clearErrorFields, clearErrors} from '@libs/actions/FormActions'; @@ -24,12 +25,14 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) { const {backTo = '', reportID} = route.params ?? {}; const context = useSearchContext(); const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true}); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); + const ancestors = useAncestors(report); const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true}); const onSubmit = useCallback( ({comment}: FormOnyxValues) => { if (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS) { - putTransactionsOnHold(context.selectedTransactionIDs, comment, reportID); + putTransactionsOnHold(context.selectedTransactionIDs, comment, reportID, ancestors); context.clearSelectedTransactions(true); } else { holdMoneyRequestOnSearch(context.currentSearchHash, Object.keys(context.selectedTransactions), comment, allTransactions, allReportActions); @@ -38,7 +41,7 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) { Navigation.goBack(); }, - [route.name, context, reportID, allTransactions, allReportActions], + [route.name, context, reportID, allTransactions, allReportActions, ancestors], ); const validate = useCallback( diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index d10844230222c..f26c976a554e9 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -1,5 +1,6 @@ import React, {useCallback, useEffect} from 'react'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; +import useAncestors from '@hooks/useAncestors'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import {addErrorMessage} from '@libs/ErrorUtils'; @@ -26,6 +27,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { const {transactionID, reportID, backTo} = route.params; const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); + const ancestors = useAncestors(report); // We first check if the report is part of a policy - if not, then it's a personal request (1:1 request) // For personal requests, we need to allow both users to put the request on hold @@ -40,7 +42,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { return; } - putOnHold(transactionID, values.comment, reportID); + putOnHold(transactionID, values.comment, reportID, ancestors); Navigation.goBack(backTo); };