Skip to content

Commit 9529299

Browse files
committed
fixed pr comments
1 parent 47c4a3f commit 9529299

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/pages/iou/request/step/IOURequestStepParticipants.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import ROUTES from '@src/ROUTES';
4141
import type SCREENS from '@src/SCREENS';
4242
import type {Policy} from '@src/types/onyx';
4343
import type {Participant} from '@src/types/onyx/IOU';
44+
import type Report from '@src/types/onyx/Report';
4445
import type Transaction from '@src/types/onyx/Transaction';
4546
import getEmptyArray from '@src/types/utils/getEmptyArray';
4647
import KeyboardUtils from '@src/utils/keyboard';
@@ -121,7 +122,14 @@ function IOURequestStepParticipants({
121122
return translate('iou.chooseRecipient');
122123
}, [iouType, translate, isSplitRequest, action]);
123124

124-
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
125+
const selfDMReportSelector = useCallback((reports: OnyxCollection<Report>) => {
126+
const selfDMReportID = findSelfDMReportID();
127+
if (selfDMReportID && reports) {
128+
return reports[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
129+
}
130+
}, []);
131+
132+
const [selfDMReport] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true, selector: selfDMReportSelector});
125133
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false});
126134
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`, {canBeMissing: true});
127135
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
@@ -186,9 +194,7 @@ function IOURequestStepParticipants({
186194
const trackExpense = useCallback(() => {
187195
// If coming from the combined submit/track flow and the user proceeds to just track the expense,
188196
// we will use the track IOU type in the confirmation flow.
189-
const selfDMReportID = findSelfDMReportID();
190-
const selfDMReport = selfDMReportID && reports ? reports[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`] : undefined;
191-
if (!selfDMReportID) {
197+
if (!selfDMReport) {
192198
return;
193199
}
194200

@@ -202,9 +208,9 @@ function IOURequestStepParticipants({
202208
currentUserPersonalDetails.accountID,
203209
shouldSetParticipantAutoAssignment ? isActivePolicyRequest : false,
204210
);
205-
setTransactionReport(transaction.transactionID, {reportID: selfDMReportID}, true);
211+
setTransactionReport(transaction.transactionID, {reportID: selfDMReport.reportID}, true);
206212
}
207-
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, CONST.IOU.TYPE.TRACK, initialTransactionID, selfDMReportID);
213+
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, CONST.IOU.TYPE.TRACK, initialTransactionID, selfDMReport.reportID);
208214
waitForKeyboardDismiss(() => {
209215
// If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack.
210216
if (backTo) {
@@ -218,7 +224,7 @@ function IOURequestStepParticipants({
218224
});
219225
}
220226
});
221-
}, [transactions, action, initialTransactionID, waitForKeyboardDismiss, iouType, currentUserPersonalDetails.accountID, reports, isActivePolicyRequest, backTo]);
227+
}, [transactions, action, initialTransactionID, waitForKeyboardDismiss, iouType, currentUserPersonalDetails.accountID, selfDMReport, isActivePolicyRequest, backTo]);
222228

223229
const addParticipant = useCallback(
224230
(val: Participant[]) => {

0 commit comments

Comments
 (0)