From 010bc09c7b71bdf89808c3df7a58a4f6a516f7bb Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 13 Dec 2023 19:23:35 +0530 Subject: [PATCH] fix duplicate endpoints --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/pages/iou/request/step/IOURequestStepDistance.js | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index c4a481cb71c0..8b860372d730 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -612,6 +612,7 @@ export default { genericDeleteFailureMessage: 'Unexpected error deleting the money request, please try again later', genericEditFailureMessage: 'Unexpected error editing the money request, please try again later', genericSmartscanFailureMessage: 'Transaction is missing fields', + duplicateWaypointsErrorMessage: 'Please remove duplicate waypoints', atLeastTwoDifferentWaypoints: 'Please enter at least two different addresses', splitBillMultipleParticipantsErrorMessage: 'Split bill is only allowed between a single workspace or individual users. Please update your selection.', }, diff --git a/src/languages/es.ts b/src/languages/es.ts index a91a8768a3ee..b0bc725351aa 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -607,6 +607,7 @@ export default { genericDeleteFailureMessage: 'Error inesperado eliminando la solicitud de dinero. Por favor, inténtalo más tarde', genericEditFailureMessage: 'Error inesperado al guardar la solicitud de dinero. Por favor, inténtalo más tarde', genericSmartscanFailureMessage: 'La transacción tiene campos vacíos', + duplicateWaypointsErrorMessage: 'Por favor elimina los puntos de ruta duplicados', atLeastTwoDifferentWaypoints: 'Por favor introduce al menos dos direcciones diferentes', splitBillMultipleParticipantsErrorMessage: 'Solo puedes dividir una cuenta entre un único espacio de trabajo o con usuarios individuales. Por favor actualiza tu selección.', }, diff --git a/src/pages/iou/request/step/IOURequestStepDistance.js b/src/pages/iou/request/step/IOURequestStepDistance.js index 39e9d6f03afa..0270ec724e0d 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance.js +++ b/src/pages/iou/request/step/IOURequestStepDistance.js @@ -131,6 +131,10 @@ function IOURequestStepDistance({ return ErrorUtils.getLatestErrorField(transaction, 'route'); } + if (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) { + return {0: translate('iou.error.duplicateWaypointsErrorMessage')}; + } + if (_.size(validatedWaypoints) < 2) { return {0: translate('iou.error.atLeastTwoDifferentWaypoints')}; } @@ -159,12 +163,12 @@ function IOURequestStepDistance({ const submitWaypoints = useCallback(() => { // If there is any error or loading state, don't let user go to next page. - if (_.size(validatedWaypoints) < 2 || hasRouteError || isLoadingRoute || isLoading) { + if (_.size(validatedWaypoints) < 2 || (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) || hasRouteError || isLoadingRoute || isLoading) { setHasError(true); return; } navigateToNextStep(); - }, [setHasError, hasRouteError, isLoadingRoute, isLoading, validatedWaypoints, navigateToNextStep]); + }, [setHasError, waypoints, hasRouteError, isLoadingRoute, isLoading, validatedWaypoints, navigateToNextStep]); return ( {/* Show error message if there is route error or there are less than 2 routes and user has tried submitting, */} - {((hasError && _.size(validatedWaypoints) < 2) || hasRouteError) && ( + {((hasError && _.size(validatedWaypoints) < 2) || (_.keys(waypoints).length > 2 && _.size(validatedWaypoints) !== _.keys(waypoints).length) || hasRouteError) && (