Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
17917f8
refactor: move getPolicyTagsData to IOU and Transaction files
Skalakid Oct 15, 2025
b08a9a5
fix: move Onyx.connect temporarily to TransactionUtils
Skalakid Oct 15, 2025
d293bdf
fix: update link to the issues in TODO comments in Transaction.ts
Skalakid Oct 15, 2025
b2fae7c
fix: remove getPolicyTagsData export
Skalakid Oct 15, 2025
5978bbf
refactor: update issue urls
Skalakid Oct 16, 2025
c676eea
Merge branch 'main' into @Skalakid/refactor/useonyx-deprecate-onyx-co…
Skalakid Oct 23, 2025
0efdb55
fix: fix eslint errors
Skalakid Oct 23, 2025
4a0f467
Merge branch 'main' into @Skalakid/refactor/useonyx-deprecate-onyx-co…
Skalakid Oct 24, 2025
36619a9
Merge branch 'main' into @Skalakid/refactor/useonyx-deprecate-onyx-co…
Skalakid Oct 27, 2025
6ae91eb
Merge branch 'main' into @Skalakid/refactor/useonyx-deprecate-onyx-co…
dariusz-biela Nov 18, 2025
bdf606c
feat: removes Onyx.connect for ONYXKEYS.COLLECTION.POLICY_TAGS in src…
dariusz-biela Nov 18, 2025
f2b062d
fix: removes unused import
dariusz-biela Nov 18, 2025
113db07
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 16, 2026
a95a1b0
dont push mobile exp
Guccio163 Jan 16, 2026
0187e5d
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 16, 2026
7a690ab
fix merge
Guccio163 Jan 17, 2026
7b439fe
adding allPolicyTags Onyx.connect to necessary files
Guccio163 Jan 17, 2026
7ef57db
fixing comments about deprecation
Guccio163 Jan 17, 2026
348fbab
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 19, 2026
7289d0b
Apply suggestion from @dariusz-biela
Guccio163 Jan 20, 2026
e5ccebe
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 20, 2026
8d4bf20
update issues links
Guccio163 Jan 20, 2026
dcae657
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 20, 2026
ad33d41
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 21, 2026
a3319bd
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 22, 2026
238dc4f
add no-deprecated annotations
Guccio163 Jan 22, 2026
bfc5b63
update max-warnings
Guccio163 Jan 22, 2026
32e5f0e
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 22, 2026
9ca99c7
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 22, 2026
73d245b
Mobile
Guccio163 Jan 22, 2026
4298e80
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 22, 2026
6e70379
migrating also to Split.ts
Guccio163 Jan 22, 2026
13d34d8
prettier
Guccio163 Jan 22, 2026
766ea1b
Split issue update
Guccio163 Jan 24, 2026
96d6826
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 24, 2026
2f63889
update Mobile
Guccio163 Jan 24, 2026
0952df6
Merge branch '@Skalakid/refactor/useonyx-deprecate-onyx-connect/getPo…
Guccio163 Jan 24, 2026
21e3cae
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 24, 2026
89a384a
bump max-warnings
Guccio163 Jan 24, 2026
0a7b0be
use getPolicyTags from IOU/index.ts
Guccio163 Jan 26, 2026
c544d6e
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 26, 2026
94c2272
fix TODO comments
Guccio163 Jan 26, 2026
5df43b7
fix imports
Guccio163 Jan 26, 2026
d0ac3a2
bring back Onyx.connect to TransactionUtils to fix tests
Guccio163 Jan 26, 2026
debca04
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 Jan 26, 2026
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
26 changes: 25 additions & 1 deletion src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import utils from '@components/MapView/utils';
import type {UnreportedExpenseListItemType} from '@components/SelectionListWithSections/types';
import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow';
import {getPolicyTagsData} from '@libs/actions/Policy/Tag';
import type {MergeDuplicatesParams} from '@libs/API/parameters';
import {getCategoryDefaultTaxRate, isCategoryMissing} from '@libs/CategoryUtils';
import {convertToBackendAmount, getCurrencyDecimals, getCurrencySymbol} from '@libs/CurrencyUtils';
Expand Down Expand Up @@ -60,6 +59,7 @@
OnyxInputOrEntry,
Policy,
PolicyCategories,
PolicyTagLists,
RecentWaypoint,
Report,
ReviewDuplicates,
Expand Down Expand Up @@ -139,6 +139,28 @@
callback: (value) => (allBetas = value),
});

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

Check warning on line 143 in src/libs/TransactionUtils/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) => {
if (!value) {
allPolicyTags = {};
return;
}
allPolicyTags = value;
},
});

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file (https://github.com/Expensify/App/issues/72719)
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

function hasDistanceCustomUnit(transaction: OnyxEntry<Transaction> | Partial<Transaction>): boolean {
const type = transaction?.comment?.type;
const customUnitName = transaction?.comment?.customUnit?.name;
Expand Down Expand Up @@ -2453,6 +2475,8 @@
keep[fieldName] = firstTransaction?.[keys[0]] ?? firstTransaction?.[keys[1]];
}
} else if (fieldName === 'tag') {
// TODO: Replace getPolicyTagsData with useOnyx hook (https://github.com/Expensify/App/issues/72719)
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTags = report?.policyID ? getPolicyTagsData(report?.policyID) : {};
const isMultiLevelTags = isMultiLevelTagsPolicyUtils(policyTags);
if (isMultiLevelTags) {
Expand Down
14 changes: 13 additions & 1 deletion src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getTransactionDetails,
} from '@libs/ReportUtils';
import {getRequestType, getTransactionType} from '@libs/TransactionUtils';
import {getPolicyTagsData} from '@userActions/Policy/Tag';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
Expand All @@ -34,11 +33,22 @@ import {
getAllTransactionViolations,
getCurrentUserEmail,
getMoneyRequestParticipantsFromReport,
getPolicyTags,
getUserAccountID,
requestMoney,
trackExpense,
} from '.';

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file https://github.com/Expensify/App/issues/80049
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
const allPolicyTags = getPolicyTags();
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

function getIOUActionForTransactions(transactionIDList: Array<string | undefined>, iouReportID: string | undefined): Array<OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> {
const allReportActions = getAllReportActionsFromIOU();
return Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`] ?? {})?.filter(
Expand Down Expand Up @@ -559,6 +569,8 @@ function duplicateExpenseTransaction({

params.policyParams = {
policy: targetPolicy,
// TODO: remove `allPolicyTags` from this file https://github.com/Expensify/App/issues/80049
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTagList: getPolicyTagsData(targetPolicy.id) ?? {},
policyCategories: targetPolicyCategories ?? {},
};
Expand Down
16 changes: 14 additions & 2 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {buildOptimisticTransaction} from '@libs/TransactionUtils';
import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '@userActions/Policy/Tag';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import {notifyNewAction} from '@userActions/Report';
import {removeDraftTransaction} from '@userActions/TransactionEdit';
import CONST from '@src/CONST';
Expand All @@ -34,7 +34,7 @@ import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'
import type {OnyxData} from '@src/types/onyx/Request';
import type {Receipt} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {getAllPersonalDetails, getReceiptError, getSearchOnyxUpdate, mergePolicyRecentlyUsedCategories, mergePolicyRecentlyUsedCurrencies} from '.';
import {getAllPersonalDetails, getPolicyTags, getReceiptError, getSearchOnyxUpdate, mergePolicyRecentlyUsedCategories, mergePolicyRecentlyUsedCurrencies} from '.';
import type {BasePolicyParams} from '.';

type SendInvoiceInformation = {
Expand Down Expand Up @@ -108,6 +108,16 @@ type BuildOnyxDataForInvoiceParams = {
participant?: Participant;
};

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file https://github.com/Expensify/App/issues/80048
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
const allPolicyTags = getPolicyTags();
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

/** Builds the Onyx data for an invoice */
function buildOnyxDataForInvoice(
invoiceParams: BuildOnyxDataForInvoiceParams,
Expand Down Expand Up @@ -635,6 +645,8 @@ function getSendInvoiceInformation({

const optimisticPolicyRecentlyUsedCategories = mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories);
const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
// TODO: remove `allPolicyTags` from this file https://github.com/Expensify/App/issues/80048
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(optimisticInvoiceReport.policyID),
policyRecentlyUsedTags,
transactionTags: tag,
Expand Down
18 changes: 16 additions & 2 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {buildOptimisticTransaction, getChildTransactions, isOnHold, isPerDiemRequest as isPerDiemRequestTransactionUtils} from '@libs/TransactionUtils';
import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '@userActions/Policy/Tag';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import {notifyNewAction} from '@userActions/Report';
import {removeDraftSplitTransaction, removeDraftTransaction} from '@userActions/TransactionEdit';
import CONST from '@src/CONST';
Expand All @@ -65,6 +65,7 @@ import {
getMoneyRequestInformation,
getMoneyRequestParticipantsFromReport,
getOrCreateOptimisticSplitChatReport,
getPolicyTags,
getReceiptError,
getReportPreviewAction,
getUpdateMoneyRequestParams,
Expand Down Expand Up @@ -304,6 +305,16 @@ function splitBillAndOpenReport({
notifyNewAction(splitData.chatReportID, currentUserAccountID);
}

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file [https://github.com/Expensify/App/issues/80401]
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
const allPolicyTags = getPolicyTags();
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

/** Used exclusively for starting a split expense request that contains a receipt, the split request will be completed once the receipt is scanned
* or user enters details manually.
*
Expand Down Expand Up @@ -592,6 +603,8 @@ function startSplitBill({
}
const optimisticPolicyRecentlyUsedCategories = mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories);
const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
// TODO: remove `allPolicyTags` from this file [https://github.com/Expensify/App/issues/80401]
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(participant.policyID),
policyRecentlyUsedTags,
transactionTags: tag,
Expand Down Expand Up @@ -996,7 +1009,8 @@ function updateSplitTransactions({
const originalTransactionID = transactionData?.originalTransactionID ?? CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
const originalTransaction = allTransactionsList?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`];
const originalTransactionDetails = getTransactionDetails(originalTransaction);

// TODO: remove `allPolicyTags` from this file [https://github.com/Expensify/App/issues/80401]
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTags = getPolicyTagsData(expenseReport?.policyID);
const participants = getMoneyRequestParticipantsFromReport(expenseReport, currentUserPersonalDetails.accountID);
const splitExpenses = transactionData?.splitExpenses ?? [];
Expand Down
41 changes: 40 additions & 1 deletion src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
import {clearByKey as clearPdfByOnyxKey} from '@userActions/CachedPDFPaths';
import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from '@userActions/Policy/Member';
import {buildPolicyData, generatePolicyID} from '@userActions/Policy/Policy';
import {buildOptimisticPolicyRecentlyUsedTags, getPolicyTagsData} from '@userActions/Policy/Tag';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import type {GuidedSetupData} from '@userActions/Report';
import {buildInviteToRoomOnyxData, completeOnboarding, getCurrentUserAccountID, notifyNewAction, optimisticReportLastData} from '@userActions/Report';
import {clearAllRelatedReportActionErrors} from '@userActions/ReportActions';
Expand Down Expand Up @@ -759,7 +759,7 @@
};

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

Check warning on line 762 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 @@ -837,7 +837,7 @@
};

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

Check warning on line 840 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 @@ -851,7 +851,7 @@
});

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

Check warning on line 854 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 @@ -860,7 +860,7 @@
});

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

Check warning on line 863 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 @@ -873,8 +873,21 @@
},
});

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

Check warning on line 877 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
Comment thread
Guccio163 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tgolen Create one issue for this too and assign me there.

@Guccio163 Guccio163 Jan 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'll be resolved in #72721

key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
allPolicyTags = {};
return;
}
allPolicyTags = value;
},
});

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

Check warning on line 890 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 @@ -883,7 +896,7 @@
});

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

Check warning on line 899 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 @@ -893,7 +906,7 @@

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

Check warning on line 909 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 @@ -902,7 +915,7 @@
});

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

Check warning on line 918 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 @@ -971,6 +984,19 @@
return userAccountID;
}

function getPolicyTags(): OnyxCollection<OnyxTypes.PolicyTagLists> {
return allPolicyTags;
}

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file (https://github.com/Expensify/App/issues/72721)
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

/**
* @private
* After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report.
Expand Down Expand Up @@ -3209,6 +3235,8 @@

const optimisticPolicyRecentlyUsedCategories = mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories);
const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(iouReport.policyID),
policyRecentlyUsedTags,
transactionTags: tag,
Expand Down Expand Up @@ -3562,6 +3590,8 @@
optimisticTransaction.hasEReceipt = true;
const optimisticPolicyRecentlyUsedCategories = mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories);
const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(iouReport.policyID),
policyRecentlyUsedTags,
transactionTags: tag,
Expand Down Expand Up @@ -4399,6 +4429,8 @@
const hasModifiedTag = 'tag' in transactionChanges;
if (hasModifiedTag) {
const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(iouReport?.policyID),
policyRecentlyUsedTags,
transactionTags: transactionChanges.tag,
Expand Down Expand Up @@ -7303,6 +7335,8 @@
// Add tag to optimistic policy recently used tags when a participant is a workspace
const optimisticPolicyRecentlyUsedTags = isPolicyExpenseChat
? buildOptimisticPolicyRecentlyUsedTags({
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
policyTags: getPolicyTagsData(participant.policyID),
policyRecentlyUsedTags,
transactionTags: tag,
Expand Down Expand Up @@ -11005,6 +11039,8 @@
];

if (transactionPolicy && isPaidGroupPolicy(transactionPolicy) && newTransaction) {
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTagList = getPolicyTagsData(transactionPolicy.id);
const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? [];
const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
Expand Down Expand Up @@ -11130,6 +11166,8 @@
];

if (transactionPolicy && isPaidGroupPolicy(transactionPolicy) && newTransaction) {
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTagList = getPolicyTagsData(transactionPolicy.id);
const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? [];
const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
Expand Down Expand Up @@ -13136,6 +13174,7 @@
getUserAccountID,
getReceiptError,
getSearchOnyxUpdate,
getPolicyTags,
setMoneyRequestTimeRate,
setMoneyRequestTimeCount,
buildMinimalTransactionForFormula,
Expand Down
21 changes: 1 addition & 20 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodashCloneDeep from 'lodash/cloneDeep';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import type PolicyData from '@hooks/usePolicyData/types';
Expand Down Expand Up @@ -44,20 +44,6 @@ function isTaskIncomplete(taskReport: OnyxEntry<Report>): boolean {
return !!taskReport && (taskReport.stateNum !== CONST.REPORT.STATE_NUM.APPROVED || taskReport.statusNum !== CONST.REPORT.STATUS_NUM.APPROVED);
}

let allPolicyTags: OnyxCollection<PolicyTagLists> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
allPolicyTags = {};
return;
}

allPolicyTags = value;
},
});

function openPolicyTagsPage(policyID: string) {
if (!policyID) {
Log.warn('openPolicyTagsPage invalid params', {policyID});
Expand Down Expand Up @@ -1289,10 +1275,6 @@ function downloadMultiLevelTagsCSV(policyID: string, onDownloadFailed: () => voi
fileDownload(translate, ApiUtils.getCommandURL({command}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

function getPolicyTagsData(policyID: string | undefined) {
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

export {
buildOptimisticPolicyRecentlyUsedTags,
setPolicyRequiresTag,
Expand All @@ -1312,7 +1294,6 @@ export {
setPolicyTagApprover,
importPolicyTags,
downloadTagsCSV,
getPolicyTagsData,
downloadMultiLevelTagsCSV,
cleanPolicyTags,
setImportedSpreadsheetIsImportingMultiLevelTags,
Expand Down
14 changes: 13 additions & 1 deletion src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import type {OriginalMessageIOU, OriginalMessageModifiedExpense} from '@src/type
import type {OnyxData} from '@src/types/onyx/Request';
import type {Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import type TransactionState from '@src/types/utils/TransactionStateType';
import {getPolicyTagsData} from './Policy/Tag';
import {getPolicyTags} from './IOU/index';

let allTransactionDrafts: OnyxCollection<Transaction> = {};
Onyx.connect({
Expand Down Expand Up @@ -95,6 +95,16 @@ Onyx.connect({
callback: (val) => (allTransactionViolations = val ?? []),
});

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getPolicyTagsData` from this file (https://github.com/Expensify/App/issues/72720)
* All usages of this function should be replaced with useOnyx hook in React components.
*/
function getPolicyTagsData(policyID: string | undefined) {
const allPolicyTags = getPolicyTags();
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

// Helper to safely check for a string 'name' property
function isViolationWithName(violation: unknown): violation is {name: string} {
return !!(violation && typeof violation === 'object' && typeof (violation as {name?: unknown}).name === 'string');
Expand Down Expand Up @@ -888,6 +898,8 @@ function changeTransactionsReport({
let transactionsMoved = false;
let shouldFixViolations = false;

// TODO: Replace getPolicyTagsData with useOnyx hook (https://github.com/Expensify/App/issues/72720)
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTagList = getPolicyTagsData(policy?.id);
const policyHasDependentTags = hasDependentTags(policy, policyTagList);

Expand Down
Loading