Skip to content

Commit

Permalink
Merge pull request Expensify#42302 from Expensify/neil-distance-split
Browse files Browse the repository at this point in the history
Enable distance splits
  • Loading branch information
arosiclair authored Aug 7, 2024
2 parents f9306d5 + 717d344 commit 65bca91
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 135 deletions.
16 changes: 10 additions & 6 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,10 @@ function MoneyRequestConfirmationList({

const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest);
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate) && !isMovingTransactionFromTrackExpense;
const distanceRequestAmount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0);
const formattedAmount = isDistanceRequestWithPendingRoute
? ''
: CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0) : iouAmount,
isDistanceRequest ? currency : iouCurrencyCode,
);
: CurrencyUtils.convertToDisplayString(shouldCalculateDistanceAmount ? distanceRequestAmount : iouAmount, isDistanceRequest ? currency : iouCurrencyCode);

const previousTransactionAmount = usePrevious(transaction?.amount);
const previousTransactionCurrency = usePrevious(transaction?.currency);
Expand Down Expand Up @@ -340,9 +338,15 @@ function MoneyRequestConfirmationList({
return;
}

const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0);
const amount = distanceRequestAmount;
IOU.setMoneyRequestAmount(transactionID, amount, currency ?? '');
}, [shouldCalculateDistanceAmount, distance, rate, unit, transactionID, currency]);

// If it's a split request among individuals, set the split shares
const participantAccountIDs: number[] = selectedParticipantsProp.map((participant) => participant.accountID ?? -1);
if (isTypeSplit && !isPolicyExpenseChat && amount && transaction?.currency) {
IOU.setSplitShares(transaction, amount, currency, participantAccountIDs);
}
}, [shouldCalculateDistanceAmount, distanceRequestAmount, transactionID, currency, isTypeSplit, isPolicyExpenseChat, selectedParticipantsProp, transaction]);

// Calculate and set tax amount in transaction draft
useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/ReportActionItem/ReportActionItemImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Transaction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type ReportActionItemImageProps = {
/** thumbnail URI for the image */
Expand Down Expand Up @@ -75,7 +76,8 @@ function ReportActionItemImage({
const {translate} = useLocalize();
const isDistanceRequest = !!transaction && TransactionUtils.isDistanceRequest(transaction);
const hasPendingWaypoints = transaction && TransactionUtils.isFetchingWaypointsFromServer(transaction);
const showMapAsImage = isDistanceRequest && hasPendingWaypoints;
const hasErrors = !isEmptyObject(transaction?.errors) || !isEmptyObject(transaction?.errorFields);
const showMapAsImage = isDistanceRequest && (hasErrors || hasPendingWaypoints);

if (showMapAsImage) {
return (
Expand Down
22 changes: 12 additions & 10 deletions src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
type CreateDistanceRequestParams = {
comment: string;
iouReportID: string;
chatReportID: string;
transactionID: string;
reportActionID: string;
chatReportID: string;
createdChatReportActionID: string;
createdIOUReportActionID: string;
reportPreviewReportActionID: string;
reportActionID: string;
waypoints: string;
customUnitRateID: string;
comment: string;
created: string;
iouReportID?: string;
createdIOUReportActionID?: string;
reportPreviewReportActionID?: string;
category?: string;
tag?: string;
taxCode?: string;
taxAmount?: number;
billable?: boolean;
transactionThreadReportID: string;
createdReportActionIDForThread: string;
payerEmail: string;
customUnitRateID?: string;
transactionThreadReportID?: string;
createdReportActionIDForThread?: string;
payerEmail?: string;
splits?: string;
chatType?: string;
};

export default CreateDistanceRequestParams;
4 changes: 2 additions & 2 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ function buildOptimisticTransaction(
merchant: merchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
created: created || DateUtils.getDBTime(),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
receipt,
filename,
receipt: receipt?.source ? {source: receipt.source, state: receipt.state ?? CONST.IOU.RECEIPT_STATE.SCANREADY} : {},
filename: receipt?.source ?? receipt?.name ?? filename,
category,
tag,
taxCode,
Expand Down
Loading

0 comments on commit 65bca91

Please sign in to comment.