Skip to content

Commit

Permalink
Merge pull request #51840 from nkdengineer/fix/51285
Browse files Browse the repository at this point in the history
Fix blank map preview on employee side
  • Loading branch information
Gonals authored Nov 7, 2024
2 parents ad0f834 + 7e9ec7b commit e453cfd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals

const distanceRequestFields = (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints') ?? getPendingFieldAction('merchant')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={distanceToDisplay}
Expand Down
6 changes: 4 additions & 2 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import lodashDeepClone from 'lodash/cloneDeep';
import lodashHas from 'lodash/has';
import lodashIsEqual from 'lodash/isEqual';
import lodashSet from 'lodash/set';
Expand Down Expand Up @@ -249,7 +250,7 @@ function areRequiredFieldsEmpty(transaction: OnyxEntry<Transaction>): boolean {
*/
function getUpdatedTransaction(transaction: Transaction, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, shouldUpdateReceiptState = true): Transaction {
// Only changing the first level fields so no need for deep clone now
const updatedTransaction = {...transaction};
const updatedTransaction = lodashDeepClone(transaction);
let shouldStopSmartscan = false;

// The comment property does not have its modifiedComment counterpart
Expand Down Expand Up @@ -301,7 +302,7 @@ function getUpdatedTransaction(transaction: Transaction, transactionChanges: Tra
const conversionFactor = existingDistanceUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS : CONST.CUSTOM_UNITS.KILOMETERS_TO_MILES;
const distance = NumberUtils.roundToTwoDecimalPlaces((transaction?.comment?.customUnit?.quantity ?? 0) * conversionFactor);
lodashSet(updatedTransaction, 'comment.customUnit.quantity', distance);
lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
lodashSet(updatedTransaction, 'pendingFields.merchant', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);
}
}

Expand Down Expand Up @@ -341,6 +342,7 @@ function getUpdatedTransaction(transaction: Transaction, transactionChanges: Tra
}

updatedTransaction.pendingFields = {
...(updatedTransaction?.pendingFields ?? {}),
...(Object.hasOwn(transactionChanges, 'comment') && {comment: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(Object.hasOwn(transactionChanges, 'created') && {created: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
...(Object.hasOwn(transactionChanges, 'amount') && {amount: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
Expand Down
10 changes: 8 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ function getUpdateMoneyRequestParams(
const failureData: OnyxUpdate[] = [];

// Step 1: Set any "pending fields" (ones updated while the user was offline) to have error messages in the failureData
const pendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
let pendingFields: OnyxTypes.Transaction['pendingFields'] = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}]));

const allReports = ReportConnection.getAllReports();
Expand All @@ -2519,6 +2519,13 @@ function getUpdateMoneyRequestParams(
let updatedTransaction: OnyxEntry<OnyxTypes.Transaction> = transaction ? TransactionUtils.getUpdatedTransaction(transaction, transactionChanges, isFromExpenseReport) : undefined;
const transactionDetails = ReportUtils.getTransactionDetails(updatedTransaction);

if (updatedTransaction?.pendingFields) {
pendingFields = {
...pendingFields,
...updatedTransaction?.pendingFields,
};
}

if (transactionDetails?.waypoints) {
// This needs to be a JSON string since we're sending this to the MapBox API
transactionDetails.waypoints = JSON.stringify(transactionDetails.waypoints);
Expand Down Expand Up @@ -4982,7 +4989,6 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA
const splitParticipants: Split[] = updatedTransaction?.comment?.splits ?? [];
const amount = updatedTransaction?.modifiedAmount;
const currency = updatedTransaction?.modifiedCurrency;
console.debug(updatedTransaction);

// Exclude the current user when calculating the split amount, `calculateAmount` takes it into account
const splitAmount = IOUUtils.calculateAmount(splitParticipants.length - 1, amount ?? 0, currency ?? '', false);
Expand Down

0 comments on commit e453cfd

Please sign in to comment.