Skip to content

Commit cfeaadd

Browse files
authored
Merge pull request Expensify#89517 from dukenv0307/fix/66424-part-16
[No QA] refactor createTransactionThreadReport to use 1 param
2 parents 0c42f05 + af6a4b2 commit cfeaadd

13 files changed

Lines changed: 228 additions & 57 deletions

File tree

src/components/MoneyReportHeaderPrimaryAction/ReviewDuplicatesPrimaryAction.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ function ReviewDuplicatesPrimaryAction({reportID, chatReportID}: SimpleActionPro
5252
} else {
5353
const transactionID = duplicateTransaction.transactionID;
5454
const iouAction = getIOUActionForReportID(moneyRequestReport?.reportID, transactionID);
55-
const createdTransactionThreadReport = createTransactionThreadReport(introSelected, email ?? '', accountID, betas, moneyRequestReport, iouAction);
55+
const createdTransactionThreadReport = createTransactionThreadReport({
56+
introSelected,
57+
currentUserLogin: email ?? '',
58+
currentUserAccountID: accountID,
59+
betas,
60+
iouReport: moneyRequestReport,
61+
iouReportAction: iouAction,
62+
});
5663
threadID = createdTransactionThreadReport?.reportID;
5764
}
5865
}

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,15 @@ function MoneyRequestReportTransactionList({
456456

457457
if (!reportIDToNavigate) {
458458
const transaction = sortedTransactions.find((t) => t.transactionID === activeTransactionID);
459-
const transactionThreadReport = createTransactionThreadReport(
459+
const transactionThreadReport = createTransactionThreadReport({
460460
introSelected,
461-
currentUserDetails.email ?? '',
462-
currentUserDetails.accountID,
461+
currentUserLogin: currentUserDetails.email ?? '',
462+
currentUserAccountID: currentUserDetails.accountID,
463463
betas,
464-
report,
465-
iouAction,
464+
iouReport: report,
465+
iouReportAction: iouAction,
466466
transaction,
467-
);
467+
});
468468
if (transactionThreadReport) {
469469
reportIDToNavigate = transactionThreadReport.reportID;
470470
routeParams.reportID = reportIDToNavigate;

src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, isFromR
136136
}
137137
// The transaction thread doesn't exist yet, so we should create it
138138
if (!nextThreadReportID) {
139-
const transactionThreadReport = createTransactionThreadReport(
139+
const transactionThreadReport = createTransactionThreadReport({
140140
introSelected,
141-
currentUserEmail ?? '',
141+
currentUserLogin: currentUserEmail ?? '',
142142
currentUserAccountID,
143143
betas,
144-
parentReport,
145-
nextParentReportAction,
146-
nextTransaction,
147-
);
144+
iouReport: parentReport,
145+
iouReportAction: nextParentReportAction,
146+
transaction: nextTransaction,
147+
});
148148
navigationParams.reportID = transactionThreadReport?.reportID;
149149
}
150150
// Wait for the next frame to ensure Onyx has processed the optimistic data updates from setOptimisticTransactionThread or createTransactionThreadReport before navigating
@@ -172,15 +172,15 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, isFromR
172172
}
173173
// The transaction thread doesn't exist yet, so we should create it
174174
if (!prevThreadReportID) {
175-
const transactionThreadReport = createTransactionThreadReport(
175+
const transactionThreadReport = createTransactionThreadReport({
176176
introSelected,
177-
currentUserEmail ?? '',
177+
currentUserLogin: currentUserEmail ?? '',
178178
currentUserAccountID,
179179
betas,
180-
parentReport,
181-
prevParentReportAction,
182-
prevTransaction,
183-
);
180+
iouReport: parentReport,
181+
iouReportAction: prevParentReportAction,
182+
transaction: prevTransaction,
183+
});
184184
navigationParams.reportID = transactionThreadReport?.reportID;
185185
}
186186
// Wait for the next frame to ensure Onyx has processed the optimistic data updates from setOptimisticTransactionThread or createTransactionThreadReport before navigating

src/components/ReportActionItem/MoneyRequestAction.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ function MoneyRequestAction({
119119
const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : CONST.DEFAULT_NUMBER_ID;
120120

121121
if (!action?.childReportID && transactionID && action.reportActionID) {
122-
const transactionThreadReport = createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, iouReport, action);
122+
const transactionThreadReport = createTransactionThreadReport({
123+
introSelected,
124+
currentUserLogin: currentUserEmail ?? '',
125+
currentUserAccountID,
126+
betas,
127+
iouReport,
128+
iouReportAction: action,
129+
});
123130
if (shouldOpenReportInRHP) {
124131
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo: Navigation.getActiveRoute()}));
125132
return;

src/libs/ReportUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11588,8 +11588,11 @@ type PrepareOnboardingOnyxDataParams = {
1158811588
selectedInterestedFeatures?: string[];
1158911589
isInvitedAccountant?: boolean;
1159011590
onboardingPurposeSelected?: OnboardingPurpose;
11591-
isSelfTourViewed?: boolean;
1159211591
betas: OnyxEntry<Beta[]>;
11592+
// TODO: isSelfTourViewed will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
11593+
isSelfTourViewed?: boolean;
11594+
// TODO: hasCompletedGuidedSetupFlow will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
11595+
hasCompletedGuidedSetupFlow?: boolean;
1159311596
};
1159411597

1159511598
function getBespokeWelcomeMessage(companySize: OnboardingCompanySize | undefined, userReportedIntegration?: OnboardingAccounting): string {
@@ -11645,6 +11648,7 @@ function prepareOnboardingOnyxData({
1164511648
onboardingPurposeSelected,
1164611649
isSelfTourViewed,
1164711650
betas,
11651+
hasCompletedGuidedSetupFlow,
1164811652
}: PrepareOnboardingOnyxDataParams) {
1164911653
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) {
1165011654
// eslint-disable-next-line no-param-reassign
@@ -12208,7 +12212,7 @@ function prepareOnboardingOnyxData({
1220812212
failureData.push({
1220912213
onyxMethod: Onyx.METHOD.MERGE,
1221012214
key: ONYXKEYS.NVP_ONBOARDING,
12211-
value: {hasCompletedGuidedSetupFlow: onboarding?.hasCompletedGuidedSetupFlow ?? null},
12215+
value: {hasCompletedGuidedSetupFlow: hasCompletedGuidedSetupFlow ?? onboarding?.hasCompletedGuidedSetupFlow ?? null},
1221212216
});
1221312217
}
1221412218

src/libs/SearchUIUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,16 +2531,16 @@ function createAndOpenSearchTransactionThread(
25312531
const transaction = shouldPassTransactionData ? getTransactionFromTransactionListItem(item) : undefined;
25322532
const transactionViolations = shouldPassTransactionData ? item.violations : undefined;
25332533
const reportActionToPass = iouReportAction ?? item.reportAction ?? ({reportActionID} as OnyxTypes.ReportAction);
2534-
transactionThreadReport = createTransactionThreadReport(
2534+
transactionThreadReport = createTransactionThreadReport({
25352535
introSelected,
2536-
currentUserLogin ?? '',
2536+
currentUserLogin: currentUserLogin ?? '',
25372537
currentUserAccountID,
25382538
betas,
2539-
getReportOrDraftReport(item.reportID) ?? item.report,
2540-
reportActionToPass,
2539+
iouReport: getReportOrDraftReport(item.reportID) ?? item.report,
2540+
iouReportAction: reportActionToPass,
25412541
transaction,
25422542
transactionViolations,
2543-
);
2543+
});
25442544
}
25452545

25462546
if (shouldNavigate) {

src/libs/actions/IOU/BulkEdit.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ function updateMultipleMoneyRequests({
138138
// bulk-edit comments are visible immediately while still offline.
139139
let didCreateThreadInThisIteration = false;
140140
if (!transactionThreadReportID && iouReport?.reportID) {
141-
const optimisticTransactionThread = createTransactionThreadReport(introSelected, currentUserLogin, currentUserAccountID, betas, iouReport, reportAction, transaction);
141+
const optimisticTransactionThread = createTransactionThreadReport({
142+
introSelected,
143+
currentUserLogin,
144+
currentUserAccountID,
145+
betas,
146+
iouReport,
147+
iouReportAction: reportAction,
148+
transaction,
149+
});
142150
if (optimisticTransactionThread?.reportID) {
143151
transactionThreadReportID = optimisticTransactionThread.reportID;
144152
transactionThread = optimisticTransactionThread;

src/libs/actions/Report/index.ts

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ type OpenReportActionParams = {
346346
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
347347
isSelfTourViewed?: boolean;
348348

349+
/** Whether the user has completed the guided setup flow */
350+
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
351+
hasCompletedGuidedSetupFlow?: boolean;
352+
349353
/** Beta features list */
350354
betas: OnyxEntry<Beta[]>;
351355
};
@@ -1366,9 +1370,11 @@ function getGuidedSetupDataForOpenReport(
13661370
betas: OnyxEntry<Beta[]>,
13671371
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
13681372
isSelfTourViewed?: boolean,
1373+
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
1374+
hasCompletedGuidedSetupFlow?: boolean,
13691375
): GuidedSetupDataForOpenReport | undefined {
13701376
const isInviteOnboardingComplete = introSelected?.isInviteOnboardingComplete ?? false;
1371-
const isOnboardingCompleted = onboarding?.hasCompletedGuidedSetupFlow ?? false;
1377+
const isOnboardingCompleted = hasCompletedGuidedSetupFlow ?? onboarding?.hasCompletedGuidedSetupFlow ?? false;
13721378

13731379
// Some cases we can have two open report requests with guide setup data because isInviteOnboardingComplete is not updated completely.
13741380
// Then we need to check the list request and prevent the guided setup data from being duplicated.
@@ -1401,6 +1407,7 @@ function getGuidedSetupDataForOpenReport(
14011407
onboardingMessage,
14021408
companySize: introSelected?.companySize as OnboardingCompanySize,
14031409
isSelfTourViewed,
1410+
hasCompletedGuidedSetupFlow,
14041411
betas,
14051412
});
14061413

@@ -1448,6 +1455,7 @@ function openReport(params: OpenReportActionParams) {
14481455
currentUserLogin,
14491456
currentUserAccountID,
14501457
isSelfTourViewed,
1458+
hasCompletedGuidedSetupFlow,
14511459
betas,
14521460
} = params;
14531461
if (!reportID) {
@@ -1678,7 +1686,7 @@ function openReport(params: OpenReportActionParams) {
16781686
});
16791687
}
16801688

1681-
const guidedSetup = getGuidedSetupDataForOpenReport(introSelected, betas, isSelfTourViewed);
1689+
const guidedSetup = getGuidedSetupDataForOpenReport(introSelected, betas, isSelfTourViewed, hasCompletedGuidedSetupFlow);
16821690
if (guidedSetup) {
16831691
optimisticData.push(...guidedSetup.optimisticData);
16841692
successData.push(...guidedSetup.successData);
@@ -2093,18 +2101,59 @@ function getOptimisticChatReport(accountID: number, currentUserAccountID: number
20932101
});
20942102
}
20952103

2096-
function createTransactionThreadReport(
2097-
introSelected: OnyxEntry<IntroSelected>,
2098-
currentUserLogin: string,
2099-
currentUserAccountID: number,
2100-
betas: OnyxEntry<Beta[]>,
2101-
iouReport?: OnyxEntry<Report>,
2102-
iouReportAction?: OnyxEntry<ReportAction>,
2103-
transaction?: Transaction,
2104-
transactionViolations?: TransactionViolations,
2104+
type CreateTransactionThreadReportParams = {
2105+
/** The intro selected by the user */
2106+
introSelected: OnyxEntry<IntroSelected>;
2107+
2108+
/** The current user's login */
2109+
currentUserLogin: string;
2110+
2111+
/** The current user's account ID */
2112+
currentUserAccountID: number;
2113+
2114+
/** Beta features list */
2115+
betas: OnyxEntry<Beta[]>;
2116+
2117+
/** The IOU report that the transaction thread is being created from */
2118+
iouReport?: OnyxEntry<Report>;
2119+
2120+
/** The IOU report action that the transaction thread is being created from */
2121+
iouReportAction?: OnyxEntry<ReportAction>;
2122+
2123+
/** The transaction object for legacy transactions that don't have a transaction thread or money request preview yet */
2124+
transaction?: Transaction;
2125+
2126+
/** The violations for the transaction, if any */
2127+
transactionViolations?: TransactionViolations;
2128+
21052129
// TODO: personalDetails should be a required field in follow-up PRs https://github.com/Expensify/App/issues/73656
2106-
personalDetails?: OnyxEntry<PersonalDetailsList>,
2107-
): OptimisticChatReport | undefined {
2130+
/** The personal details of the participants */
2131+
personalDetails?: OnyxEntry<PersonalDetailsList>;
2132+
2133+
/** Whether the user has seen the self tour */
2134+
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
2135+
isSelfTourViewed?: boolean;
2136+
2137+
/** Whether the user has completed the guided setup flow */
2138+
// TODO: This will be required eventually. Refactor issue: https://github.com/Expensify/App/issues/66424
2139+
hasCompletedGuidedSetupFlow?: boolean;
2140+
};
2141+
2142+
function createTransactionThreadReport(params: CreateTransactionThreadReportParams): OptimisticChatReport | undefined {
2143+
const {
2144+
introSelected,
2145+
currentUserLogin,
2146+
currentUserAccountID,
2147+
betas,
2148+
iouReport,
2149+
iouReportAction,
2150+
transaction,
2151+
transactionViolations,
2152+
personalDetails,
2153+
isSelfTourViewed,
2154+
hasCompletedGuidedSetupFlow,
2155+
} = params;
2156+
21082157
// Determine if we need selfDM report (for track expenses or unreported transactions)
21092158
const isTrackExpense = !iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction);
21102159
const isUnreportedTransaction = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
@@ -2159,6 +2208,8 @@ function createTransactionThreadReport(
21592208
optimisticSelfDMReport,
21602209
currentUserLogin,
21612210
currentUserAccountID,
2211+
isSelfTourViewed,
2212+
hasCompletedGuidedSetupFlow,
21622213
betas,
21632214
});
21642215
return optimisticTransactionThread;
@@ -7797,7 +7848,7 @@ function clearConciergeThinkingKickoff() {
77977848
Onyx.set(ONYXKEYS.CONCIERGE_THINKING_KICKOFF, null);
77987849
}
77997850

7800-
export type {Video, GuidedSetupData, TaskForParameters, IntroSelected, OpenReportActionParams, ParticipantInfo};
7851+
export type {Video, GuidedSetupData, TaskForParameters, IntroSelected, OpenReportActionParams, ParticipantInfo, CreateTransactionThreadReportParams};
78017852

78027853
export {
78037854
addAttachmentWithComment,

src/pages/Search/SearchMoneyRequestReportPage.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
199199

200200
if (transactionThreadReportID === CONST.FAKE_REPORT_ID && oneTransactionID) {
201201
const iouAction = getIOUActionForTransactionID(reportActions, oneTransactionID);
202-
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, iouAction);
202+
createTransactionThreadReport({
203+
introSelected,
204+
currentUserLogin: currentUserEmail ?? '',
205+
currentUserAccountID,
206+
betas,
207+
iouReport: report,
208+
iouReportAction: iouAction,
209+
});
203210
return;
204211
}
205212

@@ -267,7 +274,15 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
267274
hasCreatedLegacyThreadRef.current = true;
268275

269276
const violations = allReportViolations[transaction.transactionID] ?? snapshotViolations;
270-
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, undefined, transaction, violations);
277+
createTransactionThreadReport({
278+
introSelected,
279+
currentUserLogin: currentUserEmail ?? '',
280+
currentUserAccountID,
281+
betas,
282+
iouReport: report,
283+
transaction,
284+
transactionViolations: violations,
285+
});
271286
}, [
272287
allReportTransactions,
273288
allReportViolations,

src/pages/inbox/ReportFetchHandler.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ function ReportFetchHandler() {
148148
);
149149
const oneTransactionID = currentReportTransactions.at(0)?.transactionID;
150150
const iouAction = getIOUActionForReportID(reportID, oneTransactionID);
151-
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, iouAction, currentReportTransactions.at(0));
151+
createTransactionThreadReport({
152+
introSelected,
153+
currentUserLogin: currentUserEmail ?? '',
154+
currentUserAccountID,
155+
betas,
156+
iouReport: report,
157+
iouReportAction: iouAction,
158+
transaction: currentReportTransactions.at(0),
159+
});
152160
});
153161

154162
const onUnmount = useEffectEvent(() => {
@@ -350,7 +358,14 @@ function ReportFetchHandler() {
350358

351359
// For legacy transactions, pass undefined as IOU action and the transaction object
352360
// It will be created optimistically and in the backend when call openReport
353-
createTransactionThreadReport(introSelected, currentUserEmail ?? '', currentUserAccountID, betas, report, undefined, transaction);
361+
createTransactionThreadReport({
362+
introSelected,
363+
currentUserLogin: currentUserEmail ?? '',
364+
currentUserAccountID,
365+
betas,
366+
iouReport: report,
367+
transaction,
368+
});
354369
}, [
355370
introSelected,
356371
currentUserEmail,

0 commit comments

Comments
 (0)