Skip to content

Commit 92c14d4

Browse files
DylanDylannclaude
andcommitted
refactor: thread reportActionsList through createWorkspaceFromIOUPayment
Add reportActionsList parameter to createWorkspaceFromIOUPayment and pass it through to createPolicyExpenseChats, replacing the deprecated Onyx.connect() fallback. Update BaseKYCWall.tsx to pass filteredReportActions from the useAllPolicyExpenseChatReportActions hook. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b96c699 commit 92c14d4

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

src/components/KYCWall/BaseKYCWall.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function KYCWall({
180180
conciergeReportID,
181181
lastWorkspaceNumber,
182182
translate,
183+
filteredReportActions,
183184
) ?? {};
184185
if (policyID && iouReport?.policyID) {
185186
savePreferredPaymentMethod(iouReport.policyID, policyID, CONST.LAST_PAYMENT_METHOD.IOU, lastPaymentMethod?.[iouReport?.policyID]);

src/libs/actions/Policy/Policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,7 @@ function createWorkspaceFromIOUPayment(
39383938
conciergeReportID: string | undefined,
39393939
lastWorkspaceNumber: number | undefined,
39403940
localeTranslate: LocalizedTranslate,
3941+
reportActionsList?: OnyxCollection<ReportActions>,
39413942
): WorkspaceFromIOUCreationData | undefined {
39423943
// This flow only works for IOU reports
39433944
if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) {
@@ -3969,8 +3970,7 @@ function createWorkspaceFromIOUPayment(
39693970
}
39703971

39713972
// Create the expense chat for the employee whose IOU is being paid
3972-
// TODO: Update to include reportActionsList later (https://github.com/Expensify/App/issues/66578)
3973-
const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[iouReportOwnerEmail]: employeeAccountID}, undefined, true);
3973+
const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[iouReportOwnerEmail]: employeeAccountID}, reportActionsList, true);
39743974
const newWorkspace = {
39753975
id: policyID,
39763976

tests/actions/PolicyTest.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5718,7 +5718,7 @@ describe('actions/Policy', () => {
57185718

57195719
// eslint-disable-next-line @typescript-eslint/naming-convention
57205720
const mockTranslate = ((key: string) => key) as unknown as Parameters<typeof Policy.createWorkspaceFromIOUPayment>[7];
5721-
Policy.createWorkspaceFromIOUPayment(iouReport, undefined, customAccountID, customEmail, iouReportOwnerEmail, undefined, undefined, mockTranslate);
5721+
Policy.createWorkspaceFromIOUPayment(iouReport, undefined, customAccountID, customEmail, iouReportOwnerEmail, undefined, undefined, mockTranslate, {});
57225722
await waitForBatchedUpdates();
57235723

57245724
const writeOptions = apiWriteSpy.mock.calls.at(0)?.at(2) as {
@@ -5750,8 +5750,63 @@ describe('actions/Policy', () => {
57505750

57515751
// eslint-disable-next-line @typescript-eslint/naming-convention
57525752
const mockTranslate = ((key: string) => key) as unknown as Parameters<typeof Policy.createWorkspaceFromIOUPayment>[7];
5753-
const result = Policy.createWorkspaceFromIOUPayment(nonIOUReport, undefined, ESH_ACCOUNT_ID, ESH_EMAIL, 'owner@example.com', undefined, undefined, mockTranslate);
5753+
const result = Policy.createWorkspaceFromIOUPayment(nonIOUReport, undefined, ESH_ACCOUNT_ID, ESH_EMAIL, 'owner@example.com', undefined, undefined, mockTranslate, {});
57545754
expect(result).toBeUndefined();
57555755
});
5756+
5757+
it('should use reportActionsList parameter instead of deprecated Onyx connection', async () => {
5758+
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
5759+
await waitForBatchedUpdates();
5760+
5761+
const employeeAccountID = 300;
5762+
const iouReportOwnerEmail = 'employee@example.com';
5763+
5764+
const existingChatReportID = '700';
5765+
5766+
// Create a report preview action for the existing chat
5767+
const reportPreviewAction: ReportAction = {
5768+
reportActionID: 'previewAction1',
5769+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
5770+
childReportID: 'childReport1',
5771+
created: '2024-01-01',
5772+
message: [],
5773+
};
5774+
5775+
// Pass reportActionsList explicitly - this should be used instead of the deprecated Onyx connection
5776+
const reportActionsList = {
5777+
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${existingChatReportID}`]: {
5778+
[reportPreviewAction.reportActionID]: reportPreviewAction,
5779+
},
5780+
};
5781+
5782+
const iouReport: Report = {
5783+
...createRandomReport(1, undefined),
5784+
reportID: '800',
5785+
type: CONST.REPORT.TYPE.IOU,
5786+
ownerAccountID: employeeAccountID,
5787+
chatReportID: '801',
5788+
policyID: 'oldPolicyID',
5789+
currency: CONST.CURRENCY.USD,
5790+
total: 2000,
5791+
};
5792+
5793+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, iouReport);
5794+
await waitForBatchedUpdates();
5795+
5796+
const isIOUReportUsingReportSpy = jest.spyOn(ReportUtils, 'isIOUReportUsingReport').mockReturnValue(true);
5797+
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());
5798+
5799+
// eslint-disable-next-line @typescript-eslint/naming-convention
5800+
const mockTranslate = ((key: string) => key) as unknown as Parameters<typeof Policy.createWorkspaceFromIOUPayment>[7];
5801+
const result = Policy.createWorkspaceFromIOUPayment(iouReport, undefined, ESH_ACCOUNT_ID, ESH_EMAIL, iouReportOwnerEmail, undefined, undefined, mockTranslate, reportActionsList);
5802+
5803+
// Verify the function returns a valid result (not undefined)
5804+
expect(result).toBeDefined();
5805+
expect(result?.policyID).toBeDefined();
5806+
expect(result?.workspaceChatReportID).toBeDefined();
5807+
5808+
apiWriteSpy.mockRestore();
5809+
isIOUReportUsingReportSpy.mockRestore();
5810+
});
57565811
});
57575812
});

0 commit comments

Comments
 (0)