Skip to content
Open
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
14 changes: 0 additions & 14 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

let allPolicies: OnyxCollection<Policy>;

Onyx.connect({

Check warning on line 76 in src/libs/PolicyUtils.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,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -1202,17 +1202,6 @@
.filter((employee) => employee.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && employee.role === CONST.POLICY.ROLE.ADMIN);
}

/**
* Returns the policy of the report
* @deprecated Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
*/
function getPolicy(policyID: string | undefined, policies: OnyxCollection<Policy> = allPolicies): OnyxEntry<Policy> {
if (!policies || !policyID) {
return undefined;
}
return policies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
}

/** Return active policies where current user is an admin */
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
const activePolicies = getActivePolicies(policies, currentUserLogin);
Expand Down Expand Up @@ -2076,9 +2065,6 @@
// This will be fixed as part of https://github.com/Expensify/App/issues/66397
// eslint-disable-next-line @typescript-eslint/no-deprecated
getPersonalPolicy,
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
getPolicy,
getPolicyBrickRoadIndicatorStatus,
getPolicyEmployeeListByIdWithoutCurrentUser,
getSortedTagKeys,
Expand Down
17 changes: 4 additions & 13 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import useSelfDMReport from '@hooks/useSelfDMReport';
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaypointItems from '@hooks/useWaypointItems';
import {getIOURequestPolicyID, setMoneyRequestAmount, updateMoneyRequestDistance} from '@libs/actions/IOU';
import {setMoneyRequestAmount, updateMoneyRequestDistance} from '@libs/actions/IOU';
import {handleMoneyRequestStepDistanceNavigation} from '@libs/actions/IOU/MoneyRequest';
import {setDraftSplitTransaction, setSplitShares} from '@libs/actions/IOU/Split';
import {init, stop} from '@libs/actions/MapboxToken';
Expand All @@ -41,7 +41,6 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {shouldUseTransactionDraft} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getPolicy} from '@libs/PolicyUtils';
import {isArchivedReport, isPolicyExpenseChat as isPolicyExpenseChatUtil} from '@libs/ReportUtils';
import {getDistanceInMeters, getRateID, getRequestType, hasRoute, isCustomUnitRateIDForP2P, isWaypointNullIsland} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -80,7 +79,6 @@ function IOURequestStepDistance({
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const {isBetaEnabled} = usePermissions();
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const isArchived = isArchivedReport(reportNameValuePairs);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
Expand Down Expand Up @@ -184,17 +182,10 @@ function IOURequestStepDistance({
(participants: Participant[]) => {
// Get policy report based on transaction participants
const isPolicyExpenseChat = participants?.some((participant) => participant.isPolicyExpenseChat);
const selectedReportID = participants?.length === 1 ? (participants.at(0)?.reportID ?? reportID) : reportID;
const policyReport = participants.at(0) ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`] : report;

const IOUpolicyID = getIOURequestPolicyID(transaction, policyReport);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const IOUpolicy = getPolicy(report?.policyID ?? IOUpolicyID);
const policyCurrency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy);
const mileageRates = DistanceRequestUtils.getMileageRates(policy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy);
const mileageRate: MileageRate | undefined = isCustomUnitRateIDForP2P(transaction)
? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction)
: // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand All @@ -211,7 +202,7 @@ function IOURequestStepDistance({
setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []);
}
},
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID, personalPolicy?.outputCurrency],
[policy, personalPolicy?.outputCurrency, transaction, customUnitRateID, transactionID, isSplitRequest],
);

// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
Expand Down
18 changes: 4 additions & 14 deletions src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import useSelfDMReport from '@hooks/useSelfDMReport';
import useShowNotFoundPageInIOUStep from '@hooks/useShowNotFoundPageInIOUStep';
import useThemeStyles from '@hooks/useThemeStyles';
import useWaypointItems from '@hooks/useWaypointItems';
import {getIOURequestPolicyID, setMoneyRequestAmount, updateMoneyRequestDistance} from '@libs/actions/IOU';
import {setMoneyRequestAmount, updateMoneyRequestDistance} from '@libs/actions/IOU';
import {handleMoneyRequestStepDistanceNavigation} from '@libs/actions/IOU/MoneyRequest';
import {setDraftSplitTransaction, setSplitShares} from '@libs/actions/IOU/Split';
import {init, stop} from '@libs/actions/MapboxToken';
Expand All @@ -41,7 +41,6 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {shouldUseTransactionDraft} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getPolicy} from '@libs/PolicyUtils';
import {isArchivedReport, isPolicyExpenseChat as isPolicyExpenseChatUtil} from '@libs/ReportUtils';
import {getDistanceInMeters, getRateID, getRequestType, hasRoute, isCustomUnitRateIDForP2P, isWaypointNullIsland} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -80,7 +79,6 @@ function IOURequestStepDistanceMap({
const {translate} = useLocalize();
const {isBetaEnabled} = usePermissions();
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const isArchived = isArchivedReport(reportNameValuePairs);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
Expand Down Expand Up @@ -179,19 +177,11 @@ function IOURequestStepDistanceMap({
// Sets `amount` and `split` share data before moving to the next step to avoid briefly showing `0.00` as the split share for participants
const setDistanceRequestData = useCallback(
(participants: Participant[]) => {
// Get policy report based on transaction participants
const isPolicyExpenseChat = participants?.some((participant) => participant.isPolicyExpenseChat);
const selectedReportID = participants?.length === 1 ? (participants.at(0)?.reportID ?? reportID) : reportID;
const policyReport = participants.at(0) ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`] : report;

const IOUpolicyID = getIOURequestPolicyID(transaction, policyReport);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const IOUpolicy = getPolicy(report?.policyID ?? IOUpolicyID);
const policyCurrency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy);
const mileageRates = DistanceRequestUtils.getMileageRates(policy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy);
const mileageRate: MileageRate | undefined = isCustomUnitRateIDForP2P(transaction)
? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction)
: // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand All @@ -208,7 +198,7 @@ function IOURequestStepDistanceMap({
setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []);
}
},
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID, personalPolicy?.outputCurrency],
[policy, personalPolicy?.outputCurrency, transaction, customUnitRateID, transactionID, isSplitRequest],
);

// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/ModifiedExpenseMessageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import {createRandomReport} from '../utils/collections/reports';
import {translateLocal} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

// Mock PolicyUtils so getPolicy and isPolicyAdmin are controllable in tests. ModifiedExpenseMessage
// Mock PolicyUtils so isPolicyAdmin are controllable in tests. ModifiedExpenseMessage
// uses named imports from this module; spies alone do not affect those references, so we need a module mock.
jest.mock('@libs/PolicyUtils', () => ({
...jest.requireActual<typeof PolicyUtils>('@libs/PolicyUtils'),
getPolicy: jest.fn(),
isPolicyAdmin: jest.fn(),
}));

Expand Down
Loading