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

Show invalid waypoint error message for an invalid distance request route #41481

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -340,7 +340,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 @@ -105,6 +106,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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bernhardoj Sorry I missed this. Why are taking the error object OnyxEntry<Errors> alone? Can't we have the linkedTransaction itself as a prop and take the error inside the class? Similar to how transaction object is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just care about the error object, so @tgolen suggested to use selector to optimize it.

};

type ReportActionItemProps = {
Expand Down Expand Up @@ -183,6 +187,7 @@ function ReportActionItem({
onPress = undefined,
isFirstVisibleReportAction = false,
shouldUseThreadDividerLine = false,
linkedTransactionRouteError,
}: ReportActionItemProps) {
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -977,7 +982,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 @@ -1049,6 +1054,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 @@ -1083,6 +1092,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
Loading