diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 65e763540f27c..a84a434bb66ef 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1696,6 +1696,10 @@ function getToFieldValueForTransaction( return emptyPersonalDetails; } +function getTransactionPendingAction(transactionItem: OnyxTypes.Transaction): OnyxTypes.Transaction['pendingAction'] { + return transactionItem.pendingAction ?? (transactionItem.pendingFields ? Object.values(transactionItem.pendingFields).find(Boolean) : undefined); +} + /** * @private * Organizes data into List Sections for display, for the TransactionListItemType of Search Results. @@ -1782,8 +1786,10 @@ function getTransactionsSections({ const actions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionItem.reportID}`] ?? []; const reportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`] ?? {}; const allActions = getActions(data, allViolations, key, currentSearch, currentUserEmail, currentAccountID, bankAccountList, reportMetadata, actions); + const transactionPendingAction = getTransactionPendingAction(transactionItem); const transactionSection: TransactionListItemType = { ...transactionItem, + ...(transactionPendingAction ? {pendingAction: transactionPendingAction} : {}), keyForList: transactionItem.transactionID, action: allActions.at(0) ?? CONST.SEARCH.ACTION_TYPES.VIEW, allActions, @@ -2469,8 +2475,10 @@ function getReportSections({ const transactionReportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`] ?? {}; const allActions = getActions(data, allViolations, key, currentSearch, currentUserEmail, currentAccountID, bankAccountList, transactionReportMetadata, actions); + const transactionPendingAction = getTransactionPendingAction(transactionItem); const transaction = { ...transactionItem, + ...(transactionPendingAction ? {pendingAction: transactionPendingAction} : {}), action: allActions.at(0) ?? CONST.SEARCH.ACTION_TYPES.VIEW, allActions, report, diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index b244c1acf5afb..464e66021d80c 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -13503,6 +13503,7 @@ function updateMultipleMoneyRequests({ > > = []; const snapshotOptimisticData: Array> = []; + const snapshotSuccessData: Array> = []; const snapshotFailureData: Array> = []; // Pending fields for the transaction @@ -13579,18 +13580,34 @@ function updateMultipleMoneyRequests({ value: { // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 data: { - [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: updatedTransaction, + [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: { + ...updatedTransaction, + pendingFields, + }, ...(optimisticViolationsData && {[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]: optimisticViolationsData.value}), }, }, }); + snapshotSuccessData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}` as const, + value: { + data: { + // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 + [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: {pendingFields: clearedPendingFields}, + }, + }, + }); snapshotFailureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}` as const, value: { // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 data: { - [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: transaction, + [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: { + ...transaction, + pendingFields: clearedPendingFields, + }, ...(currentTransactionViolations && {[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]: currentTransactionViolations}), }, }, @@ -13756,7 +13773,15 @@ function updateMultipleMoneyRequests({ | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS > >, - successData, + successData: [...successData, ...snapshotSuccessData] as Array< + OnyxUpdate< + | typeof ONYXKEYS.COLLECTION.TRANSACTION + | typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + | typeof ONYXKEYS.COLLECTION.SNAPSHOT + | typeof ONYXKEYS.COLLECTION.REPORT + | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS + > + >, failureData: [...failureData, ...snapshotFailureData] as Array< OnyxUpdate< | typeof ONYXKEYS.COLLECTION.TRANSACTION