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
3 changes: 1 addition & 2 deletions src/hooks/useMoneyRequestPolicyTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type UseMoneyRequestPolicyTagsParams = {
const selectReportPolicyID = (report: OnyxEntry<Report>) => report?.policyID;

/**
* Resolves the `PolicyTagLists` for the money-request flow — a reactive replacement for the deprecated
* `getMoneyRequestPolicyTags`, picking the policy from the IOU/money-request/chat/participant reports in order.
* Resolves the `PolicyTagLists` for the money-request flow, picking the policy from the IOU/money-request/chat/participant reports in order.
*
* Case-specific: it mirrors how these flows resolve their policy, not a general-purpose hook.
*/
Expand Down
25 changes: 2 additions & 23 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
canAddTransaction,
generateReportID,
getReimbursableTotal,
getReportOrDraftReport,
getTransactionDetails,
isMoneyRequestReport as isMoneyRequestReportReportUtils,
} from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {
Expand Down Expand Up @@ -61,7 +59,7 @@ import type {PerDiemExpenseInformation} from './PerDiem';
import type {CreateDistanceRequestInformation} from './Split';
import type {CreateTrackExpenseParams} from './TrackExpense';

import {getAllReportActionsFromIOU, getAllReports, getAllTransactions, getMoneyRequestPolicyTags} from '.';
import {getAllReportActionsFromIOU, getAllReports, getAllTransactions} from '.';
import {getCleanUpTransactionThreadReportOnyxData} from './DeleteMoneyRequest';
import {getMoneyRequestParticipantsFromReport} from './MoneyRequest';
import {submitPerDiemExpense} from './PerDiem';
Expand Down Expand Up @@ -654,7 +652,6 @@ function createExpenseByType({
personalDetails,
recentWaypoints,
isTrackIntentUser,
policyTagList,
}: {
transactionType: string;
params: RequestMoneyInformation;
Expand All @@ -668,7 +665,6 @@ function createExpenseByType({
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
isTrackIntentUser: boolean | undefined;
policyTagList: OnyxTypes.PolicyTagLists;
}) {
switch (transactionType) {
case CONST.SEARCH.TRANSACTION_TYPE.DISTANCE: {
Expand All @@ -677,7 +673,6 @@ function createExpenseByType({
participants,
currentUserLogin: params.currentUserEmailParam,
currentUserAccountID: params.currentUserAccountIDParam,
policyParams: {...params.policyParams, policyTagList},
existingTransaction: {
iouRequestType: getDuplicateRequestType(transaction),
amount: 0,
Expand Down Expand Up @@ -726,7 +721,6 @@ function createExpenseByType({
default:
return requestMoney({
...params,
policyParams: {...(params.policyParams ?? {}), policyTagList},
});
}
}
Expand Down Expand Up @@ -777,7 +771,6 @@ function duplicateExpenseTransaction({
betas,
personalDetails,
recentWaypoints,
targetPolicyTags,
shouldPlaySound = true,
shouldDeferAutoSubmit = false,
existingIOUReport,
Expand Down Expand Up @@ -883,7 +876,7 @@ function duplicateExpenseTransaction({

params.policyParams = {
policy: targetPolicy,
policyTagList: targetPolicyTags,
policyTagList,
policyCategories: targetPolicyCategories ?? {},
};

Expand All @@ -900,7 +893,6 @@ function duplicateExpenseTransaction({
personalDetails,
recentWaypoints,
isTrackIntentUser,
policyTagList,
});
}

Expand Down Expand Up @@ -1056,18 +1048,6 @@ function duplicateReport({
delegateAccountID,
};

const isMoneyRequestReport = isMoneyRequestReportReportUtils(params.report);
const currentChatReport = isMoneyRequestReport ? getReportOrDraftReport(params.report?.chatReportID) : params.report;
const moneyRequestReportID = isMoneyRequestReport ? params.report?.reportID : '';
// Part of the onyx.connect migration, it will be removed in further PRs (https://github.com/Expensify/App/issues/72721).
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyTagList = getMoneyRequestPolicyTags({
existingIOUReport: params.existingIOUReport,
moneyRequestReportID,
parentChatReport: currentChatReport,
participant: participants.at(0) ?? {},
});

const result = createExpenseByType({
transactionType: getTransactionType(transaction),
params,
Expand All @@ -1081,7 +1061,6 @@ function duplicateReport({
personalDetails,
recentWaypoints,
isTrackIntentUser,
policyTagList,
});

if (result?.iouReport) {
Expand Down
25 changes: 0 additions & 25 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,6 @@ function getPolicyTagsData(policyID: string | undefined) {
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}

/**
* @deprecated This function uses Onyx.connect and should be replaced with useOnyx for reactive data access.
* TODO: remove `getMoneyRequestPolicyTags` 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 getMoneyRequestPolicyTags({
existingIOUReport,
moneyRequestReportID,
parentChatReport,
participant,
}: {
existingIOUReport?: OnyxEntry<OnyxTypes.Report>;
moneyRequestReportID?: string;
parentChatReport: OnyxEntry<OnyxTypes.Report>;
participant: Participant;
}): OnyxTypes.PolicyTagLists {
const iouReportPolicyID =
existingIOUReport?.policyID ??
(moneyRequestReportID ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`]?.policyID : undefined) ??
parentChatReport?.policyID ??
allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${participant.reportID}`]?.policyID;
return getPolicyTagsData(iouReportPolicyID) ?? {};
}

export {
getAllPersonalDetails,
getAllTransactions,
Expand All @@ -234,5 +210,4 @@ export {
// TODO: Replace getPolicyTagsData (https://github.com/Expensify/App/issues/72721) and getPolicyRecentlyUsedTagsData (https://github.com/Expensify/App/issues/71491) with useOnyx hook
getPolicyTagsData,
getPolicyTags,
getMoneyRequestPolicyTags,
};
Loading