Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {resolveDetachReceiptConflicts} from '../RequestConflictUtils';

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

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../RequestConflictUtils'. Use '@userActions/RequestConflictUtils' instead

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

Expand Down Expand Up @@ -779,7 +779,7 @@
};

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

Check warning on line 782 in src/libs/actions/IOU/index.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 @@ -909,7 +909,7 @@
};

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

Check warning on line 912 in src/libs/actions/IOU/index.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 @@ -923,7 +923,7 @@
});

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

Check warning on line 926 in src/libs/actions/IOU/index.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 @@ -932,7 +932,7 @@
});

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

Check warning on line 935 in src/libs/actions/IOU/index.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 @@ -946,7 +946,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 949 in src/libs/actions/IOU/index.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_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -959,7 +959,7 @@
});

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

Check warning on line 962 in src/libs/actions/IOU/index.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 @@ -968,7 +968,7 @@
});

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

Check warning on line 971 in src/libs/actions/IOU/index.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 @@ -978,7 +978,7 @@

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

Check warning on line 981 in src/libs/actions/IOU/index.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 @@ -987,7 +987,7 @@
});

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

Check warning on line 990 in src/libs/actions/IOU/index.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 @@ -5290,7 +5290,7 @@
}

type UpdateMoneyRequestDistanceParams = {
transactionID: string | undefined;
transaction: OnyxEntry<OnyxTypes.Transaction>;
transactionThreadReport: OnyxEntry<OnyxTypes.Report>;
parentReport: OnyxEntry<OnyxTypes.Report>;
waypoints?: WaypointCollection;
Expand All @@ -5311,7 +5311,7 @@

/** Updates the waypoints of a distance expense */
function updateMoneyRequestDistance({
transactionID,
transaction,
transactionThreadReport,
parentReport,
waypoints,
Expand Down Expand Up @@ -5341,10 +5341,10 @@
let data: UpdateMoneyRequestData<UpdateMoneyRequestDataKeys | typeof ONYXKEYS.NVP_RECENT_WAYPOINTS>;
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReport?.reportID, transactionChanges, policy);
data = getUpdateTrackExpenseParams(transaction?.transactionID, transactionThreadReport?.reportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
transactionID,
transactionID: transaction?.transactionID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep using the route transaction ID for distance edits

updateMoneyRequestDistance() now builds the request from transaction?.transactionID, but the manual and odometer edit screens pass transaction from withFullTransactionOrNotFound before that hook necessarily has a loaded Onyx value. Those screens do not block on isLoadingTransaction and explicitly render with shouldShowNotFoundPage={false}, so on a cold start or deep link into an edit flow the user can press Save while transaction is still undefined. Before this refactor the route param still produced a valid update; now both getUpdateMoneyRequestParams() and getUpdateTrackExpenseParams() receive an undefined transactionID, so the server edit is dropped until hydration finishes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue.

transactionThreadReport,
iouReport: parentReport,
transactionChanges,
Expand Down Expand Up @@ -5376,8 +5376,6 @@
}

if (transactionBackup) {
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];

// We need to include all keys of the optimisticData's waypoints in the failureData for onyx merge to properly reset
// waypoint keys that do not exist in the failureData's waypoints. For instance, if the optimisticData waypoints had
// three keys and the failureData waypoint had only 2 keys then the third key that doesn't exist in the failureData
Expand All @@ -5394,7 +5392,7 @@
}, {});
onyxData?.failureData?.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction?.transactionID}`,
value: {
comment: {
waypoints: onyxWaypoints,
Expand Down
5 changes: 2 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ function IOURequestStepDistance({
}
if (transaction?.transactionID && report?.reportID) {
updateMoneyRequestDistance({
transactionID: transaction?.transactionID,
transaction,
transactionThreadReport: report,
parentReport,
waypoints,
Expand Down Expand Up @@ -508,8 +508,7 @@ function IOURequestStepDistance({
originalSplitTransactionDraft,
transactionBackup,
waypoints,
transaction?.routes,
transaction?.transactionID,
transaction,
report,
navigateBack,
currentTransaction?.comment?.waypoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function IOURequestStepDistanceManual({

if (shouldUpdateTransaction) {
updateMoneyRequestDistance({
transactionID: transaction?.transactionID,
transaction,
transactionThreadReport: report,
parentReport,
distance: distanceAsFloat,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ function IOURequestStepDistanceMap({
}
if (transaction?.transactionID && report?.reportID) {
updateMoneyRequestDistance({
transactionID: transaction?.transactionID,
transaction,
transactionThreadReport: report,
parentReport,
waypoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ function IOURequestStepDistanceOdometer({
if (hasChanges) {
// Update distance (which will also update amount and merchant)
updateMoneyRequestDistance({
transactionID: transaction?.transactionID,
transaction,
transactionThreadReport: report,
parentReport,
distance: calculatedDistance,
Expand Down
10 changes: 5 additions & 5 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15074,7 +15074,7 @@ describe('actions/IOU', () => {

// When updating the money request with distance and waypoints
updateMoneyRequestDistance({
transactionID,
transaction: fakeTransaction,
transactionThreadReport,
parentReport,
waypoints: fakeWaypoints,
Expand Down Expand Up @@ -15159,7 +15159,7 @@ describe('actions/IOU', () => {

// When updating the money request WITHOUT distance (only waypoints)
updateMoneyRequestDistance({
transactionID,
transaction: fakeTransaction,
transactionThreadReport,
parentReport,
waypoints: {
Expand Down Expand Up @@ -15238,7 +15238,7 @@ describe('actions/IOU', () => {

// First update: Add more waypoints to the expense
updateMoneyRequestDistance({
transactionID,
transaction: fakeTransaction,
transactionThreadReport,
parentReport,
waypoints: updatedWaypoints,
Expand Down Expand Up @@ -15305,7 +15305,7 @@ describe('actions/IOU', () => {

// Call with empty waypoints - should not crash
updateMoneyRequestDistance({
transactionID,
transaction: fakeTransaction,
transactionThreadReport,
parentReport,
waypoints: emptyWaypoints,
Expand Down Expand Up @@ -15349,7 +15349,7 @@ describe('actions/IOU', () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID2}`, fakeTransaction2);

updateMoneyRequestDistance({
transactionID: transactionID2,
transaction: fakeTransaction2,
transactionThreadReport,
parentReport,
waypoints: {
Expand Down
Loading