Skip to content
81 changes: 59 additions & 22 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
generateReportID,
getReportOrDraftReport,
hasViolations as hasViolationsReportUtils,
isMoneyRequestReport,
isProcessingReport,
isReportOutstanding,
isSelectedManagerMcTest,
Expand Down Expand Up @@ -527,6 +528,41 @@
});
}, [requestType, iouType, initialTransactionID, reportID, action, report, transactions, participants]);

const policyParams = useMemo(
() => ({
policy,
policyTagList: policyTags,
policyCategories,
policyRecentlyUsedCategories,
}),
[policy, policyTags, policyCategories, policyRecentlyUsedCategories],
);

const emptyPolicyParams = useMemo(() => ({}), []);

const getMoneyRequestContextForParticipant = useCallback(
(participant: Participant | undefined) => {
const isWorkspaceTarget = !!participant?.isPolicyExpenseChat;
const workspaceChatReport = isWorkspaceTarget && participant?.reportID ? getReportOrDraftReport(participant.reportID) : undefined;
return {
parentChatReport: isWorkspaceTarget ? workspaceChatReport : undefined,
policyParams: isWorkspaceTarget ? policyParams : emptyPolicyParams,
};
},
[policyParams, emptyPolicyParams],
);

const getReportToUseAndBackToReport = useCallback(
(participant: Participant | undefined, parentChatReport: Report | undefined, reportParam: Report | undefined, backToReportParam: string | undefined) => {
const reportToUse = participant?.isPolicyExpenseChat ? parentChatReport : undefined;

const backToReportToUse = backToReportParam ?? (isMoneyRequestReport(reportParam) ? reportParam?.reportID : undefined);

return {reportToUse, backToReportToUse};
},
[],
);

const requestMoney = useCallback(
(selectedParticipants: Participant[], gpsPoint?: GpsPoint) => {
if (!transactions.length) {
Expand All @@ -538,6 +574,9 @@
return;
}

const {parentChatReport, policyParams: contextPolicyParams} = getMoneyRequestContextForParticipant(participant);
const {reportToUse, backToReportToUse} = getReportToUseAndBackToReport(participant, parentChatReport, report, backToReport);

const optimisticChatReportID = generateReportID();
const optimisticCreatedReportActionID = rand64();
const optimisticReportPreviewActionID = rand64();
Expand All @@ -556,7 +595,7 @@
}

const {iouReport} = requestMoneyIOUActions({
report,
report: reportToUse,
existingIOUReport,
optimisticChatReportID,
optimisticCreatedReportActionID,
Expand All @@ -566,12 +605,7 @@
payeeAccountID: currentUserPersonalDetails.accountID,
participant,
},
policyParams: {
policy,
policyTagList: policyTags,
policyCategories,
policyRecentlyUsedCategories,
},
policyParams: contextPolicyParams,
gpsPoint,
action,
transactionParams: {
Expand Down Expand Up @@ -600,7 +634,7 @@
},
shouldHandleNavigation: index === transactions.length - 1,
shouldGenerateTransactionThreadReport,
backToReport,
backToReport: backToReportToUse,
isASAPSubmitBetaEnabled,
currentUserAccountIDParam: currentUserPersonalDetails.accountID,
currentUserEmailParam: currentUserPersonalDetails.login ?? '',
Expand All @@ -609,7 +643,7 @@
existingIOUReport = iouReport;
}
},
[

Check warning on line 646 in src/pages/iou/request/step/IOURequestStepConfirmation.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has missing dependencies: 'getMoneyRequestContextForParticipant' and 'getReportToUseAndBackToReport'. Either include them or remove the dependency array
transactions,
receiptFiles,
archivedReportsIdSet,
Expand Down Expand Up @@ -700,24 +734,23 @@
if (!participant) {
return;
}
const {parentChatReport, policyParams: contextPolicyParams} = getMoneyRequestContextForParticipant(participant);
const {reportToUse} = getReportToUseAndBackToReport(participant, parentChatReport, report, backToReport);

for (const [index, item] of transactions.entries()) {
const isLinkedTrackedExpenseReportArchived =
!!item.linkedTrackedExpenseReportID && archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${item.linkedTrackedExpenseReportID}`);

trackExpenseIOUActions({
report,
report: reportToUse,
isDraftPolicy,
action,
participantParams: {
payeeEmail: currentUserPersonalDetails.login,
payeeAccountID: currentUserPersonalDetails.accountID,
participant,
},
policyParams: {
policy,
policyCategories,
policyTagList: policyTags,
},
policyParams: contextPolicyParams,
transactionParams: {
amount: item.amount,
distance: isManualDistanceRequest ? (item.comment?.customUnit?.quantity ?? undefined) : undefined,
Expand Down Expand Up @@ -749,7 +782,7 @@
});
}
},
[

Check warning on line 785 in src/pages/iou/request/step/IOURequestStepConfirmation.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has missing dependencies: 'backToReport', 'getMoneyRequestContextForParticipant', and 'getReportToUseAndBackToReport'. Either include them or remove the dependency array
report,
transactions,
receiptFiles,
Expand All @@ -774,19 +807,23 @@
if (!transaction) {
return;
}

const participant = selectedParticipants.at(0);
if (!participant) {
return;
}

const {parentChatReport, policyParams: contextPolicyParams} = getMoneyRequestContextForParticipant(participant);
const {reportToUse, backToReportToUse} = getReportToUseAndBackToReport(participant, parentChatReport, report, backToReport);

createDistanceRequestIOUActions({
report,
report: reportToUse,
participants: selectedParticipants,
currentUserLogin: currentUserPersonalDetails.login,
currentUserAccountID: currentUserPersonalDetails.accountID,
iouType,
existingTransaction: transaction,
policyParams: {
policy,
policyCategories,
policyTagList: policyTags,
policyRecentlyUsedCategories,
},
policyParams: contextPolicyParams,
transactionParams: {
amount: transaction.amount,
comment: trimmedComment,
Expand All @@ -806,12 +843,12 @@
attendees: transaction.comment?.attendees,
receipt: isManualDistanceRequest ? receiptFiles[transaction.transactionID] : undefined,
},
backToReport,
backToReport: backToReportToUse,
isASAPSubmitBetaEnabled,
transactionViolations,
});
},
[

Check warning on line 851 in src/pages/iou/request/step/IOURequestStepConfirmation.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has missing dependencies: 'getMoneyRequestContextForParticipant' and 'getReportToUseAndBackToReport'. Either include them or remove the dependency array
transaction,
report,
currentUserPersonalDetails.login,
Expand Down
Loading