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
165 changes: 156 additions & 9 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
import type {QuickActionName} from '@src/types/onyx/QuickAction';
import type RecentlyUsedTags from '@src/types/onyx/RecentlyUsedTags';
import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report';
import type {InvoiceReceiver, InvoiceReceiverType, ReportNextStep} from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import type {SearchTransaction} from '@src/types/onyx/SearchResults';
Expand Down Expand Up @@ -574,7 +574,8 @@
destinations?: string[];
};
personalDetailListAction?: OnyxTypes.PersonalDetailsList;
nextStep?: OnyxTypes.ReportNextStepDeprecated | null;
nextStepDeprecated?: OnyxTypes.ReportNextStepDeprecated | null;
nextStep?: ReportNextStep | null;
testDriveCommentReportActionID?: string;
};

Expand Down Expand Up @@ -742,7 +743,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 746 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -837,7 +838,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 841 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -851,7 +852,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 855 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -860,7 +861,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 864 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -874,7 +875,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStepDeprecated>> = {};
Onyx.connect({

Check warning on line 878 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -886,14 +887,14 @@
// `allRecentlyUsedTags` was moved here temporarily from `src/libs/actions/Policy/Tag.ts` during the `Deprecate Onyx.connect` refactor.
// All uses of this variable should be replaced with `useOnyx`.
let allRecentlyUsedTags: OnyxCollection<RecentlyUsedTags> = {};
Onyx.connect({

Check warning on line 890 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS,
waitForCollectionCallback: true,
callback: (val) => (allRecentlyUsedTags = val),
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 897 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -902,7 +903,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 906 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -912,7 +913,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 916 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -921,7 +922,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 925 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -1624,6 +1625,7 @@
policyRecentlyUsed,
personalDetailListAction,
nextStep,
nextStepDeprecated,
testDriveCommentReportActionID,
} = optimisticParams;

Expand Down Expand Up @@ -1894,11 +1896,42 @@
});
}

if (!isEmptyObject(nextStep)) {
if (!isEmptyObject(nextStepDeprecated)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iou.report.reportID}`,
value: nextStep,
value: nextStepDeprecated,
});
}
if (!isEmptyObject(nextStep)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
value: {
nextStep,
pendingFields: {
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
Comment thread
DylanDylann marked this conversation as resolved.
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
value: {
pendingFields: {
nextStep: null,
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
value: {
nextStep: iou.report.nextStep ?? null,
pendingFields: {
nextStep: null,
},
},
});
}

Expand Down Expand Up @@ -2157,7 +2190,6 @@
if (!policy || !isPaidGroupPolicy(policy) || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
return [optimisticData, successData, failureData];
}

const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
transaction,
[],
Expand All @@ -2170,10 +2202,20 @@

if (violationsOnyxData) {
const shouldFixViolations = Array.isArray(violationsOnyxData.value) && violationsOnyxData.value.length > 0;

const optimisticNextStep = buildOptimisticNextStep({
report: iou.report,
predictedNextStatus: iou.report.statusNum ?? CONST.REPORT.STATE_NUM.OPEN,
shouldFixViolations,
policy,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
});
optimisticData.push(violationsOnyxData, {
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iou.report.reportID}`,
onyxMethod: Onyx.METHOD.SET,
// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
value: buildNextStepNew({
report: iou.report,
Expand All @@ -2186,11 +2228,40 @@
isASAPSubmitBetaEnabled,
}),
});
optimisticData.push({
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
nextStep: optimisticNextStep,
pendingFields: {
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
value: {
pendingFields: {
nextStep: null,
},
},
Comment thread
DylanDylann marked this conversation as resolved.
});
Comment thread
DylanDylann marked this conversation as resolved.
failureData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
value: [],
});
failureData.push({
key: `${ONYXKEYS.COLLECTION.REPORT}${iou.report.reportID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
nextStep: iou.report.nextStep ?? null,
pendingFields: {
nextStep: null,
},
},
});
}

return [optimisticData, successData, failureData];
Expand Down Expand Up @@ -3674,8 +3745,19 @@

const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN;
const hasViolations = hasViolationsReportUtils(iouReport.reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam);
// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
const optimisticNextStep = buildNextStepNew({
const optimisticNextStepDeprecated = buildNextStepNew({
report: iouReport,
predictedNextStatus,
policy,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
});

const optimisticNextStep = buildOptimisticNextStep({
report: iouReport,
predictedNextStatus,
policy,
Expand Down Expand Up @@ -3718,6 +3800,7 @@
currencies: optimisticPolicyRecentlyUsedCurrencies,
},
personalDetailListAction: optimisticPersonalDetailListAction,
nextStepDeprecated: optimisticNextStepDeprecated,
nextStep: optimisticNextStep,
testDriveCommentReportActionID,
},
Expand Down Expand Up @@ -3979,8 +4062,26 @@
: {};

const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN;
// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
const optimisticNextStep = buildNextStepNew({report: iouReport, predictedNextStatus, currentUserAccountIDParam, currentUserEmailParam, hasViolations, isASAPSubmitBetaEnabled, policy});
const optimisticNextStepDeprecated = buildNextStepNew({
report: iouReport,
predictedNextStatus,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
policy,
});
const optimisticNextStep = buildOptimisticNextStep({
report: iouReport,
predictedNextStatus,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
policy,
});

// STEP 5: Build Onyx Data
const [optimisticData, successData, failureData] = buildOnyxDataForMoneyRequest({
Expand Down Expand Up @@ -4016,6 +4117,7 @@
},
personalDetailListAction: optimisticPersonalDetailListAction,
nextStep: optimisticNextStep,
nextStepDeprecated: optimisticNextStepDeprecated,
},
currentUserAccountIDParam,
currentUserEmailParam,
Expand Down Expand Up @@ -4820,9 +4922,20 @@
const shouldFixViolations = Array.isArray(violationsOnyxData.value) && violationsOnyxData.value.length > 0;
const moneyRequestReport = updatedMoneyRequestReport ?? iouReport ?? undefined;
const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, currentUserAccountIDParam, currentUserEmailParam);
const optimisticNextStep = buildOptimisticNextStep({
report: moneyRequestReport,
predictedNextStatus: iouReport?.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN,
shouldFixViolations,
currentUserAccountIDParam,
currentUserEmailParam,
hasViolations,
isASAPSubmitBetaEnabled,
policy,
});
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`,
// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
value: buildNextStepNew({
report: moneyRequestReport,
Expand All @@ -4835,11 +4948,40 @@
policy,
}),
});
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
value: {
nextStep: optimisticNextStep,
pendingFields: {
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
});
Comment thread
DylanDylann marked this conversation as resolved.
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`,
value: currentNextStep,
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
value: {
nextStep: iouReport?.nextStep ?? null,
pendingFields: {
nextStep: null,
},
},
});
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`,
value: {
pendingFields: {
nextStep: null,
},
},
});
}
}

Expand Down Expand Up @@ -11781,7 +11923,11 @@
statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
isWaitingOnBankAccount: expenseReport.isWaitingOnBankAccount,
isCancelledIOU: false,
nextStep: expenseReport.nextStep ?? null,
nextStep:
buildOptimisticNextStep({
report: expenseReport,
predictedNextStatus: CONST.REPORT.STATUS_NUM.REIMBURSED,
}) ?? null,
pendingFields: {
nextStep: null,
},
Expand Down Expand Up @@ -11833,6 +11979,7 @@
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`,
// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
value: buildNextStepNew({
report: expenseReport,
Expand Down
Loading