Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fd4fed5
feat: add tests for createExpenseByType, createTransaction, handleMon…
jakubstec May 13, 2026
841f637
fix: typecheck, prettier, lint
jakubstec May 13, 2026
cf49248
feat: move participantsPolicyTags one level up to useExpenseSubmissio…
jakubstec May 13, 2026
895eaaa
fix: tests
jakubstec May 13, 2026
b5c1480
Merge remote-tracking branch 'origin/main' into jakubstec/remove-onyx…
jakubstec Jul 8, 2026
acac84c
refactor: remove dead code, update tests, move participantsPolicyTags…
jakubstec Jul 8, 2026
5adf906
fix: simplify tests, fix eslint
jakubstec Jul 8, 2026
733ccfb
Merge remote-tracking branch 'origin/main' into jakubstec/remove-onyx…
jakubstec Jul 9, 2026
062800f
refactor: seperate a new type for participant policy tags
jakubstec Jul 10, 2026
51a2543
Merge remote-tracking branch 'origin/main' into jakubstec/remove-onyx…
jakubstec Jul 10, 2026
8f20744
fix: typecheck in tests
jakubstec Jul 10, 2026
d6659b2
Merge remote-tracking branch 'upstream/main' into jakubstec/remove-on…
jakubstec Jul 16, 2026
7b3fdd2
fix: apply review changes, add proper comments
jakubstec Jul 16, 2026
5b79f91
fix: tests
jakubstec Jul 16, 2026
1d4b92b
fix: remove dependency array from useOnyx hook
jakubstec Jul 17, 2026
e5fc4ed
Merge remote-tracking branch 'origin/main' into jakubstec/remove-onyx…
jakubstec Jul 21, 2026
3902325
Merge remote-tracking branch 'origin/main' into jakubstec/remove-onyx…
jakubstec Jul 22, 2026
1ea5ded
Merge remote-tracking branch 'upstream/main' into jakubstec/remove-on…
jakubstec Jul 22, 2026
30e26b2
fix: typecheck
jakubstec Jul 23, 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
10 changes: 5 additions & 5 deletions src/hooks/useParticipantsPolicyTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTagLists} from '@src/types/onyx';
import type {ParticipantsPolicyTags, PolicyTagLists} from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';

import type {OnyxCollection} from 'react-native-onyx';
Expand All @@ -10,12 +10,12 @@ type ParticipantWithPolicyID = {
policyID?: string;
};

function getPolicyTagsSelector(participants: ParticipantWithPolicyID[]): (allTags: OnyxCollection<PolicyTagLists>) => Record<string, PolicyTagLists> {
function getPolicyTagsSelector(participants: ParticipantWithPolicyID[]): (allTags: OnyxCollection<PolicyTagLists>) => ParticipantsPolicyTags {
return (allTags: OnyxCollection<PolicyTagLists>) => {
if (!participants) {
return {};
}
return participants.reduce<Record<string, PolicyTagLists>>((acc, participant) => {
return participants.reduce<ParticipantsPolicyTags>((acc, participant) => {
const key = `${ONYXKEYS.COLLECTION.POLICY_TAGS}${participant.policyID}`;
if (allTags?.[key] && participant.policyID) {
acc[participant.policyID] = allTags[key];
Expand All @@ -31,8 +31,8 @@ function getPolicyTagsSelector(participants: ParticipantWithPolicyID[]): (allTag
* @param participants - Array of participants with optional policyID
* @returns Record mapping policyID to PolicyTagLists
*/
function useParticipantsPolicyTags(participants: ParticipantWithPolicyID[]): Record<string, PolicyTagLists> {
const [participantsPolicyTags = getEmptyObject<Record<string, PolicyTagLists>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: getPolicyTagsSelector(participants)});
function useParticipantsPolicyTags(participants: ParticipantWithPolicyID[]): ParticipantsPolicyTags {
const [participantsPolicyTags = getEmptyObject<ParticipantsPolicyTags>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {selector: getPolicyTagsSelector(participants)});

return participantsPolicyTags;
}
Expand Down
7 changes: 5 additions & 2 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import type {PerDiemExpenseInformation} from './PerDiem';
import type {CreateDistanceRequestInformation} from './Split';
import type {CreateTrackExpenseParams} from './TrackExpense';

import {getAllReportActionsFromIOU, getAllReports, getAllTransactions} from '.';
import {buildParticipantsPolicyTags, getAllReportActionsFromIOU, getAllReports, getAllTransactions} from '.';
import {getCleanUpTransactionThreadReportOnyxData} from './DeleteMoneyRequest';
import {getMoneyRequestParticipantsFromReport} from './MoneyRequest';
import {submitPerDiemExpense} from './PerDiem';
Expand Down Expand Up @@ -704,6 +704,9 @@ function createExpenseByType({
personalDetails,
recentWaypoints,
formatPhoneNumber,
// buildParticipantsPolicyTags is deprecated but still needed here until this call site is migrated to useOnyx (https://github.com/Expensify/App/issues/72721)
// eslint-disable-next-line @typescript-eslint/no-deprecated
participantsPolicyTags: buildParticipantsPolicyTags(participants),
};
return createDistanceRequest(distanceParams);
}
Expand Down Expand Up @@ -1376,5 +1379,5 @@ function bulkDuplicateReports({
playSound(SOUNDS.DONE);
}

export {getIOUActionForTransactions, mergeDuplicates, resolveDuplicates, duplicateExpenseTransaction, bulkDuplicateExpenses, duplicateReport, bulkDuplicateReports};
export {getIOUActionForTransactions, mergeDuplicates, resolveDuplicates, duplicateExpenseTransaction, bulkDuplicateExpenses, duplicateReport, bulkDuplicateReports, createExpenseByType};
export type {DuplicateReportParams, BulkDuplicateReportsParams};
20 changes: 11 additions & 9 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import type {BuildOnyxDataForMoneyRequestKeys, OneOnOneIOUReport} from './MoneyR
import type BasePolicyParams from './types/BasePolicyParams';
import type BaseTransactionParams from './types/BaseTransactionParams';

import {buildParticipantsPolicyTags, getAllPersonalDetails, getAllReports, getAllTransactionDrafts, getAllTransactions} from './index';
import {getAllPersonalDetails, getAllReports, getAllTransactionDrafts, getAllTransactions} from './index';
import {
buildMinimalTransactionForFormula,
buildOnyxDataForMoneyRequest,
Expand Down Expand Up @@ -145,6 +145,7 @@ type CreateDistanceRequestInformation = {
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags;

/** Optimistic chat reportID to build the new chat report at, so it matches the ID the confirmation screen already subscribed to (brand-new P2P recipient). */
optimisticChatReportID?: string;
Expand All @@ -170,7 +171,7 @@ type CreateSplitsAndOnyxDataParams = {
policyRecentlyUsedCurrencies: string[];
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags;
delegateAccountID: number | undefined;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
Expand Down Expand Up @@ -198,7 +199,7 @@ type StartSplitBilActionParams = {
policyRecentlyUsedTags: OnyxEntry<RecentlyUsedTags>;
quickAction: OnyxEntry<OnyxTypes.QuickAction>;
policyRecentlyUsedCurrencies: string[];
participantsPolicyTags: Record<string, OnyxTypes.PolicyTagLists>;
participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags;
delegateAccountID: number | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};
Expand Down Expand Up @@ -250,6 +251,7 @@ type SplitBillActionsParams = {
shouldHandleNavigation?: boolean;
shouldDeferForSearch?: boolean;
delegateAccountID: number | undefined;
participantsPolicyTags: OnyxTypes.ParticipantsPolicyTags;
isTrackIntentUser: boolean | undefined;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
};
Expand Down Expand Up @@ -290,6 +292,7 @@ function splitBill({
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
}: SplitBillActionsParams) {
const parsedComment = getParsedComment(comment);
const {splitData, splits, onyxData} = createSplitsAndOnyxData({
Expand Down Expand Up @@ -321,8 +324,7 @@ function splitBill({
policyRecentlyUsedCurrencies,
betas,
personalDetails,
// eslint-disable-next-line @typescript-eslint/no-deprecated
participantsPolicyTags: buildParticipantsPolicyTags(participants),
participantsPolicyTags,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
Expand Down Expand Up @@ -406,6 +408,7 @@ function splitBillAndOpenReport({
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
}: SplitBillActionsParams) {
const parsedComment = getParsedComment(comment);
const {splitData, splits, onyxData} = createSplitsAndOnyxData({
Expand Down Expand Up @@ -437,11 +440,10 @@ function splitBillAndOpenReport({
policyRecentlyUsedCurrencies,
betas,
personalDetails,
// eslint-disable-next-line @typescript-eslint/no-deprecated
participantsPolicyTags: buildParticipantsPolicyTags(participants),
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
});

const parameters: SplitBillParams = {
Expand Down Expand Up @@ -1975,6 +1977,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
optimisticChatReportID,
} = distanceRequestInformation;
const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams;
Expand Down Expand Up @@ -2064,8 +2067,7 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest
policyRecentlyUsedCurrencies,
betas,
personalDetails,
// eslint-disable-next-line @typescript-eslint/no-deprecated
participantsPolicyTags: buildParticipantsPolicyTags(participants),
participantsPolicyTags,
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ function getPolicyTags(): OnyxCollection<OnyxTypes.PolicyTagLists> {
* TODO: remove `buildParticipantsPolicyTags` from this file (https://github.com/Expensify/App/issues/72721)
* All usages of this function should be replaced with params passed to the functions or useOnyx hook in React components.
*/
function buildParticipantsPolicyTags(participants: Participant[]): Record<string, OnyxTypes.PolicyTagLists> {
return participants.reduce<Record<string, OnyxTypes.PolicyTagLists>>((acc, participant) => {
function buildParticipantsPolicyTags(participants: Participant[]): OnyxTypes.ParticipantsPolicyTags {
return participants.reduce<OnyxTypes.ParticipantsPolicyTags>((acc, participant) => {
if (participant.policyID) {
const tags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${participant.policyID}`];
if (tags) {
Expand Down Expand Up @@ -241,6 +241,7 @@ export {
getRecentAttendees,
getAllSnapshots,
getSearchQueryByHash,
// TODO: Replace buildParticipantsPolicyTags (https://github.com/Expensify/App/issues/72721) with useOnyx hook
Comment thread
jakubstec marked this conversation as resolved.
Resolved
// eslint-disable-next-line @typescript-eslint/no-deprecated
buildParticipantsPolicyTags,
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {LocaleContextProps} from '@components/LocaleContextProvider';

import {buildParticipantsPolicyTags} from '@libs/actions/IOU';
import {
getMoneyRequestParticipantOptions,
setCustomUnitRateID,
Expand Down Expand Up @@ -409,6 +410,9 @@ function handleMoneyRequestStepDistanceNavigation({
isTrackIntentUser,
delegateAccountID,
formatPhoneNumber,
// buildParticipantsPolicyTags is deprecated but still needed here until this call site is migrated to useOnyx (https://github.com/Expensify/App/issues/72721)
// eslint-disable-next-line @typescript-eslint/no-deprecated
participantsPolicyTags: buildParticipantsPolicyTags(participants),
});
cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, {
report,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
isTrackIntentUser,
delegateAccountID,
formatPhoneNumber,
participantsPolicyTags,
});

const isExpenseReport = isMoneyRequestReportReportUtils(report);
Expand Down Expand Up @@ -967,6 +968,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
});
}
markSubmitExpenseEnd();
Expand Down Expand Up @@ -1007,6 +1009,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
delegateAccountID,
isTrackIntentUser,
formatPhoneNumber,
participantsPolicyTags,
});
}
markSubmitExpenseEnd();
Expand Down
5 changes: 4 additions & 1 deletion src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ type PolicyTagList = {
/** Record of policy tag lists, index by the name of the tag list */
type PolicyTagLists = Record<string, OnyxCommon.OnyxValueWithOfflineFeedback<PolicyTagList>>;

export type {PolicyTag, PolicyTags, PolicyTagLists};
/** Record of policy tag lists, indexed by policyID */
type ParticipantsPolicyTags = Record<string, PolicyTagLists>;

export type {PolicyTag, PolicyTags, PolicyTagLists, ParticipantsPolicyTags};
3 changes: 2 additions & 1 deletion src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import type {PolicyEmployeeList} from './PolicyEmployee';
import type PolicyEmployee from './PolicyEmployee';
import type PolicyJoinMember from './PolicyJoinMember';
import type PolicyOwnershipChangeChecks from './PolicyOwnershipChangeChecks';
import type {PolicyTag, PolicyTagLists, PolicyTags} from './PolicyTag';
import type {ParticipantsPolicyTags, PolicyTag, PolicyTagLists, PolicyTags} from './PolicyTag';
import type PrivatePersonalDetails from './PrivatePersonalDetails';
import type PrivatePromoDiscount from './PrivatePromoDiscount';
import type PrivateSubscription from './PrivateSubscription';
Expand Down Expand Up @@ -300,6 +300,7 @@ export type {
PolicyTag,
PolicyTags,
PolicyTagLists,
ParticipantsPolicyTags,
PrivatePersonalDetails,
QuickAction,
ShareBankAccount,
Expand Down
Loading
Loading