Skip to content

Commit

Permalink
pass correct custom rate id
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Oct 24, 2024
1 parent 6645d39 commit e87e740
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {LastSelectedDistanceRates, OnyxInputOrEntry, Transaction} from '@src/types/onyx';
import type {Unit} from '@src/types/onyx/Policy';
import type Policy from '@src/types/onyx/Policy';
import type Report from '@src/types/onyx/Report';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CurrencyUtils from './CurrencyUtils';
import * as PolicyUtils from './PolicyUtils';
Expand All @@ -30,6 +31,13 @@ Onyx.connect({
},
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

const METERS_TO_KM = 0.001; // 1 kilometer is 1000 meters
const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 miles in a meter

Expand Down Expand Up @@ -279,7 +287,9 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number {
*/
function getCustomUnitRateID(reportID: string, shouldUseDefault?: boolean) {
const allReports = ReportConnection.getAllReports();
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const reportReal = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const reportDraft = allReportsDraft?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportID}`];
const report = reportReal ?? reportDraft;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
const policy = PolicyUtils.getPolicy(report?.policyID ?? parentReport?.policyID ?? '-1');
let customUnitRateID: string = CONST.CUSTOM_UNITS.FAKE_P2P_ID;
Expand Down
4 changes: 3 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type IOURequestStepDistanceProps = WithCurrentUserPersonalDetailsProps &
};

function IOURequestStepDistance({
report,
report: reportReal,
reportDraft,
route: {
params: {action, iouType, reportID, transactionID, backTo},
},
Expand All @@ -63,6 +64,7 @@ function IOURequestStepDistance({
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const report = reportReal ?? reportDraft;
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${transactionID}`);
const policy = usePolicy(report?.policyID);
Expand Down

0 comments on commit e87e740

Please sign in to comment.