Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,21 @@
});
}, [requestType, iouType, initialTransactionID, reportID, action, report, transactions, participants]);

function getMoneyRequestContextForParticipant(participant: Participant | undefined, reportParam: Report | undefined) {
const isWorkspaceTarget = !!participant?.isPolicyExpenseChat;
return {
parentChatReport: isWorkspaceTarget ? reportParam : undefined,
policyParams: isWorkspaceTarget
? {
policy,
policyTagList: policyTags,
policyCategories,
policyRecentlyUsedCategories,
}
: {},
};
}

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

const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);

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

const {iouReport} = requestMoneyIOUActions({
report,
report: parentChatReport,
existingIOUReport,
optimisticChatReportID,
optimisticCreatedReportActionID,
Expand All @@ -551,12 +568,7 @@
payeeAccountID: currentUserPersonalDetails.accountID,
participant,
},
policyParams: {
policy,
policyTagList: policyTags,
policyCategories,
policyRecentlyUsedCategories,
},
policyParams,
gpsPoint,
action,
transactionParams: {
Expand Down Expand Up @@ -591,7 +603,7 @@
existingIOUReport = iouReport;
}
},
[

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'getMoneyRequestContextForParticipant'. Either include it or remove the dependency array
transactions,
receiptFiles,
archivedReportsIdSet,
Expand Down Expand Up @@ -677,24 +689,21 @@
if (!participant) {
return;
}
const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);
for (const [index, item] of transactions.entries()) {
const isLinkedTrackedExpenseReportArchived =
!!item.linkedTrackedExpenseReportID && archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${item.linkedTrackedExpenseReportID}`);

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

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'getMoneyRequestContextForParticipant'. Either include it or remove the dependency array
report,
transactions,
receiptFiles,
Expand All @@ -751,19 +760,22 @@
if (!transaction) {
return;
}

const participant = selectedParticipants.at(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Issue: Missing defensive empty-participant guard in createDistanceRequest

Unlike requestMoney and trackExpense, this function does not early-return when participant is empty.

Today the UI likely always passes at least one participant, but this function is a critical backend boundary between UI and createDistanceRequestIOUActions. If a future regression allows confirming with no participant (e.g., a bug in MoneyRequestConfirmationList), selectedParticipants could be [].

createDistanceRequestIOUActions then calls participants.at(0) internally and passes a participant with no accountID to getMoneyRequestInformation which will:

• Set payerAccountID = Number(participant.accountID)0.
• Try getChatByParticipants([0, payeeAccountID]), possibly creating a bogus self / ghost chat.

Why this matters / potential bug if left as-is

If this edge case happens, you could end up with:

• Distance expenses linked to a chat that has no real participant (payer account ID 0)
• Confusing history/actions in some “ghost” conversation where nothing else lives
• Potential future crashes if other code assumes a chat’s participants always map to real account IDs

Suggested fix

Mirror the pattern in requestMoney / trackExpense:

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👉 This one is still valid even if the "🔴 Regression Alert" fix is applied.

if (!participant) {
return;
}

const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);

createDistanceRequestIOUActions({
report,
report: parentChatReport,
participants: selectedParticipants,
currentUserLogin: currentUserPersonalDetails.login,
currentUserAccountID: currentUserPersonalDetails.accountID,
iouType,
existingTransaction: transaction,
policyParams: {
policy,
policyCategories,
policyTagList: policyTags,
policyRecentlyUsedCategories,
},
policyParams,
transactionParams: {
amount: transaction.amount,
comment: trimmedComment,
Expand All @@ -787,7 +799,7 @@
isASAPSubmitBetaEnabled,
});
},
[

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

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