Skip to content

Commit

Permalink
update the optimistic data when a distance is edited offlien to show …
Browse files Browse the repository at this point in the history
…a simple message offline
  • Loading branch information
klajdipaja committed Jan 30, 2025
1 parent ab3a7ee commit 4477dde
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ const translations = {
attendees: 'Attendees',
paymentComplete: 'Payment complete',
time: 'Time',
updatedTheDistanceOptimistically: 'Updated the distance',
startDate: 'Start date',
endDate: 'End date',
startTime: 'Start time',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ const translations = {
attendees: 'Asistentes',
paymentComplete: 'Pago completo',
time: 'Tiempo',
updatedTheDistanceOptimistically: 'Distancia actualizada',
startDate: 'Fecha de inicio',
endDate: 'Fecha de finalización',
startTime: 'Hora de inicio',
Expand Down
9 changes: 9 additions & 0 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ function getForReportAction(reportOrID: string | SearchReport | undefined, repor
'currency' in reportActionOriginalMessage;

const hasModifiedMerchant = isReportActionOriginalMessageAnObject && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
const optimisticDistanceUpdateMessage = Localize.translateLocal('iou.updatedTheDistanceOptimistically');
const hasOptimisticDistanceUpdate =
hasModifiedMerchant &&
CONST.REGEX.DISTANCE_MERCHANT.test(reportActionOriginalMessage?.oldMerchant ?? '') &&
(reportActionOriginalMessage?.merchant ?? '') === optimisticDistanceUpdateMessage;

if (hasOptimisticDistanceUpdate) {
return optimisticDistanceUpdateMessage;
}

if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3908,6 +3908,10 @@ function getModifiedExpenseOriginalMessage(
if ('attendees' in transactionChanges) {
[originalMessage.oldAttendees, originalMessage.attendees] = getFormattedAttendees(transactionChanges?.attendees, getAttendees(oldTransaction));
}
if ('waypoints' in transactionChanges) {
originalMessage.oldMerchant = getMerchant(oldTransaction);
originalMessage.merchant = translateLocal('iou.updatedTheDistanceOptimistically');
}

// The amount is always a combination of the currency and the number value so when one changes we need to store both
// to match how we handle the modified expense action in oldDot
Expand Down
11 changes: 5 additions & 6 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,7 @@ function getUpdateMoneyRequestParams(
value: null,
});


// Revert the transaction's amount to the original value on failure.
// The IOU Report will be fully reverted in the failureData further below.
failureData.push({
Expand All @@ -3266,12 +3267,11 @@ function getUpdateMoneyRequestParams(

// Step 3: Build the modified expense report actions
// We don't create a modified report action if:
// - we're updating the waypoints
// - we're updating the distance rate while the waypoints are still pending
// In these cases, there isn't a valid optimistic mileage data we can use,
// and the report action is created on the server with the distance-related response from the MapBox API
const updatedReportAction = buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, isFromExpenseReport, policy, updatedTransaction);
if (!hasPendingWaypoints && !(hasModifiedDistanceRate && isFetchingWaypointsFromServer(transaction))) {
if (!hasModifiedDistanceRate) {
params.reportActionID = updatedReportAction.reportActionID;

optimisticData.push({
Expand Down Expand Up @@ -3301,7 +3301,7 @@ function getUpdateMoneyRequestParams(
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {pendingAction: null},
[updatedReportAction.reportActionID]: (hasPendingWaypoints ? null : {pendingAction: null}),
},
});
failureData.push({
Expand Down Expand Up @@ -3597,12 +3597,11 @@ function getUpdateTrackExpenseParams(

// Step 3: Build the modified expense report actions
// We don't create a modified report action if:
// - we're updating the waypoints
// - we're updating the distance rate while the waypoints are still pending
// In these cases, there isn't a valid optimistic mileage data we can use,
// and the report action is created on the server with the distance-related response from the MapBox API
const updatedReportAction = buildOptimisticModifiedExpenseReportAction(transactionThread, transaction, transactionChanges, false, policy, updatedTransaction);
if (!hasPendingWaypoints && !(hasModifiedDistanceRate && isFetchingWaypointsFromServer(transaction))) {
if (!hasModifiedDistanceRate) {
params.reportActionID = updatedReportAction.reportActionID;

optimisticData.push({
Expand All @@ -3616,7 +3615,7 @@ function getUpdateTrackExpenseParams(
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`,
value: {
[updatedReportAction.reportActionID]: {pendingAction: null},
[updatedReportAction.reportActionID]: (hasPendingWaypoints ? null : {pendingAction: null}),
},
});
failureData.push({
Expand Down

0 comments on commit 4477dde

Please sign in to comment.