Skip to content

Commit d5c95c1

Browse files
committed
Refactor send money flow function and improve help content logic
1 parent b74be6d commit d5c95c1

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/components/SidePanel/HelpComponents/HelpContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ function HelpContent({closeSidePanel}: HelpContentProps) {
5050
selector: (actions) =>
5151
Object.values(actions ?? {})
5252
.filter((action) => action.reportActionID === report?.parentReportActionID)
53+
.filter(isMoneyRequestAction)
5354
.at(0),
5455
});
5556

5657
const transactionID = useMemo(() => {
5758
const transactionThreadReportAction = getOneTransactionThreadReportAction(report, chatReport, reportActions ?? []);
58-
return getOriginalMessage(isMoneyRequestAction(parentIOUReportAction) ? parentIOUReportAction : transactionThreadReportAction)?.IOUTransactionID;
59+
return getOriginalMessage(parentIOUReportAction ?? transactionThreadReportAction)?.IOUTransactionID;
5960
}, [report, chatReport, reportActions, parentIOUReportAction]);
6061
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {canBeMissing: true});
6162

src/libs/ReportActionsUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ function isTagModificationAction(actionName: string): boolean {
11981198
* Used for Send Money flow, which is a special case where we have no IOU create action and only one IOU pay action.
11991199
* In other reports, pay actions do not count as a transactions, but this is an exception to this rule.
12001200
*/
1201-
function getSendMoneyFlowOneTransactionReportAction(actions: OnyxEntry<ReportActions> | ReportAction[], chatReport: OnyxEntry<Report>): ReportAction<'IOU'> | undefined {
1201+
function getSendMoneyFlowAction(actions: OnyxEntry<ReportActions> | ReportAction[], chatReport: OnyxEntry<Report>): ReportAction<'IOU'> | undefined {
12021202
if (!chatReport) {
12031203
return undefined;
12041204
}
@@ -1273,7 +1273,7 @@ function getOneTransactionThreadReportAction(
12731273
return;
12741274
}
12751275

1276-
const sendMoneyFlow = getSendMoneyFlowOneTransactionReportAction(reportActions, chatReport);
1276+
const sendMoneyFlow = getSendMoneyFlowAction(reportActions, chatReport);
12771277

12781278
if (sendMoneyFlow?.childReportID) {
12791279
return sendMoneyFlow;
@@ -3099,7 +3099,7 @@ export {
30993099
getWorkspaceDescriptionUpdatedMessage,
31003100
getWorkspaceReportFieldAddMessage,
31013101
getWorkspaceCustomUnitRateAddedMessage,
3102-
getSendMoneyFlowOneTransactionReportAction,
3102+
getSendMoneyFlowAction,
31033103
getWorkspaceTagUpdateMessage,
31043104
getWorkspaceReportFieldUpdateMessage,
31053105
getWorkspaceReportFieldDeleteMessage,

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {actionR14932 as mockIOUAction, originalMessageR14932 as mockOriginalMess
66
import {chatReportR14932 as mockChatReport, iouReportR14932 as mockIOUReport} from '../../__mocks__/reportData/reports';
77
import CONST from '../../src/CONST';
88
import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils';
9-
import {getOneTransactionThreadReportID, getOriginalMessage, getSendMoneyFlowOneTransactionReportAction, isIOUActionMatchingTransactionList} from '../../src/libs/ReportActionsUtils';
9+
import {getOneTransactionThreadReportID, getOriginalMessage, getSendMoneyFlowAction, isIOUActionMatchingTransactionList} from '../../src/libs/ReportActionsUtils';
1010
import ONYXKEYS from '../../src/ONYXKEYS';
1111
import type {Report, ReportAction} from '../../src/types/onyx';
1212
import {createRandomReport} from '../utils/collections/reports';
@@ -856,7 +856,7 @@ describe('ReportActionsUtils', () => {
856856
});
857857
});
858858

859-
describe('getSendMoneyFlowOneTransactionReportAction', () => {
859+
describe('getSendMoneyFlowAction', () => {
860860
const mockChatReportID = `${ONYXKEYS.COLLECTION.REPORT}REPORT` as const;
861861
const mockDMChatReportID = `${ONYXKEYS.COLLECTION.REPORT}REPORT_DM` as const;
862862
const childReportID = `${ONYXKEYS.COLLECTION.REPORT}childReport123` as const;
@@ -891,27 +891,27 @@ describe('ReportActionsUtils', () => {
891891
};
892892

893893
it('should return undefined for a single non-IOU action', () => {
894-
expect(getSendMoneyFlowOneTransactionReportAction([nonIOUAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
894+
expect(getSendMoneyFlowAction([nonIOUAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
895895
});
896896

897897
it('should return undefined for multiple IOU actions regardless of type', () => {
898-
expect(getSendMoneyFlowOneTransactionReportAction([payAction, payAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
898+
expect(getSendMoneyFlowAction([payAction, payAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
899899
});
900900

901901
it('should return undefined for a single IOU action that is not `Pay`', () => {
902-
expect(getSendMoneyFlowOneTransactionReportAction([createAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
902+
expect(getSendMoneyFlowAction([createAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
903903
});
904904

905905
it('should return the appropriate childReportID for a valid single `Pay` IOU action in DM chat', () => {
906-
expect(getSendMoneyFlowOneTransactionReportAction([payAction], mockedReports[mockDMChatReportID])?.childReportID).toEqual(childReportID);
906+
expect(getSendMoneyFlowAction([payAction], mockedReports[mockDMChatReportID])?.childReportID).toEqual(childReportID);
907907
});
908908

909909
it('should return undefined for a valid single `Pay` IOU action in a chat that is not DM', () => {
910-
expect(getSendMoneyFlowOneTransactionReportAction([payAction], mockedReports[mockChatReportID])?.childReportID).toBeUndefined();
910+
expect(getSendMoneyFlowAction([payAction], mockedReports[mockChatReportID])?.childReportID).toBeUndefined();
911911
});
912912

913913
it('should return undefined for a valid `Pay` IOU action in DM chat that has also a create IOU action', () => {
914-
expect(getSendMoneyFlowOneTransactionReportAction([payAction, createAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
914+
expect(getSendMoneyFlowAction([payAction, createAction], mockedReports[mockDMChatReportID])?.childReportID).toBeUndefined();
915915
});
916916
});
917917

0 commit comments

Comments
 (0)