Skip to content

Commit 18cae89

Browse files
pecanoroOSBotify
authored andcommitted
Merge pull request #58390 from shubham1206agra/fix-scan-expense
Fixed scan expense flow when participants are missing (cherry picked from commit 25401cf) (CP triggered by mountiny)
1 parent 02f0058 commit 18cae89

File tree

5 files changed

+72
-49
lines changed

5 files changed

+72
-49
lines changed

src/libs/actions/IOU.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9243,7 +9243,7 @@ function replaceReceipt(transactionID: string, file: File, source: string) {
92439243
* @param transactionID of the transaction to set the participants of
92449244
* @param report attached to the transaction
92459245
*/
9246-
function setMoneyRequestParticipantsFromReport(transactionID: string, report: OnyxEntry<OnyxTypes.Report>): Participant[] {
9246+
function getMoneyRequestParticipantsFromReport(report: OnyxEntry<OnyxTypes.Report>): Participant[] {
92479247
// If the report is iou or expense report, we should get the chat report to set participant for request money
92489248
const chatReport = isMoneyRequestReportReportUtils(report) ? getReportOrDraftReport(report?.chatReportID) : report;
92499249
const currentUserAccountID = currentUserPersonalDetails?.accountID;
@@ -9268,11 +9268,19 @@ function setMoneyRequestParticipantsFromReport(transactionID: string, report: On
92689268
participants = chatReportOtherParticipants.map((accountID) => ({accountID, selected: true}));
92699269
}
92709270

9271-
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants, participantsAutoAssigned: true});
9272-
92739271
return participants;
92749272
}
92759273

9274+
/**
9275+
* Sets the participants for an IOU based on the attached report
9276+
* @param transactionID of the transaction to set the participants of
9277+
* @param report attached to the transaction
9278+
*/
9279+
function setMoneyRequestParticipantsFromReport(transactionID: string, report: OnyxEntry<OnyxTypes.Report>) {
9280+
const participants = getMoneyRequestParticipantsFromReport(report);
9281+
return Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {participants, participantsAutoAssigned: true});
9282+
}
9283+
92769284
function setMoneyRequestTaxRate(transactionID: string, taxCode: string | null) {
92779285
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {taxCode});
92789286
}
@@ -10086,6 +10094,7 @@ export {
1008610094
setMoneyRequestMerchant,
1008710095
setMoneyRequestParticipants,
1008810096
setMoneyRequestParticipantsFromReport,
10097+
getMoneyRequestParticipantsFromReport,
1008910098
setMoneyRequestPendingFields,
1009010099
setMoneyRequestReceipt,
1009110100
setMoneyRequestTag,

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
1717
import {calculateTaxAmount, getAmount, getCurrency, getDefaultTaxCode, getRequestType, getTaxValue} from '@libs/TransactionUtils';
1818
import MoneyRequestAmountForm from '@pages/iou/MoneyRequestAmountForm';
1919
import {
20+
getMoneyRequestParticipantsFromReport,
2021
requestMoney,
2122
resetSplitShares,
2223
sendMoneyElsewhere,
@@ -186,7 +187,7 @@ function IOURequestStepAmount({
186187
// to the confirm step.
187188
// If the user is started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page.
188189
if (report?.reportID && !isArchivedReport(reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) {
189-
const selectedParticipants = setMoneyRequestParticipantsFromReport(transactionID, report);
190+
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
190191
const participants = selectedParticipants.map((participant) => {
191192
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
192193
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant);
@@ -242,28 +243,30 @@ function IOURequestStepAmount({
242243
return;
243244
}
244245
}
245-
setMoneyRequestParticipantsFromReport(transactionID, report);
246246
if (isSplitBill && !report.isOwnPolicyExpenseChat && report.participants) {
247247
const participantAccountIDs = Object.keys(report.participants).map((accountID) => Number(accountID));
248248
setSplitShares(transaction, amountInSmallestCurrencyUnits, currency || CONST.CURRENCY.USD, participantAccountIDs);
249249
}
250-
navigateToConfirmationPage();
250+
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
251+
navigateToConfirmationPage();
252+
});
251253
return;
252254
}
253255

254256
// If there was no reportID, then that means the user started this flow from the global + menu
255257
// and an optimistic reportID was generated. In that case, the next step is to select the participants for this expense.
256258
if (iouType === CONST.IOU.TYPE.CREATE && isPaidGroupPolicy(activePolicy) && activePolicy?.isPolicyExpenseChatEnabled && !shouldRestrictUserBillableActions(activePolicy.id)) {
257259
const activePolicyExpenseChat = getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id);
258-
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat);
259-
Navigation.navigate(
260-
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
261-
CONST.IOU.ACTION.CREATE,
262-
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
263-
transactionID,
264-
activePolicyExpenseChat?.reportID,
265-
),
266-
);
260+
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
261+
Navigation.navigate(
262+
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
263+
CONST.IOU.ACTION.CREATE,
264+
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
265+
transactionID,
266+
activePolicyExpenseChat?.reportID,
267+
),
268+
);
269+
});
267270
} else {
268271
navigateToParticipantPage();
269272
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
2323
import {
2424
createDistanceRequest,
2525
getIOURequestPolicyID,
26+
getMoneyRequestParticipantsFromReport,
2627
resetSplitShares,
2728
setCustomUnitRateID,
2829
setMoneyRequestAmount,
@@ -312,7 +313,7 @@ function IOURequestStepDistance({
312313
// to the confirm step.
313314
// If the user started this flow using the Create expense option (combined submit/track flow), they should be redirected to the participants page.
314315
if (report?.reportID && !isArchivedReport(reportNameValuePairs) && iouType !== CONST.IOU.TYPE.CREATE) {
315-
const selectedParticipants = setMoneyRequestParticipantsFromReport(transactionID, report);
316+
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
316317
const participants = selectedParticipants.map((participant) => {
317318
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
318319
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant);
@@ -371,26 +372,28 @@ function IOURequestStepDistance({
371372
});
372373
return;
373374
}
374-
setMoneyRequestParticipantsFromReport(transactionID, report);
375-
navigateToConfirmationPage();
375+
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
376+
navigateToConfirmationPage();
377+
});
376378
return;
377379
}
378380

379381
// If there was no reportID, then that means the user started this flow from the global menu
380382
// and an optimistic reportID was generated. In that case, the next step is to select the participants for this expense.
381383
if (iouType === CONST.IOU.TYPE.CREATE && isPaidGroupPolicy(activePolicy) && activePolicy?.isPolicyExpenseChatEnabled && !shouldRestrictUserBillableActions(activePolicy.id)) {
382384
const activePolicyExpenseChat = getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id);
383-
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat);
384385
const rateID = DistanceRequestUtils.getCustomUnitRateID(activePolicyExpenseChat?.reportID);
385386
setCustomUnitRateID(transactionID, rateID);
386-
Navigation.navigate(
387-
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
388-
CONST.IOU.ACTION.CREATE,
389-
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
390-
transactionID,
391-
activePolicyExpenseChat?.reportID,
392-
),
393-
);
387+
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
388+
Navigation.navigate(
389+
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
390+
CONST.IOU.ACTION.CREATE,
391+
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
392+
transactionID,
393+
activePolicyExpenseChat?.reportID,
394+
),
395+
);
396+
});
394397
} else {
395398
navigateToParticipantPage();
396399
}

src/pages/iou/request/step/IOURequestStepScan/index.native.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import StepScreenWrapper from '@pages/iou/request/step/StepScreenWrapper';
4646
import withFullTransactionOrNotFound from '@pages/iou/request/step/withFullTransactionOrNotFound';
4747
import withWritableReportOrNotFound from '@pages/iou/request/step/withWritableReportOrNotFound';
4848
import {
49+
getMoneyRequestParticipantsFromReport,
4950
replaceReceipt,
5051
requestMoney,
5152
setMoneyRequestParticipantsFromReport,
@@ -304,15 +305,16 @@ function IOURequestStepScan({
304305
if ((transaction?.isFromGlobalCreate && iouType !== CONST.IOU.TYPE.TRACK && !report?.reportID) || iouType === CONST.IOU.TYPE.CREATE) {
305306
if (activePolicy && isPaidGroupPolicy(activePolicy) && !shouldRestrictUserBillableActions(activePolicy.id)) {
306307
const activePolicyExpenseChat = getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id);
307-
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat);
308-
Navigation.navigate(
309-
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
310-
CONST.IOU.ACTION.CREATE,
311-
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
312-
transactionID,
313-
activePolicyExpenseChat?.reportID,
314-
),
315-
);
308+
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
309+
Navigation.navigate(
310+
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
311+
CONST.IOU.ACTION.CREATE,
312+
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
313+
transactionID,
314+
activePolicyExpenseChat?.reportID,
315+
),
316+
);
317+
});
316318
} else {
317319
navigateToParticipantPage();
318320
}
@@ -321,7 +323,7 @@ function IOURequestStepScan({
321323

322324
// If the transaction was created from the + menu from the composer inside of a chat, the participants can automatically
323325
// be added to the transaction (taken from the chat report participants) and then the person is taken to the confirmation step.
324-
const selectedParticipants = setMoneyRequestParticipantsFromReport(transactionID, report);
326+
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
325327
const participants = selectedParticipants.map((participant) => {
326328
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
327329
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant);
@@ -425,7 +427,9 @@ function IOURequestStepScan({
425427
createTransaction(receipt, participant);
426428
return;
427429
}
428-
navigateToConfirmationPage();
430+
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
431+
navigateToConfirmationPage();
432+
});
429433
},
430434
[
431435
backTo,

src/pages/iou/request/step/IOURequestStepScan/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import StepScreenDragAndDropWrapper from '@pages/iou/request/step/StepScreenDrag
4646
import withFullTransactionOrNotFound from '@pages/iou/request/step/withFullTransactionOrNotFound';
4747
import withWritableReportOrNotFound from '@pages/iou/request/step/withWritableReportOrNotFound';
4848
import {
49+
getMoneyRequestParticipantsFromReport,
4950
replaceReceipt,
5051
requestMoney,
5152
setMoneyRequestParticipantsFromReport,
@@ -328,15 +329,16 @@ function IOURequestStepScan({
328329
if ((transaction?.isFromGlobalCreate && iouType !== CONST.IOU.TYPE.TRACK && !report?.reportID) || iouType === CONST.IOU.TYPE.CREATE) {
329330
if (activePolicy && isPaidGroupPolicy(activePolicy) && !shouldRestrictUserBillableActions(activePolicy.id)) {
330331
const activePolicyExpenseChat = getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id);
331-
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat);
332-
Navigation.navigate(
333-
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
334-
CONST.IOU.ACTION.CREATE,
335-
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
336-
transactionID,
337-
activePolicyExpenseChat?.reportID,
338-
),
339-
);
332+
setMoneyRequestParticipantsFromReport(transactionID, activePolicyExpenseChat).then(() => {
333+
Navigation.navigate(
334+
ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(
335+
CONST.IOU.ACTION.CREATE,
336+
iouType === CONST.IOU.TYPE.CREATE ? CONST.IOU.TYPE.SUBMIT : iouType,
337+
transactionID,
338+
activePolicyExpenseChat?.reportID,
339+
),
340+
);
341+
});
340342
} else {
341343
navigateToParticipantPage();
342344
}
@@ -345,7 +347,7 @@ function IOURequestStepScan({
345347

346348
// If the transaction was created from the + menu from the composer inside of a chat, the participants can automatically
347349
// be added to the transaction (taken from the chat report participants) and then the person is taken to the confirmation step.
348-
const selectedParticipants = setMoneyRequestParticipantsFromReport(transactionID, report);
350+
const selectedParticipants = getMoneyRequestParticipantsFromReport(report);
349351
const participants = selectedParticipants.map((participant) => {
350352
const participantAccountID = participant?.accountID ?? CONST.DEFAULT_NUMBER_ID;
351353
return participantAccountID ? getParticipantsOption(participant, personalDetails) : getReportOption(participant);
@@ -449,7 +451,9 @@ function IOURequestStepScan({
449451
createTransaction(receipt, participant);
450452
return;
451453
}
452-
navigateToConfirmationPage();
454+
setMoneyRequestParticipantsFromReport(transactionID, report).then(() => {
455+
navigateToConfirmationPage();
456+
});
453457
},
454458
[
455459
backTo,

0 commit comments

Comments
 (0)