From afb9f1bedd470706558e5858c58f74a66e26d9c4 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 17 Jul 2024 16:33:49 +0800 Subject: [PATCH 1/2] make it optional --- src/libs/TransactionUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 06465212733c..34b078f7040e 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -573,8 +573,8 @@ function hasPendingUI(transaction: OnyxEntry, transactionViolations /** * Check if the transaction has a defined route */ -function hasRoute(transaction: OnyxEntry, isDistanceRequestType: boolean): boolean { - return !!transaction?.routes?.route0?.geometry?.coordinates || (isDistanceRequestType && !!transaction?.comment?.customUnit?.quantity); +function hasRoute(transaction: OnyxEntry, isDistanceRequestType?: boolean): boolean { + return !!transaction?.routes?.route0?.geometry?.coordinates || (!!isDistanceRequestType && !!transaction?.comment?.customUnit?.quantity); } function getAllReportTransactions(reportID?: string, transactions?: OnyxCollection): Transaction[] { From c3a799f748945e5f3483efd2ef17419aa2af7ca0 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 17 Jul 2024 16:34:11 +0800 Subject: [PATCH 2/2] only refetch route if the route is empty and there is no route error --- src/pages/iou/request/step/IOURequestStepDistance.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDistance.tsx b/src/pages/iou/request/step/IOURequestStepDistance.tsx index 5d3b701424d5..f75adb4c2a3d 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistance.tsx @@ -94,13 +94,12 @@ function IOURequestStepDistance({ const isLoadingRoute = transaction?.comment?.isLoading ?? false; const isLoading = transaction?.isLoading ?? false; const hasRouteError = !!transaction?.errorFields?.route; - const hasRoute = TransactionUtils.hasRoute(transaction, true); + const hasRoute = TransactionUtils.hasRoute(transaction); const validatedWaypoints = TransactionUtils.getValidWaypoints(waypoints); const previousValidatedWaypoints = usePrevious(validatedWaypoints); const haveValidatedWaypointsChanged = !isEqual(previousValidatedWaypoints, validatedWaypoints); const isRouteAbsentWithoutErrors = !hasRoute && !hasRouteError; - const isEmptyCoordinates = !transaction?.routes?.route0?.geometry?.coordinates?.length; - const shouldFetchRoute = (isEmptyCoordinates || isRouteAbsentWithoutErrors || haveValidatedWaypointsChanged) && !isLoadingRoute && Object.keys(validatedWaypoints).length > 1; + const shouldFetchRoute = (isRouteAbsentWithoutErrors || haveValidatedWaypointsChanged) && !isLoadingRoute && Object.keys(validatedWaypoints).length > 1; const [shouldShowAtLeastTwoDifferentWaypointsError, setShouldShowAtLeastTwoDifferentWaypointsError] = useState(false); const isWaypointEmpty = (waypoint?: Waypoint) => { if (!waypoint) {