@@ -250,7 +250,7 @@ import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
250250import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
251251import type {QuickActionName} from '@src/types/onyx/QuickAction';
252252import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
253- import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report';
253+ import type {InvoiceReceiver, InvoiceReceiverType, ReportNextStep } from '@src/types/onyx/Report';
254254import type ReportAction from '@src/types/onyx/ReportAction';
255255import type {OnyxData} from '@src/types/onyx/Request';
256256import type {SearchTransaction} from '@src/types/onyx/SearchResults';
@@ -572,7 +572,8 @@ type MoneyRequestOptimisticParams = {
572572 destinations?: string[];
573573 };
574574 personalDetailListAction?: OnyxTypes.PersonalDetailsList;
575- nextStep?: OnyxTypes.ReportNextStepDeprecated | null;
575+ nextStepDeprecated?: OnyxTypes.ReportNextStepDeprecated | null;
576+ nextStep?: ReportNextStep | null;
576577 testDriveCommentReportActionID?: string;
577578};
578579
@@ -1616,6 +1617,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
16161617 policyRecentlyUsed,
16171618 personalDetailListAction,
16181619 nextStep,
1620+ nextStepDeprecated,
16191621 testDriveCommentReportActionID,
16201622 } = optimisticParams;
16211623
@@ -1886,11 +1888,42 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
18861888 });
18871889 }
18881890
1889- if (!isEmptyObject(nextStep )) {
1891+ if (!isEmptyObject(nextStepDeprecated )) {
18901892 optimisticData.push({
18911893 onyxMethod: Onyx.METHOD.MERGE,
18921894 key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iou.report.reportID}`,
1893- value: nextStep,
1895+ value: nextStepDeprecated,
1896+ });
1897+ }
1898+ if (!isEmptyObject(nextStep)) {
1899+ optimisticData.push({
1900+ onyxMethod: Onyx.METHOD.MERGE,
1901+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
1902+ value: {
1903+ nextStep,
1904+ pendingFields: {
1905+ nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
1906+ },
1907+ },
1908+ });
1909+ successData.push({
1910+ onyxMethod: Onyx.METHOD.MERGE,
1911+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
1912+ value: {
1913+ pendingFields: {
1914+ nextStep: null,
1915+ },
1916+ },
1917+ });
1918+ failureData.push({
1919+ onyxMethod: Onyx.METHOD.MERGE,
1920+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
1921+ value: {
1922+ nextStep: iou.report.nextStep ?? null,
1923+ pendingFields: {
1924+ nextStep: null,
1925+ },
1926+ },
18941927 });
18951928 }
18961929
@@ -2149,7 +2182,6 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
21492182 if (!policy || !isPaidGroupPolicy(policy) || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
21502183 return [optimisticData, successData, failureData];
21512184 }
2152-
21532185 const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
21542186 transaction,
21552187 [],
@@ -2162,10 +2194,20 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
21622194
21632195 if (violationsOnyxData) {
21642196 const shouldFixViolations = Array.isArray(violationsOnyxData.value) && violationsOnyxData.value.length > 0;
2165-
2197+ const optimisticNextStep = buildOptimisticNextStep({
2198+ report: iou.report,
2199+ predictedNextStatus: iou.report.statusNum ?? CONST.REPORT.STATE_NUM.OPEN,
2200+ shouldFixViolations,
2201+ policy,
2202+ currentUserAccountIDParam,
2203+ currentUserEmailParam,
2204+ hasViolations,
2205+ isASAPSubmitBetaEnabled,
2206+ });
21662207 optimisticData.push(violationsOnyxData, {
21672208 key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iou.report.reportID}`,
21682209 onyxMethod: Onyx.METHOD.SET,
2210+ // buildOptimisticNextStep is used in parallel
21692211 // eslint-disable-next-line @typescript-eslint/no-deprecated
21702212 value: buildNextStepNew({
21712213 report: iou.report,
@@ -2178,11 +2220,40 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
21782220 isASAPSubmitBetaEnabled,
21792221 }),
21802222 });
2223+ optimisticData.push({
2224+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
2225+ onyxMethod: Onyx.METHOD.MERGE,
2226+ value: {
2227+ nextStep: optimisticNextStep,
2228+ pendingFields: {
2229+ nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
2230+ },
2231+ },
2232+ });
2233+ successData.push({
2234+ onyxMethod: Onyx.METHOD.MERGE,
2235+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
2236+ value: {
2237+ pendingFields: {
2238+ nextStep: null,
2239+ },
2240+ },
2241+ });
21812242 failureData.push({
21822243 onyxMethod: Onyx.METHOD.SET,
21832244 key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
21842245 value: [],
21852246 });
2247+ failureData.push({
2248+ key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
2249+ onyxMethod: Onyx.METHOD.MERGE,
2250+ value: {
2251+ nextStep: iou.report.nextStep ?? null,
2252+ pendingFields: {
2253+ nextStep: null,
2254+ },
2255+ },
2256+ });
21862257 }
21872258
21882259 return [optimisticData, successData, failureData];
@@ -3666,8 +3737,19 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
36663737
36673738 const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN;
36683739 const hasViolations = hasViolationsReportUtils(iouReport.reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam);
3740+ // buildOptimisticNextStep is used in parallel
36693741 // eslint-disable-next-line @typescript-eslint/no-deprecated
3670- const optimisticNextStep = buildNextStepNew({
3742+ const optimisticNextStepDeprecated = buildNextStepNew({
3743+ report: iouReport,
3744+ predictedNextStatus,
3745+ policy,
3746+ currentUserAccountIDParam,
3747+ currentUserEmailParam,
3748+ hasViolations,
3749+ isASAPSubmitBetaEnabled,
3750+ });
3751+
3752+ const optimisticNextStep = buildOptimisticNextStep({
36713753 report: iouReport,
36723754 predictedNextStatus,
36733755 policy,
@@ -3710,6 +3792,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
37103792 currencies: optimisticPolicyRecentlyUsedCurrencies,
37113793 },
37123794 personalDetailListAction: optimisticPersonalDetailListAction,
3795+ nextStepDeprecated: optimisticNextStepDeprecated,
37133796 nextStep: optimisticNextStep,
37143797 testDriveCommentReportActionID,
37153798 },
@@ -3970,8 +4053,26 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
39704053 : {};
39714054
39724055 const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN;
4056+ // buildOptimisticNextStep is used in parallel
39734057 // eslint-disable-next-line @typescript-eslint/no-deprecated
3974- const optimisticNextStep = buildNextStepNew({report: iouReport, predictedNextStatus, currentUserAccountIDParam, currentUserEmailParam, hasViolations, isASAPSubmitBetaEnabled, policy});
4058+ const optimisticNextStepDeprecated = buildNextStepNew({
4059+ report: iouReport,
4060+ predictedNextStatus,
4061+ currentUserAccountIDParam,
4062+ currentUserEmailParam,
4063+ hasViolations,
4064+ isASAPSubmitBetaEnabled,
4065+ policy,
4066+ });
4067+ const optimisticNextStep = buildOptimisticNextStep({
4068+ report: iouReport,
4069+ predictedNextStatus,
4070+ currentUserAccountIDParam,
4071+ currentUserEmailParam,
4072+ hasViolations,
4073+ isASAPSubmitBetaEnabled,
4074+ policy,
4075+ });
39754076
39764077 // STEP 5: Build Onyx Data
39774078 const [optimisticData, successData, failureData] = buildOnyxDataForMoneyRequest({
@@ -4007,6 +4108,7 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
40074108 },
40084109 personalDetailListAction: optimisticPersonalDetailListAction,
40094110 nextStep: optimisticNextStep,
4111+ nextStepDeprecated: optimisticNextStepDeprecated,
40104112 },
40114113 currentUserAccountIDParam,
40124114 currentUserEmailParam,
@@ -4818,9 +4920,20 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
48184920 const shouldFixViolations = Array.isArray(violationsOnyxData.value) && violationsOnyxData.value.length > 0;
48194921 const moneyRequestReport = updatedMoneyRequestReport ?? iouReport ?? undefined;
48204922 const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, currentUserAccountIDParam, currentUserEmailParam);
4923+ const optimisticNextStep = buildOptimisticNextStep({
4924+ report: moneyRequestReport,
4925+ predictedNextStatus: iouReport?.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN,
4926+ shouldFixViolations,
4927+ currentUserAccountIDParam,
4928+ currentUserEmailParam,
4929+ hasViolations,
4930+ isASAPSubmitBetaEnabled,
4931+ policy,
4932+ });
48214933 optimisticData.push({
48224934 onyxMethod: Onyx.METHOD.MERGE,
48234935 key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`,
4936+ // buildOptimisticNextStep is used in parallel
48244937 // eslint-disable-next-line @typescript-eslint/no-deprecated
48254938 value: buildNextStepNew({
48264939 report: moneyRequestReport,
@@ -4833,11 +4946,40 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
48334946 policy,
48344947 }),
48354948 });
4949+ optimisticData.push({
4950+ onyxMethod: Onyx.METHOD.MERGE,
4951+ key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
4952+ value: {
4953+ nextStep: optimisticNextStep,
4954+ pendingFields: {
4955+ nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
4956+ },
4957+ },
4958+ });
48364959 failureData.push({
48374960 onyxMethod: Onyx.METHOD.MERGE,
48384961 key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`,
48394962 value: currentNextStep,
48404963 });
4964+ failureData.push({
4965+ onyxMethod: Onyx.METHOD.MERGE,
4966+ key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
4967+ value: {
4968+ nextStep: iouReport?.nextStep ?? null,
4969+ pendingFields: {
4970+ nextStep: null,
4971+ },
4972+ },
4973+ });
4974+ successData.push({
4975+ onyxMethod: Onyx.METHOD.MERGE,
4976+ key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
4977+ value: {
4978+ pendingFields: {
4979+ nextStep: null,
4980+ },
4981+ },
4982+ });
48414983 }
48424984 }
48434985
@@ -11784,7 +11926,11 @@ function cancelPayment(
1178411926 statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
1178511927 isWaitingOnBankAccount: expenseReport.isWaitingOnBankAccount,
1178611928 isCancelledIOU: false,
11787- nextStep: expenseReport.nextStep ?? null,
11929+ nextStep:
11930+ buildOptimisticNextStep({
11931+ report: expenseReport,
11932+ predictedNextStatus: CONST.REPORT.STATUS_NUM.REIMBURSED,
11933+ }) ?? null,
1178811934 pendingFields: {
1178911935 nextStep: null,
1179011936 },
@@ -11836,6 +11982,7 @@ function cancelPayment(
1183611982 failureData.push({
1183711983 onyxMethod: Onyx.METHOD.MERGE,
1183811984 key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`,
11985+ // buildOptimisticNextStep is used in parallel
1183911986 // eslint-disable-next-line @typescript-eslint/no-deprecated
1184011987 value: buildNextStepNew({
1184111988 report: expenseReport,
0 commit comments