Skip to content

Commit 35c25be

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #75803 from Expensify/scott-revertPutOnHoldRefactor
[CP Staging] Revert "Merge pull request #74628 from Tony-MK/putOnHold" (cherry picked from commit a60213e) (cherry-picked to staging by mountiny)
1 parent c8d8a3f commit 35c25be

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/libs/actions/IOU.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ import {
115115
isMoneyRequestAction,
116116
isReportPreviewAction,
117117
} from '@libs/ReportActionsUtils';
118-
import type {Ancestor, OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptionData, TransactionDetails} from '@libs/ReportUtils';
118+
import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptionData, TransactionDetails} from '@libs/ReportUtils';
119119
import {
120120
buildOptimisticActionableTrackExpenseWhisper,
121121
buildOptimisticAddCommentReportAction,
@@ -158,7 +158,7 @@ import {
158158
getDisplayedReportID,
159159
getMoneyRequestSpendBreakdown,
160160
getNextApproverAccountID,
161-
getOptimisticDataForAncestors,
161+
getOptimisticDataForParentReportAction,
162162
getOutstandingChildRequest,
163163
getParsedComment,
164164
getPersonalDetailsForAccountID,
@@ -11967,7 +11967,7 @@ function adjustRemainingSplitShares(transaction: NonNullable<OnyxTypes.Transacti
1196711967
/**
1196811968
* Put expense on HOLD
1196911969
*/
11970-
function putOnHold(transactionID: string, comment: string, initialReportID: string | undefined, ancestors: Ancestor[] = []) {
11970+
function putOnHold(transactionID: string, comment: string, initialReportID: string | undefined) {
1197111971
const currentTime = DateUtils.getDBTime();
1197211972
const reportID = initialReportID ?? generateReportID();
1197311973
const createdReportAction = buildOptimisticHoldReportAction(currentTime);
@@ -11990,6 +11990,7 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri
1199011990
}
1199111991

1199211992
const optimisticCreatedAction = buildOptimisticCreatedReportAction(currentUserEmail);
11993+
const parentReportActionOptimistic = getOptimisticDataForParentReportAction(transactionThreadReport, createdReportActionComment.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
1199311994

1199411995
const optimisticData: OnyxUpdate[] = [
1199511996
{
@@ -12024,8 +12025,6 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri
1202412025
},
1202512026
];
1202612027

12027-
optimisticData.push(...getOptimisticDataForAncestors(ancestors, createdReportActionComment.created, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD));
12028-
1202912028
if (iouReport && iouReport.currency === transaction?.currency) {
1203012029
const isExpenseReportLocal = isExpenseReport(iouReport);
1203112030
const coefficient = isExpenseReportLocal ? -1 : 1;
@@ -12040,6 +12039,13 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri
1204012039
});
1204112040
}
1204212041

12042+
for (const parentActionData of parentReportActionOptimistic) {
12043+
if (!parentActionData) {
12044+
continue;
12045+
}
12046+
optimisticData.push(parentActionData);
12047+
}
12048+
1204312049
const successData: OnyxUpdate[] = [
1204412050
{
1204512051
onyxMethod: Onyx.METHOD.MERGE,
@@ -12171,10 +12177,10 @@ function putOnHold(transactionID: string, comment: string, initialReportID: stri
1217112177
Navigation.setNavigationActionToMicrotaskQueue(() => notifyNewAction(currentReportID, userAccountID));
1217212178
}
1217312179

12174-
function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string, ancestors: Ancestor[] = []) {
12180+
function putTransactionsOnHold(transactionsID: string[], comment: string, reportID: string) {
1217512181
for (const transactionID of transactionsID) {
1217612182
const {childReportID} = getIOUActionForReportID(reportID, transactionID) ?? {};
12177-
putOnHold(transactionID, comment, childReportID, ancestors);
12183+
putOnHold(transactionID, comment, childReportID);
1217812184
}
1217912185
}
1218012186

src/pages/Search/SearchHoldReasonPage.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {useCallback, useEffect} from 'react';
22
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
33
import {useSearchContext} from '@components/Search/SearchContext';
4-
import useAncestors from '@hooks/useAncestors';
54
import useLocalize from '@hooks/useLocalize';
65
import useOnyx from '@hooks/useOnyx';
76
import {clearErrorFields, clearErrors} from '@libs/actions/FormActions';
@@ -25,24 +24,21 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) {
2524
const {backTo = '', reportID} = route.params ?? {};
2625
const context = useSearchContext();
2726
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
28-
const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true});
29-
30-
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
31-
const ancestors = useAncestors(report);
3227

28+
const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true});
3329
const onSubmit = useCallback(
3430
({comment}: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
3531
if (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS) {
36-
putTransactionsOnHold(context.selectedTransactionIDs, comment, reportID, ancestors);
32+
putTransactionsOnHold(context.selectedTransactionIDs, comment, reportID);
3733
context.clearSelectedTransactions(true);
3834
} else {
39-
holdMoneyRequestOnSearch(context.currentSearchHash, context.selectedTransactionIDs, comment, allTransactions, allReportActions);
35+
holdMoneyRequestOnSearch(context.currentSearchHash, Object.keys(context.selectedTransactions), comment, allTransactions, allReportActions);
4036
context.clearSelectedTransactions();
4137
}
4238

4339
Navigation.goBack();
4440
},
45-
[route.name, context.clearSelectedTransactions, context.currentSearchHash, context.selectedTransactionIDs, reportID, allTransactions, ancestors, allReportActions],
41+
[route.name, context, reportID, allTransactions, allReportActions],
4642
);
4743

4844
const validate = useCallback(

src/pages/iou/HoldReasonPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {useCallback, useEffect} from 'react';
22
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
33
import {useSearchContext} from '@components/Search/SearchContext';
4-
import useAncestors from '@hooks/useAncestors';
54
import useLocalize from '@hooks/useLocalize';
65
import useOnyx from '@hooks/useOnyx';
76
import {addErrorMessage} from '@libs/ErrorUtils';
@@ -28,7 +27,6 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
2827
const {transactionID, reportID, backTo} = route.params;
2928

3029
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
31-
const ancestors = useAncestors(report);
3230
const {selectedTransactionIDs} = useSearchContext();
3331

3432
// We first check if the report is part of a policy - if not, then it's a personal request (1:1 request)
@@ -44,7 +42,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
4442
return;
4543
}
4644

47-
putOnHold(transactionID, values.comment, reportID, ancestors);
45+
putOnHold(transactionID, values.comment, reportID);
4846
Navigation.goBack(backTo);
4947
};
5048

0 commit comments

Comments
 (0)