Skip to content

Commit

Permalink
Merge pull request #41481 from bernhardoj/fix/38213-shows-correct-tra…
Browse files Browse the repository at this point in the history
…nsaction-error-message

Show invalid waypoint error message for an invalid distance request route
  • Loading branch information
lakchote authored May 16, 2024
2 parents 18bc082 + 805b3d5 commit bf23770
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function MoneyRequestView({
{shouldShowMapOrReceipt && (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={transaction?.errors}
errors={transaction?.errorFields?.route ?? transaction?.errors}
errorRowStyles={[styles.mh4]}
onClose={() => {
if (!transaction?.transactionID) {
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 @@ -262,7 +262,7 @@ function updateWaypoints(transactionID: string, waypoints: WaypointCollection, i
}

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

function markAsCash(transactionID: string, transactionThreadReportID: string, existingViolations: TransactionViolation[]) {
Expand Down
12 changes: 11 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions';
Expand Down Expand Up @@ -102,6 +103,9 @@ type ReportActionItemOnyxProps = {

/** Transaction associated with this report, if any */
transaction: OnyxEntry<OnyxTypes.Transaction>;

/** The transaction (linked with the report action) route error */
linkedTransactionRouteError: OnyxEntry<Errors>;
};

type ReportActionItemProps = {
Expand Down Expand Up @@ -179,6 +183,7 @@ function ReportActionItem({
onPress = undefined,
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
linkedTransactionRouteError,
}: ReportActionItemProps) {
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -971,7 +976,7 @@ function ReportActionItem({
draftMessage !== undefined ? undefined : action.pendingAction ?? (action.isOptimisticAction ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : undefined)
}
shouldHideOnDelete={!ReportActionsUtils.isThreadParentMessage(action, report.reportID)}
errors={ErrorUtils.getLatestErrorMessageField(action as ErrorUtils.OnyxDataWithErrors)}
errors={linkedTransactionRouteError ?? ErrorUtils.getLatestErrorMessageField(action as ErrorUtils.OnyxDataWithErrors)}
errorRowStyles={[styles.ml10, styles.mr2]}
needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(action)}
shouldDisableStrikeThrough
Expand Down Expand Up @@ -1039,6 +1044,10 @@ export default withOnyx<ReportActionItemProps, ReportActionItemOnyxProps>({
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
},
},
linkedTransactionRouteError: {
key: ({action}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${(action as OnyxTypes.OriginalMessageIOU)?.originalMessage?.IOUTransactionID ?? 0}`,
selector: (transaction: OnyxEntry<OnyxTypes.Transaction>) => transaction?.errorFields?.route ?? null,
},
})(
memo(ReportActionItem, (prevProps, nextProps) => {
const prevParentReportAction = prevProps.parentReportAction;
Expand Down Expand Up @@ -1073,6 +1082,7 @@ export default withOnyx<ReportActionItemProps, ReportActionItemOnyxProps>({
lodashIsEqual(prevProps.transactionThreadReport, nextProps.transactionThreadReport) &&
lodashIsEqual(prevProps.reportActions, nextProps.reportActions) &&
lodashIsEqual(prevProps.transaction, nextProps.transaction) &&
lodashIsEqual(prevProps.linkedTransactionRouteError, nextProps.linkedTransactionRouteError) &&
lodashIsEqual(prevParentReportAction, nextParentReportAction)
);
}),
Expand Down

0 comments on commit bf23770

Please sign in to comment.