diff --git a/package-lock.json b/package-lock.json index bf3634ee1c50..9b751e527135 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,7 +107,7 @@ "react-native-web-linear-gradient": "^1.1.2", "react-native-web-lottie": "^1.4.4", "react-native-webview": "^11.17.2", - "react-native-x-maps": "1.0.9", + "react-native-x-maps": "1.0.10", "react-pdf": "^6.2.2", "react-plaid-link": "3.3.2", "react-web-config": "^1.0.0", @@ -43449,9 +43449,9 @@ } }, "node_modules/react-native-x-maps": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/react-native-x-maps/-/react-native-x-maps-1.0.9.tgz", - "integrity": "sha512-EEb0BcAWwTnN18J2QL7WHbafV/NLaxtPKJbB0SYJp4KzGK1lRTT3Pl/LYodEUhLUbYk04Y0jcA8ifiImc7yn6A==", + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/react-native-x-maps/-/react-native-x-maps-1.0.10.tgz", + "integrity": "sha512-jBRl5JzP3QmGY6tj5CR9UwbREZ3tnuSa7puZozai3bRFrN68k3W6x1p6O8SGp91VvcQlaqJUPFZ+bkYiY3XRvA==", "peerDependencies": { "@rnmapbox/maps": "^10.0.11", "mapbox-gl": "^2.15.0", @@ -80293,9 +80293,9 @@ } }, "react-native-x-maps": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/react-native-x-maps/-/react-native-x-maps-1.0.9.tgz", - "integrity": "sha512-EEb0BcAWwTnN18J2QL7WHbafV/NLaxtPKJbB0SYJp4KzGK1lRTT3Pl/LYodEUhLUbYk04Y0jcA8ifiImc7yn6A==", + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/react-native-x-maps/-/react-native-x-maps-1.0.10.tgz", + "integrity": "sha512-jBRl5JzP3QmGY6tj5CR9UwbREZ3tnuSa7puZozai3bRFrN68k3W6x1p6O8SGp91VvcQlaqJUPFZ+bkYiY3XRvA==", "requires": {} }, "react-pdf": { diff --git a/package.json b/package.json index 27195f385230..9101edf89ad9 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "react-native-web-linear-gradient": "^1.1.2", "react-native-web-lottie": "^1.4.4", "react-native-webview": "^11.17.2", - "react-native-x-maps": "^1.0.9", + "react-native-x-maps": "1.0.10", "react-pdf": "^6.2.2", "react-plaid-link": "3.3.2", "react-web-config": "^1.0.0", diff --git a/src/components/DistanceRequest.js b/src/components/DistanceRequest.js index 8f07c7c05ecf..3eb52c1ec1c7 100644 --- a/src/components/DistanceRequest.js +++ b/src/components/DistanceRequest.js @@ -7,6 +7,7 @@ import {withOnyx} from 'react-native-onyx'; import MapView from 'react-native-x-maps'; import ONYXKEYS from '../ONYXKEYS'; import * as Transaction from '../libs/actions/Transaction'; +import * as TransactionUtils from '../libs/TransactionUtils'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import * as Expensicons from './Icon/Expensicons'; import theme from '../styles/themes/default'; @@ -21,6 +22,10 @@ import useNetwork from '../hooks/useNetwork'; import useLocalize from '../hooks/useLocalize'; import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; +import ScreenWrapper from './ScreenWrapper'; +import DotIndicatorMessage from './DotIndicatorMessage'; +import * as ErrorUtils from '../libs/ErrorUtils'; +import usePrevious from '../hooks/usePrevious'; const MAX_WAYPOINTS = 25; const MAX_WAYPOINTS_TO_DISPLAY = 4; @@ -51,6 +56,9 @@ const propTypes = { address: PropTypes.string, }), }), + + /** Server side errors keyed by microtime */ + errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), }), /** Data about Mapbox token for calling Mapbox API */ @@ -78,7 +86,13 @@ function DistanceRequest({transactionID, transaction, mapboxAccessToken}) { const waypoints = lodashGet(transaction, 'comment.waypoints', {}); const numberOfWaypoints = _.size(waypoints); + const lastWaypointIndex = numberOfWaypoints - 1; + const isLoadingRoute = lodashGet(transaction, 'comment.isLoading', false); + const hasRouteError = Boolean(lodashGet(transaction, 'errorFields.route')); + const previousWaypoints = usePrevious(waypoints); + const haveWaypointsChanged = !_.isEqual(previousWaypoints, waypoints); + const shouldFetchRoute = haveWaypointsChanged && !isOffline && !isLoadingRoute && TransactionUtils.validateWaypoints(waypoints); const waypointMarkers = _.filter( _.map(waypoints, (waypoint, key) => { @@ -133,10 +147,19 @@ function DistanceRequest({transactionID, transaction, mapboxAccessToken}) { setShouldShowGradient(visibleAreaEnd < scrollContentHeight); }; + // Handle fetching the route when there are at least 2 waypoints + useEffect(() => { + if (!shouldFetchRoute) { + return; + } + + Transaction.getRoute(transactionID, waypoints); + }, [shouldFetchRoute, transactionID, waypoints]); + useEffect(updateGradientVisibility, [scrollContainerHeight, scrollContentHeight]); return ( - <> + setScrollContainerHeight(lodashGet(event, 'nativeEvent.layout.height', 0))} @@ -183,6 +206,13 @@ function DistanceRequest({transactionID, transaction, mapboxAccessToken}) { colors={[theme.transparent, theme.modalBackground]} /> )} + {hasRouteError && ( + + )}