Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Distance-Distance field is stuck on pending... and no error shown when updating of waypoints fails #53329

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt);

const errors = {
...(transaction?.errorFields?.route ?? transaction?.errors),
...(transaction?.errorFields?.route ?? transaction?.errorFields?.waypoints ?? transaction?.errors),
...parentReportAction?.errors,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function ReportActionItemImage({
const {translate} = useLocalize();
const isDistanceRequest = !!transaction && TransactionUtils.isDistanceRequest(transaction);
const hasPendingWaypoints = transaction && TransactionUtils.isFetchingWaypointsFromServer(transaction);
const hasErrors = !isEmptyObject(transaction?.errors) || !isEmptyObject(transaction?.errorFields);
const hasErrors = !isEmptyObject(transaction?.errors) || !isEmptyObject(transaction?.errorFields?.route) || !isEmptyObject(transaction?.errorFields?.waypoints);
const showMapAsImage = isDistanceRequest && (hasErrors || hasPendingWaypoints);

if (showMapAsImage) {
Expand Down
34 changes: 34 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3251,6 +3251,7 @@ type UpdateMoneyRequestDistanceParams = {
policy?: OnyxEntry<OnyxTypes.Policy>;
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagLists>;
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
transactionBackup: OnyxEntry<OnyxTypes.Transaction>;
};

/** Updates the waypoints of a distance expense */
Expand All @@ -3262,6 +3263,7 @@ function updateMoneyRequestDistance({
policy = {} as OnyxTypes.Policy,
policyTagList = {},
policyCategories = {},
transactionBackup,
}: UpdateMoneyRequestDistanceParams) {
const transactionChanges: TransactionChanges = {
waypoints: sanitizeRecentWaypoints(waypoints),
Expand All @@ -3285,6 +3287,38 @@ function updateMoneyRequestDistance({
value: recentServerValidatedWaypoints,
});

if (transactionBackup) {
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
// We need to include all keys of the optimisticData's waypoints in the failureData for onyx merge to properly reset
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
// waypoint keys that do not exist in the failureData's waypoints. For instance, if the optimisticData waypoints had
// three keys and the failureData waypoint had only 2 keys then the third key that doesn't exist in the failureData
// waypoints should be explicitly reset otherwise onyx merge will leave it intact.
const allWaypointKeys = [...new Set([...Object.keys(transactionBackup.comment?.waypoints ?? {}), ...Object.keys(transaction?.comment?.waypoints ?? {})])];
const onyxWaypoints = allWaypointKeys.reduce((acc: NullishDeep<WaypointCollection>, key) => {
acc[key] = transactionBackup.comment?.waypoints?.[key] ? {...transactionBackup.comment?.waypoints?.[key]} : null;
return acc;
}, {});
const allModifiedWaypointsKeys = [...new Set([...Object.keys(waypoints ?? {}), ...Object.keys(transaction?.modifiedWaypoints ?? {})])];
const onyxModifiedWaypoints = allModifiedWaypointsKeys.reduce((acc: NullishDeep<WaypointCollection>, key) => {
acc[key] = transactionBackup.modifiedWaypoints?.[key] ? {...transactionBackup.modifiedWaypoints?.[key]} : null;
return acc;
}, {});
onyxData?.failureData?.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
comment: {
waypoints: onyxWaypoints,
customUnit: {
quantity: transactionBackup?.comment?.customUnit?.quantity,
},
},
modifiedWaypoints: onyxModifiedWaypoints,
routes: null,
},
});
}

API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DISTANCE, params, onyxData);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function abandonReviewDuplicateTransactions() {
}

function clearError(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null, errorFields: {route: null}});
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null, errorFields: {route: null, waypoints: null, routes: null}});
}

function markAsCash(transactionID: string, transactionThreadReportID: string) {
Expand Down
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ function IOURequestStepDistance({
waypoints,
...(hasRouteChanged ? {routes: transaction?.routes} : {}),
policy,
transactionBackup,
});
navigateBack();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ type Transaction = OnyxCommon.OnyxValueWithOfflineFeedback<
errors?: OnyxCommon.Errors | ReceiptErrors;

/** Server side errors keyed by microtime */
errorFields?: OnyxCommon.ErrorFields<'route'>;
errorFields?: OnyxCommon.ErrorFields;

/** The name of the file used for a receipt (formerly receiptFilename) */
filename?: string;
Expand Down
Loading