Skip to content

Commit

Permalink
get custom unit and mileage rate and use distance text stub
Browse files Browse the repository at this point in the history
  • Loading branch information
arosiclair committed Aug 15, 2023
1 parent 8f7ab26 commit 5c64db9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as CurrencyUtils from '../../libs/CurrencyUtils';
import EmptyStateBackgroundImage from '../../../assets/images/empty-state_background-fade.png';
import useLocalize from '../../hooks/useLocalize';
import * as TransactionUtils from '../../libs/TransactionUtils';
import * as PolicyUtils from '../../libs/PolicyUtils';
import * as ReceiptUtils from '../../libs/ReceiptUtils';
import withLocalize from '../withLocalize';
import useWindowDimensions from '../../hooks/useWindowDimensions';
Expand Down Expand Up @@ -95,6 +96,8 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
}

const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
const distanceCustomUnit = PolicyUtils.getDistanceCustomUnit(policy);
const mileageRate = PolicyUtils.getDefaultMileageRate(distanceCustomUnit);

return (
<View>
Expand Down Expand Up @@ -133,7 +136,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
{isDistanceRequest && (
<MenuItemWithTopDescription
description={translate('tabSelector.distance')}
title="123 miles @ $456 / mile"
title={PolicyUtils.getDistanceText(transaction, distanceCustomUnit, mileageRate)}
disabled={isSettled || !canEdit}
shouldShowRightIcon={canEdit}
onPress={() => {}}
Expand Down
20 changes: 20 additions & 0 deletions src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ function getIneligibleInvitees(policyMembers, personalDetails) {
return memberEmailsToExclude;
}

function getDistanceCustomUnit(policy) {
const customUnits = _.values(policy.customUnits);
return _.find(customUnits, (customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
}

function getDefaultMileageRate(customUnit) {
if (!customUnit) {
return 0;
}

return _.find(customUnit.rates, (rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE);
}

function getDistanceText(transaction, customUnit, mileageRate) {
return '123 miles @ $456 / mile';
}

export {
getActivePolicies,
hasPolicyMemberError,
Expand All @@ -179,4 +196,7 @@ export {
isPolicyAdmin,
getMemberAccountIDsForWorkspace,
getIneligibleInvitees,
getDistanceCustomUnit,
getDefaultMileageRate,
getDistanceText,
};

0 comments on commit 5c64db9

Please sign in to comment.