Skip to content

Commit

Permalink
Merge pull request #32999 from rojiphil/29895-fix-duplicate-waypoints
Browse files Browse the repository at this point in the history
fix duplicate endpoints
  • Loading branch information
danieldoglas authored Jan 8, 2024
2 parents 9bdd4d0 + 2d6b845 commit 206ba4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,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.',
invalidMerchant: 'Please enter a correct merchant.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,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.',
invalidMerchant: 'Por favor ingrese un comerciante correcto.',
Expand Down
10 changes: 7 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')};
}
Expand Down Expand Up @@ -158,12 +162,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 (
<StepScreenWrapper
Expand Down Expand Up @@ -204,7 +208,7 @@ function IOURequestStepDistance({
</View>
<View style={[styles.w100, styles.pt2]}>
{/* 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) && (
<DotIndicatorMessage
style={[styles.mh4, styles.mv3]}
messages={getError()}
Expand Down

0 comments on commit 206ba4c

Please sign in to comment.