Skip to content

Commit aa66369

Browse files
authored
Merge pull request Expensify#72838 from software-mansion-labs/@Skalakid/refactor/useonyx-deprecate-onyx-connect/getRecentWaypoints-src-libs-actions-Transaction.ts
refactor: remove getRecentWaypoints from Transaction.ts
2 parents 6287c3d + bd38d21 commit aa66369

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from './Policy
262262
import type {GuidedSetupData} from './Report';
263263
import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from './Report';
264264
import {clearAllRelatedReportActionErrors} from './ReportActions';
265-
import {getRecentWaypoints, sanitizeRecentWaypoints} from './Transaction';
265+
import {sanitizeRecentWaypoints} from './Transaction';
266266
import {removeDraftSplitTransaction, removeDraftTransaction, removeDraftTransactions} from './TransactionEdit';
267267
import {getOnboardingMessages} from './Welcome/OnboardingFlow';
268268

@@ -943,6 +943,15 @@ Onyx.connectWithoutView({
943943
callback: (value) => (recentAttendees = value),
944944
});
945945

946+
// TODO: remove `recentWaypoints` from this file (https://github.com/Expensify/App/issues/73024)
947+
// `recentWaypoints` was moved here temporarily from `src/libs/actions/Policy/Tag.ts` during the `Deprecate Onyx.connect` refactor.
948+
// All uses of this variable should be replaced with `useOnyx`.
949+
let recentWaypoints: OnyxTypes.RecentWaypoint[] = [];
950+
Onyx.connect({
951+
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,
952+
callback: (val) => (recentWaypoints = val ?? []),
953+
});
954+
946955
/**
947956
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
948957
* All usages of this function should be replaced with useOnyx hook in React components.
@@ -5162,7 +5171,7 @@ function updateMoneyRequestDistance({
51625171
const {params, onyxData} = data;
51635172

51645173
if (!distance) {
5165-
const recentServerValidatedWaypoints = getRecentWaypoints().filter((item) => !item.pendingAction);
5174+
const recentServerValidatedWaypoints = recentWaypoints.filter((item) => !item.pendingAction);
51665175
onyxData?.failureData?.push({
51675176
onyxMethod: Onyx.METHOD.SET,
51685177
key: `${ONYXKEYS.NVP_RECENT_WAYPOINTS}`,
@@ -6400,7 +6409,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
64006409
}) ?? {};
64016410
const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport?.reportID;
64026411

6403-
const recentServerValidatedWaypoints = getRecentWaypoints().filter((item) => !item.pendingAction);
6412+
const recentServerValidatedWaypoints = recentWaypoints.filter((item) => !item.pendingAction);
64046413
onyxData?.failureData?.push({
64056414
onyxMethod: Onyx.METHOD.SET,
64066415
key: `${ONYXKEYS.NVP_RECENT_WAYPOINTS}`,
@@ -8127,7 +8136,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
81278136
};
81288137
}
81298138

8130-
const recentServerValidatedWaypoints = getRecentWaypoints().filter((item) => !item.pendingAction);
8139+
const recentServerValidatedWaypoints = recentWaypoints.filter((item) => !item.pendingAction);
81318140
onyxData?.failureData?.push({
81328141
onyxMethod: Onyx.METHOD.SET,
81338142
key: `${ONYXKEYS.NVP_RECENT_WAYPOINTS}`,

src/libs/actions/Transaction.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ import type {WaypointCollection} from '@src/types/onyx/Transaction';
5050
import type TransactionState from '@src/types/utils/TransactionStateType';
5151
import {getPolicyTagsData} from './Policy/Tag';
5252

53-
let recentWaypoints: RecentWaypoint[] = [];
54-
Onyx.connect({
55-
key: ONYXKEYS.NVP_RECENT_WAYPOINTS,
56-
callback: (val) => (recentWaypoints = val ?? []),
57-
});
58-
5953
const allTransactions: Record<string, Transaction> = {};
6054
Onyx.connect({
6155
key: ONYXKEYS.COLLECTION.TRANSACTION,
@@ -634,10 +628,6 @@ function openDraftDistanceExpense() {
634628
API.read(READ_COMMANDS.OPEN_DRAFT_DISTANCE_EXPENSE, null, onyxData);
635629
}
636630

637-
function getRecentWaypoints() {
638-
return recentWaypoints;
639-
}
640-
641631
/**
642632
* Returns a client generated 16 character hexadecimal value for the transactionID
643633
*/
@@ -1302,7 +1292,6 @@ export {
13021292
setReviewDuplicatesKey,
13031293
abandonReviewDuplicateTransactions,
13041294
openDraftDistanceExpense,
1305-
getRecentWaypoints,
13061295
sanitizeRecentWaypoints,
13071296
getLastModifiedExpense,
13081297
revert,

0 commit comments

Comments
 (0)