Skip to content

Commit 9b1f3cb

Browse files
MelvinBothuult
andcommitted
Pair the bulk pay policy with the report it belongs to
Resolve currentSelectedPolicyID from the report currentSelectedReportID points at instead of taking the first entry of the independently ordered selectedPolicyIDs array, so a cross-workspace selection can't route KYC and the add-bank-account flow to a different workspace than the report being paid. Co-authored-by: huult <huult@users.noreply.github.com>
1 parent d8dd7be commit 9b1f3cb

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/components/Search/SearchBulkActionsButton.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,19 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
104104
allReports,
105105
searchData,
106106
} = useSearchBulkActions({queryJSON});
107-
const currentSelectedPolicyID = selectedPolicyIDs?.at(0);
108107
const currentSelectedReportID = selectedTransactionReportIDs?.at(0) ?? selectedReportIDs?.at(0);
109-
const currentPolicy = usePolicy(currentSelectedPolicyID);
110108
const [selectedIOUReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentSelectedReportID}`);
109+
// Resolve the policy from the report that is actually being paid. selectedPolicyIDs is ordered and filtered
110+
// independently of currentSelectedReportID, so on a selection spanning workspaces its first entry can belong to a
111+
// different workspace than this report, which would send the KYC wall and the add-bank-account flow to the wrong
112+
// workspace. Fall back to the first selected policy only when the report itself yields nothing.
113+
const currentSelectedPolicyID =
114+
selectedIOUReport?.policyID ??
115+
searchData?.[`${ONYXKEYS.COLLECTION.REPORT}${currentSelectedReportID}`]?.policyID ??
116+
selectedReports.find((report) => report.reportID === currentSelectedReportID)?.policyID ??
117+
Object.values(selectedTransactions).find((transaction) => transaction.reportID === currentSelectedReportID)?.policyID ??
118+
selectedPolicyIDs?.at(0);
119+
const currentPolicy = usePolicy(currentSelectedPolicyID);
111120
const isCurrentSelectedExpenseReport = isExpenseReport(currentSelectedReportID);
112121
const pendingPaymentAdditionalDataRef = useRef<BulkPaySelectionData | undefined>(undefined);
113122

0 commit comments

Comments
 (0)