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

Fix error message for duplicate waypoint #30548

Merged
merged 12 commits into from
Nov 7, 2023
7 changes: 1 addition & 6 deletions src/components/DistanceRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,8 @@ function DistanceRequest({transactionID, report, transaction, route, isEditingRe
return ErrorUtils.getLatestErrorField(transaction, 'route');
}

// Initially, both waypoints will be null, and if we give fallback value as empty string that will result in true condition, that's why different default values.
if (_.keys(waypoints).length === 2 && lodashGet(waypoints, 'waypoint0.address', 'address1') === lodashGet(waypoints, 'waypoint1.address', 'address2')) {
return {0: translate('iou.error.duplicateWaypointsErrorMessage')};
}

if (_.size(validatedWaypoints) < 2) {
return {0: translate('iou.error.emptyWaypointsErrorMessage')};
return {0: translate('iou.error.atLeastTwoDifferentWaypoints')};
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,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',
emptyWaypointsErrorMessage: 'Please enter at least two waypoints',
atLeastTwoDifferentWaypoints: 'Please enter at least two different waypoints',
Copy link
Contributor

Choose a reason for hiding this comment

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

en: Please enter at least two different addresses.

},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Started settling up, payment is held until ${submitterDisplayName} enables their Wallet`,
enableWallet: 'Enable Wallet',
Expand Down
3 changes: 1 addition & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,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',
emptyWaypointsErrorMessage: 'Por favor introduce al menos dos puntos de ruta',
atLeastTwoDifferentWaypoints: 'Por favor introduce al menos dos puntos de ruta diferentes',
Copy link
Contributor

Choose a reason for hiding this comment

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

es: Por favor introduce al menos dos direcciones diferentes.

},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su Billetera`,
enableWallet: 'Habilitar Billetera',
Expand Down
6 changes: 4 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ function getValidWaypoints(waypoints: WaypointCollection, reArrangeIndexes = fal
}

let lastWaypointIndex = -1;
let waypointIndex = -1;

return waypointValues.reduce<WaypointCollection>((acc, currentWaypoint, index) => {
const previousWaypoint = waypointValues[lastWaypointIndex];
Expand All @@ -431,9 +432,10 @@ function getValidWaypoints(waypoints: WaypointCollection, reArrangeIndexes = fal
return acc;
}

const validatedWaypoints: WaypointCollection = {...acc, [`waypoint${reArrangeIndexes ? lastWaypointIndex + 1 : index}`]: currentWaypoint};
const validatedWaypoints: WaypointCollection = {...acc, [`waypoint${reArrangeIndexes ? waypointIndex + 1 : index}`]: currentWaypoint};

lastWaypointIndex += 1;
lastWaypointIndex = index;
waypointIndex += 1;

return validatedWaypoints;
}, {});
Expand Down
Loading